13#include <unordered_set> 
   26class MutableDynamicStruct;
 
   27class StructDescriptor;
 
   28class StructDescriptorDatabase;
 
   66  struct private_init {};
 
   76  using EnumValues = std::vector<std::pair<std::string, int64_t>>;
 
   96  const std::string& 
GetName()
 const { 
return m_name; }
 
  149    return m_bitWidth == 0 ? m_size * 8 : m_bitWidth;
 
 
  172  bool IsArray()
 const { 
return m_arraySize > 1; }
 
  186  bool HasEnum()
 const { 
return !m_enum.empty(); }
 
  222    return static_cast<int64_t
>(-(m_bitMask >> 1)) - 1;
 
 
  238    return (m_bitShift != 0 || m_bitWidth != (m_size * 8)) &&
 
 
  253  unsigned int m_bitWidth;
 
  254  unsigned int m_bitShift = 0;
 
 
  261  struct private_init {};
 
  272  const std::string& 
GetName()
 const { 
return m_name; }
 
  279  const std::string& 
GetSchema()
 const { 
return m_schema; }
 
  314  const std::vector<StructFieldDescriptor>& 
GetFields()
 const {
 
 
  321  std::string CalculateOffsets(
 
  325  std::string m_schema;
 
  326  std::vector<StructDescriptor*> m_references;
 
  327  std::vector<StructFieldDescriptor> m_fields;
 
  330  bool m_valid = 
false;
 
 
  377      : 
m_desc{desc}, m_data{data} {}
 
 
  391  std::span<const uint8_t> 
GetData()
 const { 
return m_data; }
 
  411                    size_t arrIndex = 0)
 const {
 
  413    return GetFieldImpl(field, arrIndex);
 
 
  424                      size_t arrIndex = 0)
 const {
 
  425    assert(field->
IsInt());
 
  426    uint64_t raw = GetFieldImpl(field, arrIndex);
 
  427    switch (field->m_size) {
 
  429        return static_cast<int8_t
>(raw);
 
  431        return static_cast<int16_t
>(raw);
 
  433        return static_cast<int32_t
>(raw);
 
 
  447                        size_t arrIndex = 0)
 const {
 
  449    return GetFieldImpl(field, arrIndex);
 
 
  460                      size_t arrIndex = 0)
 const {
 
  463        static_cast<uint32_t
>(GetFieldImpl(field, arrIndex)));
 
 
  474                        size_t arrIndex = 0)
 const {
 
 
  495                               size_t arrIndex = 0)
 const {
 
  497    assert(field->m_parent == 
m_desc);
 
  499    assert(arrIndex < field->m_arraySize);
 
  501                         m_data.subspan(field->m_offset +
 
  502                                        arrIndex * field->m_struct->
GetSize())};
 
 
  510                        size_t arrIndex) 
const;
 
  512  std::span<const uint8_t> m_data;
 
 
  536  std::span<uint8_t> 
