18#ifndef FLATBUFFERS_REGISTRY_H_
19#define FLATBUFFERS_REGISTRY_H_
35 void Register(
const char *file_identifier,
const char *schema_path)
38 schema.path_ = schema_path;
39 schemas_[file_identifier] = schema;
50 lasterror_ =
"buffer truncated";
53 std::string ident(
reinterpret_cast<const char *
>(flatbuf) +
sizeof(uoffset_t),
57 if (!LoadSchema(ident, &parser))
62 lasterror_ =
"unable to generate text for FlatBuffer binary";
75 if (!LoadSchema(file_identifier, &parser))
78 if (!parser.Parse(text))
80 lasterror_ = parser.error_;
84 return parser.builder_.Release();
98 bool LoadSchema(
const std::string &ident,
Parser *parser)
101 auto it = schemas_.find(ident);
102 if (it == schemas_.end())
105 lasterror_ =
"identifier for this buffer not in the registry";
108 auto &schema = it->second;
110 std::string schematext;
111 if (!
LoadFile(schema.path_.c_str(),
false, &schematext))
113 lasterror_ =
"could not load schema: " + schema.path_;
118 if (!
parser->Parse(schematext.c_str(),
vector_data(include_paths_), schema.path_.c_str()))
120 lasterror_ =
parser->error_;
132 std::string lasterror_;
134 std::vector<const char *> include_paths_;
135 std::map<std::string, Schema> schemas_;
static const size_t kFileIdentifierLength
The length of a FlatBuffer file header.
DetachedBuffer TextToFlatBuffer(const char *text, const char *file_identifier)
void Register(const char *file_identifier, const char *schema_path)
void AddIncludeDirectory(const char *path)
bool FlatBufferToText(const uint8_t *flatbuf, size_t len, std::string *dest)
const std::string & GetLastError()
void SetOptions(const IDLOptions &opts)
bool GenerateText(const Parser &parser, const void *flatbuffer, std::string *text)
T * vector_data(std::vector< T > &vector)
bool LoadFile(const char *name, bool binary, std::string *buf)