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

#include <flexbuffers.h>

Public Member Functions

 Reference ()
 
 Reference (const uint8_t *data, uint8_t parent_width, uint8_t byte_width, Type type)
 
 Reference (const uint8_t *data, uint8_t parent_width, uint8_t packed_type)
 
Type GetType () const
 
bool IsNull () const
 
bool IsBool () const
 
bool IsInt () const
 
bool IsUInt () const
 
bool IsIntOrUint () const
 
bool IsFloat () const
 
bool IsNumeric () const
 
bool IsString () const
 
bool IsKey () const
 
bool IsVector () const
 
bool IsUntypedVector () const
 
bool IsTypedVector () const
 
bool IsFixedTypedVector () const
 
bool IsAnyVector () const
 
bool IsMap () const
 
bool IsBlob () const
 
bool AsBool () const
 
int64_t AsInt64 () const
 
int32_t AsInt32 () const
 
int16_t AsInt16 () const
 
int8_t AsInt8 () const
 
uint64_t AsUInt64 () const
 
uint32_t AsUInt32 () const
 
uint16_t AsUInt16 () const
 
uint8_t AsUInt8 () const
 
double AsDouble () const
 
float AsFloat () const
 
const char * AsKey () const
 
String AsString () const
 
std::string ToString () const
 
void ToString (bool strings_quoted, bool keys_quoted, std::string &s) const
 
Blob AsBlob () const
 
Vector AsVector () const
 
TypedVector AsTypedVector () const
 
FixedTypedVector AsFixedTypedVector () const
 
Map AsMap () const
 
template<typename T >
As () const
 
bool MutateInt (int64_t i)
 
bool MutateBool (bool b)
 
bool MutateUInt (uint64_t u)
 
bool MutateFloat (float f)
 
bool MutateFloat (double d)
 
bool MutateString (const char *str, size_t len)
 
bool MutateString (const char *str)
 
bool MutateString (const std::string &str)
 
template<>
bool As () const
 
template<>
int8_t As () const
 
template<>
int16_t As () const
 
template<>
int32_t As () const
 
template<>
int64_t As () const
 
template<>
uint8_t As () const
 
template<>
uint16_t As () const
 
template<>
uint32_t As () const
 
template<>
uint64_t As () const
 
template<>
double As () const
 
template<>
float As () const
 
template<>
String As () const
 
template<>
Blob As () const
 
template<>
Vector As () const
 
template<>
TypedVector As () const
 
template<>
FixedTypedVector As () const
 
template<>
Map As () const
 

Friends

class Verifier
 

Detailed Description

Definition at line 373 of file flexbuffers.h.

Constructor & Destructor Documentation

◆ Reference() [1/3]

flexbuffers::Reference::Reference ( )
inline

Definition at line 375 of file flexbuffers.h.

376 : data_(nullptr), parent_width_(0), byte_width_(0), type_(FBT_NULL) {}

◆ Reference() [2/3]

flexbuffers::Reference::Reference ( const uint8_t *  data,
uint8_t  parent_width,
uint8_t  byte_width,
Type  type 
)
inline

Definition at line 378 of file flexbuffers.h.

380 : data_(data),
381 parent_width_(parent_width),
382 byte_width_(byte_width),
383 type_(type) {}
int32_t type

◆ Reference() [3/3]

flexbuffers::Reference::Reference ( const uint8_t *  data,
uint8_t  parent_width,
uint8_t  packed_type 
)
inline

Definition at line 385 of file flexbuffers.h.

386 : data_(data),
387 parent_width_(parent_width),
388 byte_width_(static_cast<uint8_t>(1 << (packed_type & 3))),
389 type_(static_cast<Type>(packed_type >> 2)) {}

Member Function Documentation

◆ As() [1/18]

template<typename T >
T flexbuffers::Reference::As ( ) const

◆ As() [2/18]

template<>
bool flexbuffers::Reference::As ( ) const
inline

Definition at line 786 of file flexbuffers.h.

786{ return AsBool(); }

References AsBool().

◆ As() [3/18]

template<>
int8_t flexbuffers::Reference::As ( ) const
inline

Definition at line 788 of file flexbuffers.h.

788{ return AsInt8(); }
int8_t AsInt8() const

References AsInt8().

◆ As() [4/18]