GetData() { 
return m_data; }
 
  555                    size_t arrIndex = 0) {
 
  557    SetFieldImpl(field, value ? 1 : 0, arrIndex);
 
 
  568                   size_t arrIndex = 0) {
 
  569    assert(field->
IsInt());
 
  570    SetFieldImpl(field, value, arrIndex);
 
 
  581                    size_t arrIndex = 0) {
 
  583    SetFieldImpl(field, value, arrIndex);
 
 
  594                     size_t arrIndex = 0) {
 
 
  607                      size_t arrIndex = 0) {
 
 
  620                      std::string_view value);
 
  640                                      size_t arrIndex = 0) {
 
  642    assert(field->m_parent == 
m_desc);
 
  644    assert(arrIndex < field->m_arraySize);
 
  646        field->m_struct, m_data.subspan(field->m_offset +
 
  647                                        arrIndex * field->m_struct->
GetSize())};
 
 
  656  std::span<uint8_t> m_data;
 
 
  662  explicit DSOData(std::span<const uint8_t> data)
 
 
 
 
  690                      std::span<const uint8_t> data)
 
  692    assert(data.size() >= desc->
GetSize());
 
 
This file implements the C++20 <bit> header.
Dynamic (run-time) read-only access to a serialized raw struct.
Definition DynamicStruct.h:366
std::span< const uint8_t > GetData() const
Gets the serialized data.
Definition DynamicStruct.h:391
uint64_t GetUintField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of an unsigned integer field.
Definition DynamicStruct.h:446
const StructDescriptor * m_desc
Definition DynamicStruct.h:506
const StructFieldDescriptor * FindField(std::string_view name) const
Gets a struct field descriptor by name.
Definition DynamicStruct.h:399
DynamicStruct GetStructField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a struct field.
Definition DynamicStruct.h:494
DynamicStruct(const StructDescriptor *desc, std::span< const uint8_t > data)
Constructs a new dynamic struct.
Definition DynamicStruct.h:376
double GetDoubleField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a double field.
Definition DynamicStruct.h:473
const StructDescriptor * GetDescriptor() const
Gets the struct descriptor.
Definition DynamicStruct.h:384
int64_t GetIntField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a signed integer field.
Definition DynamicStruct.h:423
bool GetBoolField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a boolean field.
Definition DynamicStruct.h:410
std::string_view GetStringField(const StructFieldDescriptor *field) const
Gets the value of a char or char array field.
float GetFloatField(const StructFieldDescriptor *field, size_t arrIndex=0) const
Gets the value of a float field.
Definition DynamicStruct.h:459
Dynamic (run-time) mutable access to a serialized raw struct, with internal data storage.
Definition DynamicStruct.h:673
Dynamic (run-time) mutable access to a serialized raw struct.
Definition DynamicStruct.h:518
void SetFloatField(const StructFieldDescriptor *field, float value, size_t arrIndex=0)
Sets the value of a float field.
Definition DynamicStruct.h:593
void SetBoolField(const StructFieldDescriptor *field, bool value, size_t arrIndex=0)
Sets the value of a boolean field.
Definition DynamicStruct.h:554
MutableDynamicStruct GetStructField(const StructFieldDescriptor *field, size_t arrIndex=0)
Gets the value of a struct field.
Definition DynamicStruct.h:639
void SetUintField(const StructFieldDescriptor *field, uint64_t value, size_t arrIndex=0)
Sets the value of an unsigned integer field.
Definition DynamicStruct.h:580
MutableDynamicStruct(const StructDescriptor *desc, std::span< uint8_t > data)
Constructs a new dynamic struct.
Definition DynamicStruct.h:528
std::span< uint8_t > GetData()
Gets the serialized data.
Definition DynamicStruct.h:536
bool SetStringField(const StructFieldDescriptor *field, std::string_view value)
Sets the value of a char or char array field.
void SetDoubleField(const StructFieldDescriptor *field, double value, size_t arrIndex=0)
Sets the value of a double field.
Definition DynamicStruct.h:606
void SetData(std::span< const uint8_t > data)
Overwrites the entire serialized struct by copying data from a span.
void SetStructField(const StructFieldDescriptor *field, const DynamicStruct &value, size_t arrIndex=0)
Sets the value of a struct field.
void SetIntField(const StructFieldDescriptor *field, int64_t value, size_t arrIndex=0)
Sets the value of a signed integer field.
Definition DynamicStruct.h:567
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition sha1.h:30
StringMap is a sorted associative container that contains key-value pairs with unique string keys.
Definition StringMap.h:26
Database of raw struct dynamic descriptors.
Definition DynamicStruct.h:336
const StructDescriptor * Find(std::string_view name) const
Finds a structure in the database by name.
const StructDescriptor * Add(std::string_view name, std::string_view schema, std::string *err)
Adds a structure schema to the database.
Raw struct dynamic struct descriptor.
Definition DynamicStruct.h:260
const StructFieldDescriptor * FindFieldByName(std::string_view name) const
Gets a field descriptor by name.
StructDescriptor(std::string_view name, const private_init &)
Definition DynamicStruct.h:265
const std::vector< StructFieldDescriptor > & GetFields() const
Gets all field descriptors.
Definition DynamicStruct.h:314
size_t GetSize() const
Returns the struct size, in bytes.
Definition DynamicStruct.h:294
bool IsValid() const
Returns whether the struct is valid (e.g.
Definition DynamicStruct.h:287
const std::string & GetSchema() const
Gets the struct schema.
Definition DynamicStruct.h:279
const std::string & GetName() const
Gets the struct name.
Definition DynamicStruct.h:272
Raw struct dynamic field descriptor.
Definition DynamicStruct.h:65
const StructDescriptor * GetStruct() const
Gets the struct descriptor for a struct data type.
Definition DynamicStruct.h:200
size_t GetOffset() const
Gets the storage offset of the field, in bytes.
Definition DynamicStruct.h:141
StructFieldType GetType() const
Gets the field type.
Definition DynamicStruct.h:103
const StructDescriptor * GetParent() const
Gets the dynamic struct this field is contained in.
Definition DynamicStruct.h:89
int64_t GetIntMax() const
Gets the maximum signed integer value that can be stored in this field.
Definition DynamicStruct.h:230
const std::string & GetName() const
Gets the field name.
Definition DynamicStruct.h:96
std::vector< std::pair< std::string, int64_t > > EnumValues
Set of enumerated values.
Definition DynamicStruct.h:76
const EnumValues & GetEnumValues()
Gets the enumerated values.
Definition DynamicStruct.h:193
uint64_t GetUintMin() const
Gets the minimum unsigned integer value that can be stored in this field.
Definition DynamicStruct.h:207
unsigned int GetBitShift() const
Gets the bit shift for the field (LSB=0).
Definition DynamicStruct.h:165
size_t GetSize() const
Gets the underlying storage size of the field, in bytes.
Definition DynamicStruct.h:134
bool IsUint() const
Returns whether the field type is an unsigned integer.
Definition DynamicStruct.h:122
bool IsArray() const
Returns whether the field is an array.
Definition DynamicStruct.h:172
int64_t GetIntMin() const
Gets the minimum signed integer value that can be stored in this field.
Definition DynamicStruct.h:221
bool HasEnum() const
Returns whether the field has enumerated values.
Definition DynamicStruct.h:186
StructFieldDescriptor(const StructDescriptor *parent, std::string_view name, StructFieldType type, size_t size, size_t arraySize, unsigned int bitWidth, EnumValues enumValues, const StructDescriptor *structDesc, const private_init &)
unsigned int GetBitWidth() const
Gets the bit width of the field, in bits.
Definition DynamicStruct.h:148
uint64_t GetBitMask() const
Gets the bit mask for the field.
Definition DynamicStruct.h:158
uint64_t GetUintMax() const
Gets the maximum unsigned integer value that can be stored in this field.
Definition DynamicStruct.h:214
size_t GetArraySize() const
Gets the array size.
Definition DynamicStruct.h:179
bool IsInt() const
Returns whether the field type is a signed integer.
Definition DynamicStruct.h:110
bool IsBitField() const
Returns whether the field is a bitfield.
Definition DynamicStruct.h:237
Foonathan namespace.
Definition ntcore_cpp.h:26
StructFieldType
Known data types for raw struct dynamic fields (see StructFieldDescriptor).
Definition DynamicStruct.h:33
To bit_cast(const From &from) noexcept
Definition bit.h:51
Definition DynamicStruct.h:660
DSOData(std::span< const uint8_t > data)
Definition DynamicStruct.h:662
std::vector< uint8_t > m_dataStore
Definition DynamicStruct.h:665
DSOData(size_t size)
Definition DynamicStruct.h:661