ONE - On-device Neural Engine
Loading...
Searching...
No Matches
flexbuffers Namespace Reference

Data Structures

class  Blob
 
class  FixedTypedVector
 
class  FLATBUFFERS_FINAL_CLASS
 
class  Map
 
class  Object
 
class  Reference
 
class  Sized
 
class  String
 
class  TypedVector
 
class  Vector
 

Typedefs

typedef int16_t half
 
typedef int8_t quarter
 

Enumerations

enum  BitWidth { BIT_WIDTH_8 = 0 , BIT_WIDTH_16 = 1 , BIT_WIDTH_32 = 2 , BIT_WIDTH_64 = 3 }
 
enum  Type {
  FBT_NULL = 0 , FBT_INT = 1 , FBT_UINT = 2 , FBT_FLOAT = 3 ,
  FBT_KEY = 4 , FBT_STRING = 5 , FBT_INDIRECT_INT = 6 , FBT_INDIRECT_UINT = 7 ,
  FBT_INDIRECT_FLOAT = 8 , FBT_MAP = 9 , FBT_VECTOR = 10 , FBT_VECTOR_INT = 11 ,
  FBT_VECTOR_UINT = 12 , FBT_VECTOR_FLOAT = 13 , FBT_VECTOR_KEY = 14 , FBT_VECTOR_STRING_DEPRECATED = 15 ,
  FBT_VECTOR_INT2 = 16 , FBT_VECTOR_UINT2 = 17 , FBT_VECTOR_FLOAT2 = 18 , FBT_VECTOR_INT3 = 19 ,
  FBT_VECTOR_UINT3 = 20 , FBT_VECTOR_FLOAT3 = 21 , FBT_VECTOR_INT4 = 22 , FBT_VECTOR_UINT4 = 23 ,
  FBT_VECTOR_FLOAT4 = 24 , FBT_BLOB = 25 , FBT_BOOL = 26 , FBT_VECTOR_BOOL = 36
}
 
enum  BuilderFlag {
  BUILDER_FLAG_NONE = 0 , BUILDER_FLAG_SHARE_KEYS = 1 , BUILDER_FLAG_SHARE_STRINGS = 2 , BUILDER_FLAG_SHARE_KEYS_AND_STRINGS = 3 ,
  BUILDER_FLAG_SHARE_KEY_VECTORS = 4 , BUILDER_FLAG_SHARE_ALL = 7
}
 

Functions

bool IsInline (Type t)
 
bool IsTypedVectorElementType (Type t)
 
bool IsTypedVector (Type t)
 
bool IsFixedTypedVector (Type t)
 
Type ToTypedVector (Type t, size_t fixed_len=0)
 
Type ToTypedVectorElementType (Type t)
 
Type ToFixedTypedVectorElementType (Type t, uint8_t *len)
 
template<typename R , typename T1 , typename T2 , typename T4 , typename T8 >
ReadSizedScalar (const uint8_t *data, uint8_t byte_width)
 
int64_t ReadInt64 (const uint8_t *data, uint8_t byte_width)
 
uint64_t ReadUInt64 (const uint8_t *data, uint8_t byte_width)
 
double ReadDouble (const uint8_t *data, uint8_t byte_width)
 
const uint8_t * Indirect (const uint8_t *offset, uint8_t byte_width)
 
template<typename T >
const uint8_t * Indirect (const uint8_t *offset)
 
BitWidth WidthU (uint64_t u)
 
BitWidth WidthI (int64_t i)
 
BitWidth WidthF (double f)
 
template<typename T >
void AppendToString (std::string &s, T &&v, bool keys_quoted)
 
template<>
std::string Reference::As< std::string > () const
 
uint8_t PackedType (BitWidth bit_width, Type type)
 
uint8_t NullPackedType ()
 
template<typename T >
int KeyCompare (const void *key, const void *elem)
 
Reference GetRoot (const uint8_t *buffer, size_t size)
 
Reference GetRoot (const std::vector< uint8_t > &buffer)
 