template<>
int16_t flexbuffers::Reference::As ( ) const
inline

Definition at line 789 of file flexbuffers.h.

789{ return AsInt16(); }
int16_t AsInt16() const

References AsInt16().

◆ As() [5/18]

template<>
int32_t flexbuffers::Reference::As ( ) const
inline

Definition at line 790 of file flexbuffers.h.

790{ return AsInt32(); }
int32_t AsInt32() const

References AsInt32().

◆ As() [6/18]

template<>
int64_t flexbuffers::Reference::As ( ) const
inline

Definition at line 791 of file flexbuffers.h.

791{ return AsInt64(); }
int64_t AsInt64() const

References AsInt64().

◆ As() [7/18]

template<>
uint8_t flexbuffers::Reference::As ( ) const
inline

Definition at line 793 of file flexbuffers.h.

793{ return AsUInt8(); }
uint8_t AsUInt8() const

References AsUInt8().

◆ As() [8/18]

template<>
uint16_t flexbuffers::Reference::As ( ) const
inline

Definition at line 794 of file flexbuffers.h.

794 {
795 return AsUInt16();
796}
uint16_t AsUInt16() const

References AsUInt16().

◆ As() [9/18]

template<>
uint32_t flexbuffers::Reference::As ( ) const
inline

Definition at line 797 of file flexbuffers.h.

797 {
798 return AsUInt32();
799}
uint32_t AsUInt32() const

References AsUInt32().

◆ As() [10/18]

template<>
uint64_t flexbuffers::Reference::As ( ) const
inline

Definition at line 800 of file flexbuffers.h.

800 {
801 return AsUInt64();
802}
uint64_t AsUInt64() const

References AsUInt64().

◆ As() [11/18]

template<>
double flexbuffers::Reference::As ( ) const
inline

Definition at line 804 of file flexbuffers.h.

804{ return AsDouble(); }
double AsDouble() const

References AsDouble().

◆ As() [12/18]

template<>
float flexbuffers::Reference::As ( ) const
inline

Definition at line 805 of file flexbuffers.h.

805{ return AsFloat(); }
float AsFloat() const

References AsFloat().

◆ As() [13/18]

template<>
String flexbuffers::Reference::As ( ) const
inline

Definition at line 807 of file flexbuffers.h.

807{ return AsString(); }
String AsString() const

References AsString().

◆ As() [14/18]

template<>
Blob flexbuffers::Reference::As ( ) const
inline

Definition at line 812 of file flexbuffers.h.

812{ return AsBlob(); }

References AsBlob().

◆ As() [15/18]

template<>
Vector flexbuffers::Reference::As ( ) const
inline

Definition at line 813 of file flexbuffers.h.

813{ return AsVector(); }
Vector AsVector() const

References AsVector().

◆ As() [16/18]

template<>
TypedVector flexbuffers::Reference::As ( ) const
inline

Definition at line 814 of file flexbuffers.h.

814 {
815 return AsTypedVector();
816}
TypedVector AsTypedVector() const

References AsTypedVector().

◆ As() [17/18]

template<>
FixedTypedVector flexbuffers::Reference::As ( ) const
inline

Definition at line 817 of file flexbuffers.h.

817 {
818 return AsFixedTypedVector();
819}
FixedTypedVector AsFixedTypedVector() const

References AsFixedTypedVector().

◆ As() [18/18]

template<>
Map flexbuffers::Reference::As ( ) const
inline

Definition at line 820 of file flexbuffers.h.

820{ return AsMap(); }

References AsMap().

◆ AsBlob()

Blob flexbuffers::Reference::AsBlob ( ) const
inline

Definition at line 616 of file flexbuffers.h.

616 {
617 if (type_ == FBT_BLOB || type_ == FBT_STRING) {
618 return Blob(Indirect(), byte_width_);
619 } else {
620 return Blob::EmptyBlob();
621 }
622 }
static Blob EmptyBlob()

References flexbuffers::Blob::EmptyBlob(), flexbuffers::FBT_BLOB, and flexbuffers::FBT_STRING.

Referenced by As(), and ToString().

◆ AsBool()

bool flexbuffers::Reference::AsBool ( ) const
inline

Definition at line 417 of file flexbuffers.h.

