WPILibC++ 2024.3.2
wpi::MutableDynamicStruct Class Reference

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

#include <wpi/struct/DynamicStruct.h>

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

Public Member Functions

 MutableDynamicStruct (const StructDescriptor *desc, std::span< uint8_t > data)
 Constructs a new dynamic struct. More...
 
std::span< uint8_t > GetData ()
 Gets the serialized data. More...
 
void SetData (std::span< const uint8_t > data)
 Overwrites the entire serialized struct by copying data from a span. More...
 
void SetBoolField (const StructFieldDescriptor *field, bool value, size_t arrIndex=0)
 Sets the value of a boolean field. More...
 
void SetIntField (const StructFieldDescriptor *field, int64_t value, size_t arrIndex=0)
 Sets the value of a signed integer field. More...
 
void SetUintField (const StructFieldDescriptor *field, uint64_t value, size_t arrIndex=0)
 Sets the value of an unsigned integer field. More...
 
void SetFloatField (const StructFieldDescriptor *field, float value, size_t arrIndex=0)
 Sets the value of a float field. More...
 
void SetDoubleField (const StructFieldDescriptor *field, double value, size_t arrIndex=0)
 Sets the value of a double field. More...
 
bool SetStringField (const StructFieldDescriptor *field, std::string_view value)
 Sets the value of a char or char array field. More...
 
void SetStructField (const StructFieldDescriptor *field, const DynamicStruct &value, size_t arrIndex=0)
 Sets the value of a struct field. More...
 
MutableDynamicStruct GetStructField (const StructFieldDescriptor *field, size_t arrIndex=0)
 Gets the value of a struct field. More...
 
std::span< const uint8_t > GetData () const
 Gets the serialized data. More...
 
DynamicStruct GetStructField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a struct field. More...
 
- Public Member Functions inherited from wpi::DynamicStruct
 DynamicStruct (const StructDescriptor *desc, std::span< const uint8_t > data)
 Constructs a new dynamic struct. More...
 
const StructDescriptorGetDescriptor () const
 Gets the struct descriptor. More...
 
std::span< const uint8_t > GetData () const
 Gets the serialized data. More...
 
const StructFieldDescriptorFindField (std::string_view name) const
 Gets a struct field descriptor by name. More...
 
bool GetBoolField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a boolean field. More...
 
int64_t GetIntField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a signed integer field. More...
 
uint64_t GetUintField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of an unsigned integer field. More...
 
float GetFloatField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a float field. More...
 
double GetDoubleField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a double field. More...
 
std::string_view GetStringField (const StructFieldDescriptor *field) const
 Gets the value of a char or char array field. More...
 
DynamicStruct GetStructField (const StructFieldDescriptor *field, size_t arrIndex=0) const
 Gets the value of a struct field. More...
 

Additional Inherited Members

- Protected Attributes inherited from wpi::DynamicStruct
const StructDescriptorm_desc
 

Detailed Description

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

Constructor & Destructor Documentation

◆ MutableDynamicStruct()

wpi::MutableDynamicStruct::MutableDynamicStruct ( const StructDescriptor desc,
std::span< 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

◆ GetData() [1/2]

std::span< uint8_t > wpi::MutableDynamicStruct::GetData ( )
inline

Gets the serialized data.

Returns
data

◆ GetData() [2/2]

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

Gets the serialized data.

Returns
data

◆ GetStructField() [1/2]

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

Gets the value of a struct field.

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

◆ GetStructField() [2/2]

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

◆ SetBoolField()

void wpi::MutableDynamicStruct::SetBoolField ( const StructFieldDescriptor field,
bool  value,
size_t  arrIndex = 0 
)
inline

Sets the value of a boolean field.

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

◆ SetData()

void wpi::MutableDynamicStruct::SetData ( std::span< const uint8_t >  data)

Overwrites the entire serialized struct by copying data from a span.

Parameters
datareplacement data for the struct

◆ SetDoubleField()

void wpi::MutableDynamicStruct::SetDoubleField ( const StructFieldDescriptor field,
double  value,
size_t  arrIndex = 0 
)
inline

Sets the value of a double field.

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

◆ SetFloatField()

void wpi::MutableDynamicStruct::SetFloatField ( const StructFieldDescriptor field,
float  value,
size_t  arrIndex = 0 
)
inline

Sets the value of a float field.

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

◆ SetIntField()

void wpi::MutableDynamicStruct::SetIntField ( const StructFieldDescriptor field,
int64_t  value,
size_t  arrIndex = 0 
)
inline

Sets the value of a signed integer field.

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

◆ SetStringField()

bool wpi::MutableDynamicStruct::SetStringField ( const StructFieldDescriptor field,
std::string_view  value 
)

Sets the value of a char or char array field.

Parameters
fieldfield descriptor
valuefield value
Returns
true if the full value fit in the struct, false if truncated

◆ SetStructField()

void wpi::MutableDynamicStruct::SetStructField ( const StructFieldDescriptor field,
const DynamicStruct value,
size_t  arrIndex = 0 
)

Sets the value of a struct field.

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

◆ SetUintField()

void wpi::MutableDynamicStruct::SetUintField ( const StructFieldDescriptor field,
uint64_t  value,
size_t  arrIndex = 0 
)
inline

Sets the value of an unsigned integer field.

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

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