Typedef Documentation

◆ half

typedef int16_t flexbuffers::half

Definition at line 138 of file flexbuffers.h.

◆ quarter

typedef int8_t flexbuffers::quarter

Definition at line 139 of file flexbuffers.h.

Enumeration Type Documentation

◆ BitWidth

Enumerator
BIT_WIDTH_8 
BIT_WIDTH_16 
BIT_WIDTH_32 
BIT_WIDTH_64 

Definition at line 44 of file flexbuffers.h.

45{
46 BIT_WIDTH_8 = 0,
47 BIT_WIDTH_16 = 1,
48 BIT_WIDTH_32 = 2,
49 BIT_WIDTH_64 = 3,
50};

◆ BuilderFlag

Enumerator
BUILDER_FLAG_NONE 
BUILDER_FLAG_SHARE_KEYS 
BUILDER_FLAG_SHARE_STRINGS 
BUILDER_FLAG_SHARE_KEYS_AND_STRINGS 
BUILDER_FLAG_SHARE_KEY_VECTORS 
BUILDER_FLAG_SHARE_ALL 

Definition at line 1033 of file flexbuffers.h.

◆ Type

Enumerator
FBT_NULL 
FBT_INT 
FBT_UINT 
FBT_FLOAT 
FBT_KEY 
FBT_STRING 
FBT_INDIRECT_INT 
FBT_INDIRECT_UINT 
FBT_INDIRECT_FLOAT 
FBT_MAP 
FBT_VECTOR 
FBT_VECTOR_INT 
FBT_VECTOR_UINT 
FBT_VECTOR_FLOAT 
FBT_VECTOR_KEY 
FBT_VECTOR_STRING_DEPRECATED 
FBT_VECTOR_INT2 
FBT_VECTOR_UINT2 
FBT_VECTOR_FLOAT2 
FBT_VECTOR_INT3 
FBT_VECTOR_UINT3 
FBT_VECTOR_FLOAT3 
FBT_VECTOR_INT4 
FBT_VECTOR_UINT4 
FBT_VECTOR_FLOAT4 
FBT_BLOB 
FBT_BOOL 
FBT_VECTOR_BOOL 

Definition at line 54 of file flexbuffers.h.

55{
56 FBT_NULL = 0,
57 FBT_INT = 1,
58 FBT_UINT = 2,
59 FBT_FLOAT = 3,
60 // Types above stored inline, types below store an offset.
61 FBT_KEY = 4,
62 FBT_STRING = 5,
66 FBT_MAP = 9,
67 FBT_VECTOR = 10, // Untyped.
68 FBT_VECTOR_INT = 11, // Typed any size (stores no type table).
69 FBT_VECTOR_UINT = 12,
71 FBT_VECTOR_KEY = 14,
72 // DEPRECATED, use FBT_VECTOR or FBT_VECTOR_KEY instead.
73 // Read test.cpp/FlexBuffersDeprecatedTest() for details on why.
75 FBT_VECTOR_INT2 = 16, // Typed tuple (no type table, no size field).
78 FBT_VECTOR_INT3 = 19, // Typed triple (no type table, no size field).
81 FBT_VECTOR_INT4 = 22, // Typed quad (no type table, no size field).
84 FBT_BLOB = 25,
85 FBT_BOOL = 26,
86 FBT_VECTOR_BOOL = 36, // To Allow the same type of conversion of type to vector type
87};
@ FBT_VECTOR_STRING_DEPRECATED
Definition flexbuffers.h:74

Function Documentation

◆ AppendToString()

template<typename T >
void flexbuffers::AppendToString ( std::string &  s,
T &&  v,
bool  keys_quoted 
)

Definition at line 377 of file flexbuffers.h.

378{
379 s += "[ ";
380 for (size_t i = 0; i < v.size(); i++)
381 {
382 if (i)
383 s += ", ";
384 v[i].ToString(true, keys_quoted, s);
385 }
386 s += " ]";
387}

◆ GetRoot() [1/2]

Reference flexbuffers::GetRoot ( const std::vector< uint8_t > &  buffer)
inline

Definition at line 1018 of file flexbuffers.h.

1019{
1020 return GetRoot(flatbuffers::vector_data(buffer), buffer.size());
1021}
T * vector_data(std::vector< T > &vector)
Reference GetRoot(const uint8_t *buffer, size_t size)

References GetRoot(), and flatbuffers::vector_data().

◆ GetRoot() [2/2]

Reference flexbuffers::GetRoot ( const uint8_t *  buffer,
size_t  size 
)
inline

Definition at line 1007 of file flexbuffers.h.

1008{
1009 // See Finish() below for the serialization counterpart of this.
1010 // The root starts at the end of the buffer, so we parse backwards from there.
1011 auto end = buffer + size;
1012 auto byte_width = *--end;
1013 auto packed_type = *--end;
1014 end -= byte_width; // The root data item.
1015 return Reference(end, byte_width, packed_type);
1016}
int32_t size[5]
Definition Slice.cpp:35

References size.

Referenced by GetRoot(), circledump::CustomOpPrinter::options(), and tfldump::CustomOpPrinter::options().

◆ Indirect() [1/2]

template<typename T >
const uint8_t * flexbuffers::Indirect ( const uint8_t *  offset)

Definition at line 182 of file flexbuffers.h.

183{
184 return offset - flatbuffers::ReadScalar<T>(offset);
185}
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540

References offset().

◆ Indirect() [2/2]

const uint8_t * flexbuffers::Indirect ( const uint8_t *  offset,
uint8_t  byte_width 
)
inline

Definition at line 177 of file flexbuffers.h.

178{
179 return offset - ReadUInt64(offset, byte_width);
180}
uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width)

References offset(), and ReadUInt64().

Referenced by flexbuffers::Map::Keys().

◆ IsFixedTypedVector()

bool flexbuffers::IsFixedTypedVector ( Type  t)
inline

◆ IsInline()

bool flexbuffers::IsInline ( Type  t)
inline

◆ IsTypedVector()

bool flexbuffers::IsTypedVector ( Type  t)
inline

Definition at line 96 of file flexbuffers.h.

97{
98 return (t >= FBT_VECTOR_INT && t <= FBT_VECTOR_STRING_DEPRECATED) || t == FBT_VECTOR_BOOL;
99}

References FBT_VECTOR_BOOL, FBT_VECTOR_INT, and FBT_VECTOR_STRING_DEPRECATED.

Referenced by flexbuffers::Reference::IsTypedVector(), and ToTypedVectorElementType().

◆ IsTypedVectorElementType()

bool flexbuffers::IsTypedVectorElementType ( Type  t)
inline

Definition at line 91 of file flexbuffers.h.

92{
93 return (t >= FBT_INT && t <= FBT_STRING) || t == FBT_BOOL;
94}

References FBT_BOOL, FBT_INT, and FBT_STRING.

Referenced by ToTypedVector().

◆ KeyCompare()

template<typename T >
int flexbuffers::KeyCompare ( const void *  key,
const void *  elem 
)

Definition at line 969 of file flexbuffers.h.

970{
971 auto str_elem =
972 reinterpret_cast<const char *>(Indirect<T>(reinterpret_cast<const uint8_t *>(elem)));
973 auto skey = reinterpret_cast<const char *>(key);
974 return strcmp(skey, str_elem);
975}

◆ NullPackedType()

uint8_t flexbuffers::NullPackedType ( )
inline

Definition at line 933 of file flexbuffers.h.

933{ return PackedType(BIT_WIDTH_8, FBT_NULL); }
uint8_t PackedType(BitWidth bit_width, Type type)

References BIT_WIDTH_8, FBT_NULL, and PackedType().

Referenced by flexbuffers::Map::operator[](), flexbuffers::Vector::operator[](), flexbuffers::TypedVector::operator[](), and flexbuffers::FixedTypedVector::operator[]().

◆ PackedType()

uint8_t flexbuffers::PackedType ( BitWidth  bit_width,
Type  type 
)
inline

Definition at line 928 of file flexbuffers.h.

929{
930 return static_cast<uint8_t>(bit_width | (type << 2));
931}

Referenced by NullPackedType(), and flexbuffers::FLATBUFFERS_FINAL_CLASS::Value::StoredPackedType().

◆ ReadDouble()

double flexbuffers::ReadDouble ( const uint8_t *  data,
uint8_t  byte_width 
)
inline

Definition at line 172 of file flexbuffers.h.

173{
174 return ReadSizedScalar<double, quarter, half, float, double>(data, byte_width);
175}

Referenced by flexbuffers::Reference::AsDouble(), flexbuffers::Reference::AsInt64(), and flexbuffers::Reference::AsUInt64().

◆ ReadInt64()

int64_t flexbuffers::ReadInt64 ( const uint8_t *  data,
uint8_t  byte_width 
)
inline

Definition at line 155 of file flexbuffers.h.

156{
157 return ReadSizedScalar<int64_t, int8_t, int16_t, int32_t, int64_t>(data, byte_width);
158}

Referenced by flexbuffers::Reference::AsDouble(), flexbuffers::Reference::AsInt64(), and flexbuffers::Reference::AsUInt64().

◆ ReadSizedScalar()

template<typename R , typename T1 , typename T2 , typename T4 , typename T8 >
R flexbuffers::ReadSizedScalar ( const uint8_t *  data,
uint8_t  byte_width 
)

Definition at line 147 of file flexbuffers.h.

148{
149 return byte_width < 4 ? (byte_width < 2 ? static_cast<R>(flatbuffers::ReadScalar<T1>(data))
150 : static_cast<R>(flatbuffers::ReadScalar<T2>(data)))
151 : (byte_width < 8 ? static_cast<R>(flatbuffers::ReadScalar<T4>(data))
152 : static_cast<R>(flatbuffers::ReadScalar<T8>(data)));
153}

◆ ReadUInt64()

uint64_t flexbuffers::ReadUInt64 ( const uint8_t *  data,
uint8_t  byte_width 
)
inline

Definition at line 160 of file flexbuffers.h.

161{
162#if defined(_MSC_VER) && ((defined(_M_X64) && !defined(_M_ARM64EC)) || defined _M_IX86)
163 uint64_t u = 0;
164 __movsb(reinterpret_cast<uint8_t *>(&u), reinterpret_cast<const uint8_t *>(data), byte_width);
165 return flatbuffers::EndianScalar(u);
166#else
167 return ReadSizedScalar<uint64_t, uint8_t, uint16_t, uint32_t, uint64_t>(data, byte_width);
168#endif
169 // clang-format on
170}

Referenced by flexbuffers::Reference::AsBool(), flexbuffers::Reference::AsDouble(), flexbuffers::Reference::AsInt64(), flexbuffers::Reference::AsUInt64(), Indirect(), flexbuffers::Map::Keys(), and flexbuffers::Sized::read_size().

◆ Reference::As< std::string >()

template<>
std::string flexbuffers::Reference::As< std::string > ( ) const
inline

Definition at line 917 of file flexbuffers.h.

917{ return AsString().str(); }

◆ ToFixedTypedVectorElementType()

Type flexbuffers::ToFixedTypedVectorElementType ( Type  t,
uint8_t *  len 
)
inline

Definition at line 128 of file flexbuffers.h.

129{
131 auto fixed_type = t - FBT_VECTOR_INT2;
132 *len = static_cast<uint8_t>(fixed_type / 3 + 2); // 3 types each, starting from length 2.
133 return static_cast<Type>(fixed_type % 3 + FBT_INT);
134}
#define FLATBUFFERS_ASSERT
Definition base.h:37
bool IsFixedTypedVector(Type t)

References FBT_INT, FBT_VECTOR_INT2, FLATBUFFERS_ASSERT, and IsFixedTypedVector().