417 {
418 return (type_ == FBT_BOOL ? ReadUInt64(data_, parent_width_)
419 : AsUInt64()) != 0;
420 }
uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width)

References AsUInt64(), flexbuffers::FBT_BOOL, and flexbuffers::ReadUInt64().

Referenced by As(), and ToString().

◆ AsDouble()

double flexbuffers::Reference::AsDouble ( ) const
inline

Definition at line 481 of file flexbuffers.h.

481 {
482 if (type_ == FBT_FLOAT) {
483 // A fast path for the common case.
484 return ReadDouble(data_, parent_width_);
485 } else
486 switch (type_) {
487 case FBT_INDIRECT_FLOAT: return ReadDouble(Indirect(), byte_width_);
488 case FBT_INT:
489 return static_cast<double>(ReadInt64(data_, parent_width_));
490 case FBT_UINT:
491 return static_cast<double>(ReadUInt64(data_, parent_width_));
492 case FBT_INDIRECT_INT:
493 return static_cast<double>(ReadInt64(Indirect(), byte_width_));
495 return static_cast<double>(ReadUInt64(Indirect(), byte_width_));
496 case FBT_NULL: return 0.0;
497 case FBT_STRING: {
498 double d;
500 return d;
501 }
502 case FBT_VECTOR: return static_cast<double>(AsVector().size());
503 case FBT_BOOL:
504 return static_cast<double>(ReadUInt64(data_, parent_width_));
505 default:
506 // Convert strings and other things to float.
507 return 0;
508 }
509 }
size_t size() const
bool StringToNumber(const char *s, T *val)
Definition util.h:327
double ReadDouble(const uint8_t *data, uint8_t byte_width)
int64_t ReadInt64(const uint8_t *data, uint8_t byte_width)

References AsString(), AsVector(), flexbuffers::FBT_BOOL, flexbuffers::FBT_FLOAT, flexbuffers::FBT_INDIRECT_FLOAT, flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_NULL, flexbuffers::FBT_STRING, flexbuffers::FBT_UINT, flexbuffers::FBT_VECTOR, flexbuffers::ReadDouble(), flexbuffers::ReadInt64(), flexbuffers::ReadUInt64(), flexbuffers::Sized::size(), and flatbuffers::StringToNumber().

Referenced by As(), AsFloat(), and ToString().

◆ AsFixedTypedVector()

FixedTypedVector flexbuffers::Reference::AsFixedTypedVector ( ) const
inline

Definition at line 653 of file flexbuffers.h.

653 {
654 if (IsFixedTypedVector()) {
655 uint8_t len = 0;
656 auto vtype = ToFixedTypedVectorElementType(type_, &len);
657 return FixedTypedVector(Indirect(), byte_width_, vtype, len);
658 } else {
660 }
661 }
static FixedTypedVector EmptyFixedTypedVector()
bool IsFixedTypedVector() const
Type ToFixedTypedVectorElementType(Type t, uint8_t *len)

References flexbuffers::FixedTypedVector::EmptyFixedTypedVector(), IsFixedTypedVector(), and flexbuffers::ToFixedTypedVectorElementType().

Referenced by As(), and ToString().

◆ AsFloat()

float flexbuffers::Reference::AsFloat ( ) const
inline

Definition at line 511 of file flexbuffers.h.

511{ return static_cast<float>(AsDouble()); }

References AsDouble().

Referenced by As().

◆ AsInt16()

int16_t flexbuffers::Reference::AsInt16 ( ) const
inline

Definition at line 451 of file flexbuffers.h.

451{ return static_cast<int16_t>(AsInt64()); }

References AsInt64().

Referenced by As().

◆ AsInt32()

int32_t flexbuffers::Reference::AsInt32 ( ) const
inline

Definition at line 450 of file flexbuffers.h.

450{ return static_cast<int32_t>(AsInt64()); }

References AsInt64().

Referenced by As().

◆ AsInt64()

int64_t flexbuffers::Reference::AsInt64 ( ) const
inline

Definition at line 425 of file flexbuffers.h.

425 {
426 if (type_ == FBT_INT) {
427 // A fast path for the common case.
428 return ReadInt64(data_, parent_width_);
429 } else
430 switch (type_) {
431 case FBT_INDIRECT_INT: return ReadInt64(Indirect(), byte_width_);
432 case FBT_UINT: return ReadUInt64(data_, parent_width_);
433 case FBT_INDIRECT_UINT: return ReadUInt64(Indirect(), byte_width_);
434 case FBT_FLOAT:
435 return static_cast<int64_t>(ReadDouble(data_, parent_width_));
437 return static_cast<int64_t>(ReadDouble(Indirect(), byte_width_));
438 case FBT_NULL: return 0;
439 case FBT_STRING: return flatbuffers::StringToInt(AsString().c_str());
440 case FBT_VECTOR: return static_cast<int64_t>(AsVector().size());
441 case FBT_BOOL: return ReadInt64(data_, parent_width_);
442 default:
443 // Convert other things to int.
444 return 0;
445 }
446 }
int64_t StringToInt(const char *s, int base=10)
Definition util.h:388

References AsString(), AsVector(), flexbuffers::FBT_BOOL, flexbuffers::FBT_FLOAT, flexbuffers::FBT_INDIRECT_FLOAT, flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_NULL, flexbuffers::FBT_STRING, flexbuffers::FBT_UINT, flexbuffers::FBT_VECTOR, flexbuffers::ReadDouble(), flexbuffers::ReadInt64(), flexbuffers::ReadUInt64(), flexbuffers::Sized::size(), and flatbuffers::StringToInt().

Referenced by As(), AsInt16(), AsInt32(), AsInt8(), and ToString().

◆ AsInt8()

int8_t flexbuffers::Reference::AsInt8 ( ) const
inline

Definition at line 452 of file flexbuffers.h.

452{ return static_cast<int8_t>(AsInt64()); }

References AsInt64().

Referenced by As().

◆ AsKey()

const char * flexbuffers::Reference::AsKey ( ) const
inline

Definition at line 513 of file flexbuffers.h.

513 {
514 if (type_ == FBT_KEY || type_ == FBT_STRING) {
515 return reinterpret_cast<const char *>(Indirect());
516 } else {
517 return "";
518 }
519 }

References flexbuffers::FBT_KEY, and flexbuffers::FBT_STRING.

Referenced by ToString().

◆ AsMap()

Map flexbuffers::Reference::AsMap ( ) const
inline

Definition at line 663 of file flexbuffers.h.

663 {
664 if (type_ == FBT_MAP) {
665 return Map(Indirect(), byte_width_);
666 } else {
667 return Map::EmptyMap();
668 }
669 }
static Map EmptyMap()

References flexbuffers::Map::EmptyMap(), and flexbuffers::FBT_MAP.

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

◆ AsString()

String flexbuffers::Reference::AsString ( ) const
inline

Definition at line 523 of file flexbuffers.h.

523 {
524 if (type_ == FBT_STRING) {
525 return String(Indirect(), byte_width_);
526 } else if (type_ == FBT_KEY) {
527 auto key = Indirect();
528 return String(key, byte_width_,
529 strlen(reinterpret_cast<const char *>(key)));
530 } else {
531 return String::EmptyString();
532 }
533 }
static String EmptyString()

References flexbuffers::String::EmptyString(), flexbuffers::FBT_KEY, and flexbuffers::FBT_STRING.

Referenced by As(), AsDouble(), AsInt64(), AsUInt64(), and MutateString().

◆ AsTypedVector()

TypedVector flexbuffers::Reference::AsTypedVector ( ) const
inline

Definition at line 634 of file flexbuffers.h.

634 {
635 if (IsTypedVector()) {
636 auto tv =
637 TypedVector(Indirect(), byte_width_, ToTypedVectorElementType(type_));
638 if (tv.type_ == FBT_STRING) {
639 // These can't be accessed as strings, since we don't know the bit-width
640 // of the size field, see the declaration of
641 // FBT_VECTOR_STRING_DEPRECATED above for details.
642 // We change the type here to be keys, which are a subtype of strings,
643 // and will ignore the size field. This will truncate strings with
644 // embedded nulls.
645 tv.type_ = FBT_KEY;
646 }
647 return tv;
648 } else {
650 }
651 }
bool IsTypedVector() const
static TypedVector EmptyTypedVector()
Type ToTypedVectorElementType(Type t)

References flexbuffers::TypedVector::EmptyTypedVector(), flexbuffers::FBT_KEY, flexbuffers::FBT_STRING, IsTypedVector(), and flexbuffers::ToTypedVectorElementType().

