WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
wpi::DynamicStruct Class Reference

Dynamic (run-time) read-only access to a serialized raw struct. More...

#include <wpi/struct/DynamicStruct.h>

Inheritance diagram for wpi::DynamicStruct:
wpi::MutableDynamicStruct wpi::DynamicStructObject

Public Member Functions

 DynamicStruct (const StructDescriptor *desc, std::span< const uint8_t > data)
 Constructs a new dynamic struct.
 
const StructDescriptorGetDescriptor () const
 Gets the struct descriptor.
 
std::span< const uint8_t > GetData () const
 Gets the serialized data.
 
const StructFieldDescriptorFindField (std::string_view name) const
 Gets a struct field descriptor by name.
 
bool GetBoolField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a boolean field.
 
int64_t GetIntField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a signed integer field.
 
uint64_t GetUintField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of an unsigned integer field.
 
float GetFloatField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a float field.
 
double GetDoubleField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a double field.
 
std::string_view GetStringField (const StructFieldDescriptor *field) const
 Gets the value of a char or char array field.
 
DynamicStruct GetStructField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a struct field.
 

Protected Attributes

const StructDescriptorm_desc
 

Detailed Description

Dynamic (run-time) read-only access to a serialized raw struct.

Constructor & Destructor Documentation

◆ DynamicStruct()

wpi::DynamicStruct::DynamicStruct ( const StructDescriptor * desc,
std::span< const uint8_t > data )
inline

Constructs a new dynamic struct.

Note: the passed data is a span; no copy is made, so it's necessary for the lifetime of the referenced data to be longer than this object.

Parameters
descstruct descriptor
dataserialized data

Member Function Documentation

◆ FindField()

const StructFieldDescriptor * wpi::DynamicStruct::FindField ( std::string_view name) const
inline

Gets a struct field descriptor by name.

Parameters
namefield name
Returns
field descriptor, or nullptr if no field with that name exists

◆ GetBoolField()

bool wpi::DynamicStruct::GetBoolField ( const StructFieldDescriptor * field,
size_t arrIndex = 0 ) const
inline

Gets the value of a boolean field.

Parameters
fieldfield descriptor
arrIndexarray index (must be less than field array size)
Returns
field value

◆ GetData()

std::span< const uint8_t > wpi::DynamicStruct::GetData ( ) const
inline

Gets the serialized data.

Returns
data

◆ GetDescriptor()

const StructDescriptor * wpi::DynamicStruct::GetDescriptor ( ) const
inline

Gets the struct descriptor.

Returns
struct descriptor

◆ GetDoubleField()

double wpi::DynamicStruct::GetDoubleField ( const StructFieldDescriptor * field,
size_t arrIndex = 0 ) const
inline

Gets the value of a double field.

Parameters
fieldfield descriptor
arrIndexarray index (must be less than field array size)
Returns
field value

◆ GetFloatField()

float wpi::DynamicStruct::GetFloatField ( const StructFieldDescriptor * field,
size_t arrIndex = 0 ) const
inline

Gets the value of a float field.

Parameters
fieldfield descriptor
arrIndexarray index (must be less than field array size)
Returns
field value

◆ GetIntField()

int64_t wpi::DynamicStruct::GetIntField ( const StructFieldDescriptor * field,
size_t arrIndex = 0 ) const
inline

Gets the value of a signed integer field.

Parameters
fieldfield descriptor
arrIndexarray index (must be less than field array size)
Returns
field value

◆ GetStringField()

std::string_view wpi::DynamicStruct::GetStringField ( const StructFieldDescriptor * field) const

Gets the value of a char or char array field.

Parameters
fieldfield descriptor
Returns
field value

◆ GetStructField()

DynamicStruct wpi::DynamicStruct::GetStructField ( const StructFieldDescriptor * field,
size_t arrIndex = 0 ) const
inline

Gets the value of a struct field.

Parameters
fieldfield descriptor
arrIndexarray index (must be less than field array size)
Returns
field value

◆ GetUintField()

uint64_t wpi::DynamicStruct::GetUintField ( const StructFieldDescriptor * field,
size_t arrIndex = 0 ) const
inline

Gets the value of an unsigned integer field.

Parameters
fieldfield descriptor
arrIndexarray index (must be less than field array size)
Returns
field value

Member Data Documentation

◆ m_desc

const StructDescriptor* wpi::DynamicStruct::m_desc
protected

The documentation for this class was generated from the following file: