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

#include <registry.h>

Public Member Functions

void Register (const char *file_identifier, const char *schema_path)
 
bool FlatBufferToText (const uint8_t *flatbuf, size_t len, std::string *dest)
 
DetachedBuffer TextToFlatBuffer (const char *text, const char *file_identifier)
 
void SetOptions (const IDLOptions &opts)
 
void AddIncludeDirectory (const char *path)
 
const std::string & GetLastError ()
 

Detailed Description

Definition at line 30 of file registry.h.

Member Function Documentation

◆ AddIncludeDirectory()

void flatbuffers::Registry::AddIncludeDirectory ( const char *  path)
inline

Definition at line 92 of file registry.h.

92{ include_paths_.push_back(path); }

◆ FlatBufferToText()

bool flatbuffers::Registry::FlatBufferToText ( const uint8_t *  flatbuf,
size_t  len,
std::string *  dest 
)
inline

Definition at line 44 of file registry.h.

45 {
46 // Get the identifier out of the buffer.
47 // If the buffer is truncated, exit.
48 if (len < sizeof(uoffset_t) + FlatBufferBuilder::kFileIdentifierLength)
49 {
50 lasterror_ = "buffer truncated";
51 return false;
52 }
53 std::string ident(reinterpret_cast<const char *>(flatbuf) + sizeof(uoffset_t),
55 // Load and parse the schema.
56 Parser parser;
57 if (!LoadSchema(ident, &parser))
58 return false;
59 // Now we're ready to generate text.
60 if (!GenerateText(parser, flatbuf, dest))
61 {
62 lasterror_ = "unable to generate text for FlatBuffer binary";
63 return false;
64 }
65 return true;
66 }
static const size_t kFileIdentifierLength
The length of a FlatBuffer file header.
bool GenerateText(const Parser &parser, const void *flatbuffer, std::string *text)
parser
Definition infer.py:17

References flatbuffers::GenerateText(), and flatbuffers::FlatBufferBuilder::kFileIdentifierLength.

◆ GetLastError()

const std::string & flatbuffers::Registry::GetLastError ( )
inline

Definition at line 95 of file registry.h.

95{ return lasterror_; }

◆ Register()

void flatbuffers::Registry::Register ( const char *  file_identifier,
const char *  schema_path 
)
inline

Definition at line 35 of file registry.h.

36 {
37 Schema schema;
38 schema.path_ = schema_path;
39 schemas_[file_identifier] = schema;
40 }

◆ SetOptions()

void flatbuffers::Registry::SetOptions ( const IDLOptions opts)
inline

Definition at line 88 of file registry.h.

88{ opts_ = opts; }

◆ TextToFlatBuffer()

DetachedBuffer flatbuffers::Registry::TextToFlatBuffer ( const char *  text,
const char *  file_identifier 
)
inline

Definition at line 71 of file registry.h.

72 {
73 // Load and parse the schema.
74 Parser parser;
75 if (!LoadSchema(file_identifier, &parser))
76 return DetachedBuffer();
77 // Parse the text.
78 if (!parser.Parse(text))
79 {
80 lasterror_ = parser.error_;
81 return DetachedBuffer();
82 }
83 // We have a valid FlatBuffer. Detach it from the builder and return.
84 return parser.builder_.Release();
85 }

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