Referenced by As(), and ToString().

◆ AsUInt16()

uint16_t flexbuffers::Reference::AsUInt16 ( ) const
inline

Definition at line 478 of file flexbuffers.h.

478{ return static_cast<uint16_t>(AsUInt64()); }

References AsUInt64().

Referenced by As().

◆ AsUInt32()

uint32_t flexbuffers::Reference::AsUInt32 ( ) const
inline

Definition at line 477 of file flexbuffers.h.

477{ return static_cast<uint32_t>(AsUInt64()); }

References AsUInt64().

Referenced by As().

◆ AsUInt64()

uint64_t flexbuffers::Reference::AsUInt64 ( ) const
inline

Definition at line 454 of file flexbuffers.h.

454 {
455 if (type_ == FBT_UINT) {
456 // A fast path for the common case.
457 return ReadUInt64(data_, parent_width_);
458 } else
459 switch (type_) {
460 case FBT_INDIRECT_UINT: return ReadUInt64(Indirect(), byte_width_);
461 case FBT_INT: return ReadInt64(data_, parent_width_);
462 case FBT_INDIRECT_INT: return ReadInt64(Indirect(), byte_width_);
463 case FBT_FLOAT:
464 return static_cast<uint64_t>(ReadDouble(data_, parent_width_));
466 return static_cast<uint64_t>(ReadDouble(Indirect(), byte_width_));
467 case FBT_NULL: return 0;
468 case FBT_STRING: return flatbuffers::StringToUInt(AsString().c_str());
469 case FBT_VECTOR: return static_cast<uint64_t>(AsVector().size());
470 case FBT_BOOL: return ReadUInt64(data_, parent_width_);
471 default:
472 // Convert other things to uint.
473 return 0;
474 }
475 }
uint64_t StringToUInt(const char *s, int base=10)
Definition util.h:393

References AsString(), AsVector(), flexbuffers::FBT_BOOL, flexbuffers::FBT_FLOAT, flexbuffers::FBT_INDIRECT_FLOAT, flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_NULL, flexbuffers::FBT_STRING, flexbuffers::FBT_UINT, flexbuffers::FBT_VECTOR, flexbuffers::ReadDouble(), flexbuffers::ReadInt64(), flexbuffers::ReadUInt64(), flexbuffers::Sized::size(), and flatbuffers::StringToUInt().

Referenced by As(), AsBool(), AsUInt16(), AsUInt32(), AsUInt8(), and ToString().

◆ AsUInt8()

uint8_t flexbuffers::Reference::AsUInt8 ( ) const
inline

Definition at line 479 of file flexbuffers.h.

479{ return static_cast<uint8_t>(AsUInt64()); }

References AsUInt64().

Referenced by As().

◆ AsVector()

Vector flexbuffers::Reference::AsVector ( ) const
inline

Definition at line 626 of file flexbuffers.h.

626 {
627 if (type_ == FBT_VECTOR || type_ == FBT_MAP) {
628 return Vector(Indirect(), byte_width_);
629 } else {
630 return Vector::EmptyVector();
631 }
632 }

References flexbuffers::FBT_MAP, and flexbuffers::FBT_VECTOR.

Referenced by As(), AsDouble(), AsInt64(), AsUInt64(), and ToString().

◆ GetType()

Type flexbuffers::Reference::GetType ( ) const
inline

Definition at line 391 of file flexbuffers.h.

391{ return type_; }

◆ IsAnyVector()

bool flexbuffers::Reference::IsAnyVector ( ) const
inline

Definition at line 412 of file flexbuffers.h.

412 {
413 return (IsTypedVector() || IsFixedTypedVector() || IsVector());
414 }

References IsFixedTypedVector(), IsTypedVector(), and IsVector().

◆ IsBlob()

bool flexbuffers::Reference::IsBlob ( ) const
inline

Definition at line 416 of file flexbuffers.h.

416{ return type_ == FBT_BLOB; }

References flexbuffers::FBT_BLOB.

Referenced by ToString().

◆ IsBool()

bool flexbuffers::Reference::IsBool ( ) const
inline

Definition at line 394 of file flexbuffers.h.

394{ return type_ == FBT_BOOL; }

References flexbuffers::FBT_BOOL.

