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 ,
  FBT_MAX_TYPE = 37
}
 
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 VerifyNestedFlexBuffer (const flatbuffers::Vector< uint8_t > *const nested, flatbuffers::Verifier &verifier)
 
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)
 
bool VerifyBuffer (const uint8_t *buf, size_t buf_len, std::vector< uint8_t > *reuse_tracker=nullptr)
 

Typedef Documentation

◆ half

typedef int16_t flexbuffers::half

Definition at line 130 of file flexbuffers.h.

◆ quarter

typedef int8_t flexbuffers::quarter

Definition at line 131 of file flexbuffers.h.

Enumeration Type Documentation

◆ BitWidth

Enumerator
BIT_WIDTH_8 
BIT_WIDTH_16 
BIT_WIDTH_32 
BIT_WIDTH_64 

Definition at line 43 of file flexbuffers.h.

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

◆ 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 909 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 
FBT_MAX_TYPE 

Definition at line 52 of file flexbuffers.h.

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

Function Documentation

◆ AppendToString()

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

Definition at line 364 of file flexbuffers.h.

364 {
365 s += "[ ";
366 for (size_t i = 0; i < v.size(); i++) {
367 if (i) s += ", ";
368 v[i].ToString(true, keys_quoted, s);
369 }
370 s += " ]";
371}

◆ GetRoot() [1/2]

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

Definition at line 895 of file flexbuffers.h.

895 {
896 return GetRoot(buffer.data(), buffer.size());
897}
Reference GetRoot(const uint8_t *buffer, size_t size)

References GetRoot().

◆ GetRoot() [2/2]

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

Definition at line 885 of file flexbuffers.h.

885 {
886 // See Finish() below for the serialization counterpart of this.
887 // The root starts at the end of the buffer, so we parse backwards from there.
888 auto end = buffer + size;
889 auto byte_width = *--end;
890 auto packed_type = *--end;
891 end -= byte_width; // The root data item.
892 return Reference(end, byte_width, packed_type);
893}
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 184 of file flexbuffers.h.

184 {
185 return offset - flatbuffers::ReadScalar<T>(offset);
186}
__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 180 of file flexbuffers.h.

180 {
181 return offset - ReadUInt64(offset, byte_width);
182}
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

Definition at line 100 of file flexbuffers.h.

100 {
101 return t >= FBT_VECTOR_INT2 && t <= FBT_VECTOR_FLOAT4;
102}

References FBT_VECTOR_FLOAT4, and FBT_VECTOR_INT2.

Referenced by flexbuffers::Reference::IsFixedTypedVector(), and ToFixedTypedVectorElementType().

◆ IsInline()

bool flexbuffers::IsInline ( Type  t)
inline

◆ IsTypedVector()

bool flexbuffers::IsTypedVector ( Type  t)
inline

Definition at line 95 of file flexbuffers.h.

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

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.

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

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 856 of file flexbuffers.h.

856 {
857 auto str_elem = reinterpret_cast<const char *>(
858 Indirect<T>(reinterpret_cast<const uint8_t *>(elem)));
859 auto skey = reinterpret_cast<const char *>(key);
860 return strcmp(skey, str_elem);
861}

◆ NullPackedType()

uint8_t flexbuffers::NullPackedType ( )
inline

Definition at line 826 of file flexbuffers.h.

826{ 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 822 of file flexbuffers.h.

822 {
823 return static_cast<uint8_t>(bit_width | (type << 2));
824}
int32_t type

References type.

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

◆ ReadDouble()

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

Definition at line 175 of file flexbuffers.h.

175 {
176 return ReadSizedScalar<double, quarter, half, float, double>(data,
177 byte_width);
178}

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 149 of file flexbuffers.h.

149 {
150 return ReadSizedScalar<int64_t, int8_t, int16_t, int32_t, int64_t>(
151 data, byte_width);
152}

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 139 of file flexbuffers.h.

139 {
140 return byte_width < 4
141 ? (byte_width < 2
142 ? static_cast<R>(flatbuffers::ReadScalar<T1>(data))
143 : static_cast<R>(flatbuffers::ReadScalar<T2>(data)))
144 : (byte_width < 8
145 ? static_cast<R>(flatbuffers::ReadScalar<T4>(data))
146 : static_cast<R>(flatbuffers::ReadScalar<T8>(data)));
147}

◆ ReadUInt64()

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

Definition at line 154 of file flexbuffers.h.

154 {
155 // This is the "hottest" function (all offset lookups use this), so worth
156 // optimizing if possible.
157 // TODO: GCC apparently replaces memcpy by a rep movsb, but only if count is a
158 // constant, which here it isn't. Test if memcpy is still faster than
159 // the conditionals in ReadSizedScalar. Can also use inline asm.
160
161 // clang-format off
162 #if defined(_MSC_VER) && defined(_M_X64) && !defined(_M_ARM64EC)
163 // This is 64-bit Windows only, __movsb does not work on 32-bit Windows.
164 uint64_t u = 0;
165 __movsb(reinterpret_cast<uint8_t *>(&u),
166 reinterpret_cast<const uint8_t *>(data), byte_width);
167 return flatbuffers::EndianScalar(u);
168 #else
169 return ReadSizedScalar<uint64_t, uint8_t, uint16_t, uint32_t, uint64_t>(
170 data, byte_width);
171 #endif
172 // clang-format on
173}

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 808 of file flexbuffers.h.

808 {
809 return AsString().str();
810}

◆ ToFixedTypedVectorElementType()

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

Definition at line 120 of file flexbuffers.h.

120 {
122 auto fixed_type = t - FBT_VECTOR_INT2;
123 *len = static_cast<uint8_t>(fixed_type / 3 +
124 2); // 3 types each, starting from length 2.
125 return static_cast<Type>(fixed_type % 3 + FBT_INT);
126}
#define FLATBUFFERS_ASSERT
Definition base.h:21
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 104 of file flexbuffers.h.

104 {
106 switch (fixed_len) {
107 case 0: return static_cast<Type>(t - FBT_INT + FBT_VECTOR_INT);
108 case 2: return static_cast<Type>(t - FBT_INT + FBT_VECTOR_INT2);
109 case 3: return static_cast<Type>(t - FBT_INT + FBT_VECTOR_INT3);
110 case 4: return static_cast<Type>(t - FBT_INT + FBT_VECTOR_INT4);
111 default: FLATBUFFERS_ASSERT(0); return FBT_NULL;
112 }
113}
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 115 of file flexbuffers.h.

115 {
117 return static_cast<Type>(t - FBT_VECTOR_INT + FBT_INT);
118}
bool IsTypedVector(Type t)
Definition flexbuffers.h:95

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

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

◆ VerifyBuffer()

bool flexbuffers::VerifyBuffer ( const uint8_t *  buf,
size_t  buf_len,
std::vector< uint8_t > *  reuse_tracker = nullptr 
)
inline

Definition at line 1875 of file flexbuffers.h.

1876 {
1877 Verifier verifier(buf, buf_len, reuse_tracker);
1878 return verifier.VerifyBuffer();
1879}

Referenced by VerifyNestedFlexBuffer().

◆ VerifyNestedFlexBuffer()

bool flexbuffers::VerifyNestedFlexBuffer ( const flatbuffers::Vector< uint8_t > *const  nested,
flatbuffers::Verifier &  verifier 
)
inline

Definition at line 26 of file flex_flat_util.h.

28 {
29 if (!nested) return true;
30 return verifier.Check(flexbuffers::VerifyBuffer(
31 nested->data(), nested->size(), verifier.GetFlexReuseTracker()));
32}
const T * data() const
Definition vector.h:260
SizeT size() const
Definition vector.h:164
bool VerifyBuffer(const uint8_t *buf, size_t buf_len, std::vector< uint8_t > *reuse_tracker=nullptr)

References flatbuffers::Vector< T, SizeT >::data(), flatbuffers::Vector< T, SizeT >::size(), and VerifyBuffer().

◆ WidthF()

BitWidth flexbuffers::WidthF ( double  f)
inline

Definition at line 205 of file flexbuffers.h.

205 {
206 return static_cast<double>(static_cast<float>(f)) == f ? BIT_WIDTH_32
207 : BIT_WIDTH_64;
208}

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 200 of file flexbuffers.h.

200 {
201 auto u = static_cast<uint64_t>(i) << 1;
202 return WidthU(i >= 0 ? u : ~u);
203}
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 188 of file flexbuffers.h.

188 {
189#define FLATBUFFERS_GET_FIELD_BIT_WIDTH(value, width) \
190 { \
191 if (!((u) & ~((1ULL << (width)) - 1ULL))) return BIT_WIDTH_##width; \
192 }
196#undef FLATBUFFERS_GET_FIELD_BIT_WIDTH
197 return BIT_WIDTH_64;
198}
#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().