Referenced by flexbuffers::Reference::AsFixedTypedVector().

◆ ToTypedVector()

Type flexbuffers::ToTypedVector ( Type  t,
size_t  fixed_len = 0 
)
inline

Definition at line 103 of file flexbuffers.h.

104{
106 switch (fixed_len)
107 {
108 case 0:
109 return static_cast<Type>(t - FBT_INT + FBT_VECTOR_INT);
110 case 2:
111 return static_cast<Type>(t - FBT_INT + FBT_VECTOR_INT2);
112 case 3:
113 return static_cast<Type>(t - FBT_INT + FBT_VECTOR_INT3);
114 case 4:
115 return static_cast<Type>(t - FBT_INT + FBT_VECTOR_INT4);
116 default:
118 return FBT_NULL;
119 }
120}
bool IsTypedVectorElementType(Type t)
Definition flexbuffers.h:91

References FBT_INT, FBT_NULL, FBT_VECTOR_INT, FBT_VECTOR_INT2, FBT_VECTOR_INT3, FBT_VECTOR_INT4, FLATBUFFERS_ASSERT, and IsTypedVectorElementType().

◆ ToTypedVectorElementType()

Type flexbuffers::ToTypedVectorElementType ( Type  t)
inline

Definition at line 122 of file flexbuffers.h.

123{
125 return static_cast<Type>(t - FBT_VECTOR_INT + FBT_INT);
126}
bool IsTypedVector(Type t)
Definition flexbuffers.h:96

References FBT_INT, FBT_VECTOR_INT, FLATBUFFERS_ASSERT, and IsTypedVector().

Referenced by flexbuffers::Reference::AsTypedVector().

◆ WidthF()

BitWidth flexbuffers::WidthF ( double  f)
inline

Definition at line 207 of file flexbuffers.h.

208{
209 return static_cast<double>(static_cast<float>(f)) == f ? BIT_WIDTH_32 : BIT_WIDTH_64;
210}

References BIT_WIDTH_32, and BIT_WIDTH_64.

Referenced by flexbuffers::FLATBUFFERS_FINAL_CLASS::IndirectDouble(), flexbuffers::Reference::MutateFloat(), and flexbuffers::FLATBUFFERS_FINAL_CLASS::Value::Value().

◆ WidthI()

BitWidth flexbuffers::WidthI ( int64_t  i)
inline

Definition at line 201 of file flexbuffers.h.

202{
203 auto u = static_cast<uint64_t>(i) << 1;
204 return WidthU(i >= 0 ? u : ~u);
205}
BitWidth WidthU(uint64_t u)

References WidthU().

Referenced by flexbuffers::FLATBUFFERS_FINAL_CLASS::IndirectInt(), flexbuffers::FLATBUFFERS_FINAL_CLASS::Int(), flexbuffers::Reference::MutateInt(), and flexbuffers::Reference::MutateUInt().

◆ WidthU()

BitWidth flexbuffers::WidthU ( uint64_t  u)
inline

Definition at line 187 of file flexbuffers.h.

188{
189#define FLATBUFFERS_GET_FIELD_BIT_WIDTH(value, width) \
190 { \
191 if (!((u) & ~((1ULL << (width)) - 1ULL))) \
192 return BIT_WIDTH_##width; \
193 }
197#undef FLATBUFFERS_GET_FIELD_BIT_WIDTH
198 return BIT_WIDTH_64;
199}
#define FLATBUFFERS_GET_FIELD_BIT_WIDTH(value, width)

References BIT_WIDTH_64, and FLATBUFFERS_GET_FIELD_BIT_WIDTH.

Referenced by flexbuffers::FLATBUFFERS_FINAL_CLASS::Value::ElemWidth(), flexbuffers::FLATBUFFERS_FINAL_CLASS::IndirectUInt(), flexbuffers::Reference::MutateInt(), flexbuffers::Reference::MutateUInt(), flexbuffers::FLATBUFFERS_FINAL_CLASS::UInt(), and WidthI().