Referenced by ToString().

◆ IsFixedTypedVector()

bool flexbuffers::Reference::IsFixedTypedVector ( ) const
inline

Definition at line 409 of file flexbuffers.h.

409 {
411 }
bool IsFixedTypedVector(Type t)

References flexbuffers::IsFixedTypedVector().

Referenced by AsFixedTypedVector(), IsAnyVector(), and ToString().

◆ IsFloat()

bool flexbuffers::Reference::IsFloat ( ) const
inline

Definition at line 400 of file flexbuffers.h.

400 {
401 return type_ == FBT_FLOAT || type_ == FBT_INDIRECT_FLOAT;
402 }

References flexbuffers::FBT_FLOAT, and flexbuffers::FBT_INDIRECT_FLOAT.

Referenced by IsNumeric(), and ToString().

◆ IsInt()

bool flexbuffers::Reference::IsInt ( ) const
inline

Definition at line 395 of file flexbuffers.h.

395{ return type_ == FBT_INT || type_ == FBT_INDIRECT_INT; }

References flexbuffers::FBT_INDIRECT_INT, and flexbuffers::FBT_INT.

Referenced by IsIntOrUint(), and ToString().

◆ IsIntOrUint()

bool flexbuffers::Reference::IsIntOrUint ( ) const
inline

Definition at line 399 of file flexbuffers.h.

399{ return IsInt() || IsUInt(); }

References IsInt(), and IsUInt().

Referenced by IsNumeric().

◆ IsKey()

bool flexbuffers::Reference::IsKey ( ) const
inline

Definition at line 405 of file flexbuffers.h.

405{ return type_ == FBT_KEY; }

References flexbuffers::FBT_KEY.

Referenced by ToString().

◆ IsMap()

bool flexbuffers::Reference::IsMap ( ) const
inline

Definition at line 415 of file flexbuffers.h.

415{ return type_ == FBT_MAP; }

References flexbuffers::FBT_MAP.

Referenced by ToString().

◆ IsNull()

bool flexbuffers::Reference::IsNull ( ) const
inline

Definition at line 393 of file flexbuffers.h.

393{ return type_ == FBT_NULL; }

References flexbuffers::FBT_NULL.

Referenced by ToString().

◆ IsNumeric()

bool flexbuffers::Reference::IsNumeric ( ) const
inline

Definition at line 403 of file flexbuffers.h.

403{ return IsIntOrUint() || IsFloat(); }
bool IsIntOrUint() const

References IsFloat(), and IsIntOrUint().

◆ IsString()

bool flexbuffers::Reference::IsString ( ) const
inline

Definition at line 404 of file flexbuffers.h.

404{ return type_ == FBT_STRING; }

References flexbuffers::FBT_STRING.

◆ IsTypedVector()

bool flexbuffers::Reference::IsTypedVector ( ) const
inline

Definition at line 408 of file flexbuffers.h.

408{ return flexbuffers::IsTypedVector(type_); }
bool IsTypedVector(Type t)
Definition flexbuffers.h:95

References flexbuffers::IsTypedVector().

Referenced by AsTypedVector(), IsAnyVector(), and ToString().

◆ IsUInt()

bool flexbuffers::Reference::IsUInt ( ) const
inline

Definition at line 396 of file flexbuffers.h.

396 {
397 return type_ == FBT_UINT || type_ == FBT_INDIRECT_UINT;
398 }

References flexbuffers::FBT_INDIRECT_UINT, and flexbuffers::FBT_UINT.

Referenced by IsIntOrUint(), and ToString().

◆ IsUntypedVector()

bool flexbuffers::Reference::IsUntypedVector ( ) const
inline

Definition at line 407 of file flexbuffers.h.

407{ return type_ == FBT_VECTOR; }

References flexbuffers::FBT_VECTOR.

◆ IsVector()

bool flexbuffers::Reference::IsVector ( ) const
inline

Definition at line 406 of file flexbuffers.h.

406{ return type_ == FBT_VECTOR || type_ == FBT_MAP; }

References flexbuffers::FBT_MAP, and flexbuffers::FBT_VECTOR.

Referenced by IsAnyVector(), and ToString().

◆ MutateBool()

bool flexbuffers::Reference::MutateBool ( bool  b)
inline

Definition at line 695 of file flexbuffers.h.

695 {
696 return type_ == FBT_BOOL && Mutate(data_, b, parent_width_, BIT_WIDTH_8);
697 }

References flexbuffers::BIT_WIDTH_8, and flexbuffers::FBT_BOOL.

◆ MutateFloat() [1/2]

bool flexbuffers::Reference::MutateFloat ( double  d)
inline

Definition at line 725 of file flexbuffers.h.

725 {
726 if (type_ == FBT_FLOAT) {
727 return MutateF(data_, d, parent_width_, WidthF(d));
728 } else if (type_ == FBT_INDIRECT_FLOAT) {
729 return MutateF(Indirect(), d, byte_width_, WidthF(d));
730 } else {
731 return false;
732 }
733 }
BitWidth WidthF(double f)

References flexbuffers::FBT_FLOAT, flexbuffers::FBT_INDIRECT_FLOAT, and flexbuffers::WidthF().

◆ MutateFloat() [2/2]

bool flexbuffers::Reference::MutateFloat ( float  f)
inline

Definition at line 715 of file flexbuffers.h.

715 {
716 if (type_ == FBT_FLOAT) {
717 return MutateF(data_, f, parent_width_, BIT_WIDTH_32);
718 } else if (type_ == FBT_INDIRECT_FLOAT) {
719 return MutateF(Indirect(), f, byte_width_, BIT_WIDTH_32);
720 } else {
721 return false;
722 }
723 }

References flexbuffers::BIT_WIDTH_32, flexbuffers::FBT_FLOAT, and flexbuffers::FBT_INDIRECT_FLOAT.

◆ MutateInt()

bool flexbuffers::Reference::MutateInt ( int64_t  i)
inline

Definition at line 679 of file flexbuffers.h.

679 {
680 if (type_ == FBT_INT) {
681 return Mutate(data_, i, parent_width_, WidthI(i));
682 } else if (type_ == FBT_INDIRECT_INT) {
683 return Mutate(Indirect(), i, byte_width_, WidthI(i));
684 } else if (type_ == FBT_UINT) {
685 auto u = static_cast<uint64_t>(i);
686 return Mutate(data_, u, parent_width_, WidthU(u));
687 } else if (type_ == FBT_INDIRECT_UINT) {
688 auto u = static_cast<uint64_t>(i);
689 return Mutate(Indirect(), u, byte_width_, WidthU(u));
690 } else {
691 return false;
692 }
693 }
BitWidth WidthI(int64_t i)
BitWidth WidthU(uint64_t u)

References flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_UINT, flexbuffers::WidthI(), and flexbuffers::WidthU().

◆ MutateString() [1/3]

bool flexbuffers::Reference::MutateString ( const char *  str)
inline

Definition at line 744 of file flexbuffers.h.

744{ return MutateString(str, strlen(str)); }
bool MutateString(const char *str, size_t len)

References MutateString().

Referenced by MutateString().

◆ MutateString() [2/3]

bool flexbuffers::Reference::MutateString ( const char *  str,
size_t  len 
)
inline

Definition at line 735 of file flexbuffers.h.

735 {
736 auto s = AsString();
737 if (s.IsTheEmptyString()) return false;
738 // This is very strict, could allow shorter strings, but that creates
739 // garbage.
740 if (s.length() != len) return false;
741 memcpy(const_cast<char *>(s.c_str()), str, len);
742 return true;
743 }

References AsString().

Referenced by MutateString().

◆ MutateString() [3/3]

bool flexbuffers::Reference::MutateString ( const std::string &  str)
inline

Definition at line 745 of file flexbuffers.h.

745 {
746 return MutateString(str.data(), str.length());
747 }
str
Definition infer.py:18

References MutateString().

◆ MutateUInt()

bool flexbuffers::Reference::MutateUInt ( uint64_t  u)
inline

Definition at line 699 of file flexbuffers.h.

699 {
700 if (type_ == FBT_UINT) {
701 return Mutate(data_, u, parent_width_, WidthU(u));
702 } else if (type_ == FBT_INDIRECT_UINT) {
703 return Mutate(Indirect(), u, byte_width_, WidthU(u));
704 } else if (type_ == FBT_INT) {
705 auto i = static_cast<int64_t>(u);
706 return Mutate(data_, i, parent_width_, WidthI(i));
707 } else if (type_ == FBT_INDIRECT_INT) {
708 auto i = static_cast<int64_t>(u);
709 return Mutate(Indirect(), i, byte_width_, WidthI(i));
710 } else {
711 return false;
712 }
713 }

References flexbuffers::FBT_INDIRECT_INT, flexbuffers::FBT_INDIRECT_UINT, flexbuffers::FBT_INT, flexbuffers::FBT_UINT, flexbuffers::WidthI(), and flexbuffers::WidthU().

◆ ToString() [1/2]

std::string flexbuffers::Reference::ToString ( ) const
inline

Definition at line 536 of file flexbuffers.h.

536 {
537 std::string s;
538 ToString(false, false, s);
539 return s;
540 }
std::string ToString() const

References ToString().

Referenced by ToString().

◆ ToString() [2/2]

void flexbuffers::Reference::ToString ( bool  strings_quoted,
bool  keys_quoted,
std::string &  s 
) const
inline

Definition at line 546 of file flexbuffers.h.

546 {
547 if (type_ == FBT_STRING) {
548 String str(Indirect(), byte_width_);
549 if (strings_quoted) {
550 flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, false);
551 } else {
552 s.append(str.c_str(), str.length());
553 }
554 } else if (IsKey()) {
555 auto str = AsKey();
556 if (keys_quoted) {
557 flatbuffers::EscapeString(str, strlen(str), &s, true, false);
558 } else {
559 s += str;
560 }
561 } else if (IsInt()) {
563 } else if (IsUInt()) {
565 } else if (IsFloat()) {
567 } else if (IsNull()) {
568 s += "null";
569 } else if (IsBool()) {
570 s += AsBool() ? "true" : "false";
571 } else if (IsMap()) {
572 s += "{ ";
573 auto m = AsMap();
574 auto keys = m.Keys();
575 auto vals = m.Values();
576 for (size_t i = 0; i < keys.size(); i++) {
577 bool kq = keys_quoted;
578 if (!kq) {
579 // FlexBuffers keys may contain arbitrary characters, only allow
580 // unquoted if it looks like an "identifier":
581 const char *p = keys[i].AsKey();
582 if (!flatbuffers::is_alpha(*p) && *p != '_') {
583 kq = true;
584 } else {
585 while (*++p) {
586 if (!flatbuffers::is_alnum(*p) && *p != '_') {
587 kq = true;
588 break;
589 }
590 }
591 }
592 }
593 keys[i].ToString(true, kq, s);
594 s += ": ";
595 vals[i].ToString(true, keys_quoted, s);
596 if (i < keys.size() - 1) s += ", ";
597 }
598 s += " }";
599 } else if (IsVector()) {
600 AppendToString<Vector>(s, AsVector(), keys_quoted);
601 } else if (IsTypedVector()) {
602 AppendToString<TypedVector>(s, AsTypedVector(), keys_quoted);
603 } else if (IsFixedTypedVector()) {
604 AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted);
605 } else if (IsBlob()) {
606 auto blob = AsBlob();
607 flatbuffers::EscapeString(reinterpret_cast<const char *>(blob.data()),
608 blob.size(), &s, true, false);
609 } else {
610 s += "(?)";
611 }
612 }
const char * AsKey() const
std::string NumToString(T t)
Definition util.h:128
bool is_alpha(char c)
Definition util.h:52
bool EscapeString(const char *s, size_t length, std::string *_text, bool allow_non_utf8, bool natural_utf8)
Definition util.h:594
bool is_alnum(char c)
Definition util.h:80
Configuration p

References AsBlob(), AsBool(), AsDouble(), AsFixedTypedVector(), AsInt64(), AsKey(), AsMap(), AsTypedVector(), AsUInt64(), AsVector(), flatbuffers::EscapeString(), flexbuffers::FBT_STRING, flatbuffers::is_alnum(), flatbuffers::is_alpha(), IsBlob(), IsBool(), IsFixedTypedVector(), IsFloat(), IsInt(), IsKey(), IsMap(), IsNull(), IsTypedVector(), IsUInt(), IsVector(), m, flatbuffers::NumToString(), and p.

Friends And Related Symbol Documentation

◆ Verifier

friend class Verifier
friend

Definition at line 777 of file flexbuffers.h.


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