17#ifndef FLATBUFFERS_REGISTRY_H_
18#define FLATBUFFERS_REGISTRY_H_
33 void Register(
const char *file_identifier,
const char *schema_path) {
35 schema.path_ = schema_path;
36 schemas_[file_identifier] = schema;
44 if (len <
sizeof(uoffset_t) + kFileIdentifierLength) {
45 lasterror_ =
"buffer truncated";
49 reinterpret_cast<const char *
>(flatbuf) +
sizeof(uoffset_t),
50 kFileIdentifierLength);
53 if (!LoadSchema(ident, &parser))
return false;
55 auto err =
GenText(parser, flatbuf, dest);
58 "unable to generate text for FlatBuffer binary: " + std::string(err);
68 const char *file_identifier) {
71 if (!LoadSchema(file_identifier, &parser))
return DetachedBuffer();
73 if (!parser.Parse(text)) {
74 lasterror_ = parser.error_;
78 return parser.builder_.Release();
92 bool LoadSchema(
const std::string &ident,
Parser *parser) {
94 auto it = schemas_.find(ident);
95 if (it == schemas_.end()) {
97 lasterror_ =
"identifier for this buffer not in the registry";
100 auto &schema = it->second;
102 std::string schematext;
103 if (!
LoadFile(schema.path_.c_str(),
false, &schematext)) {
104 lasterror_ =
"could not load schema: " + schema.path_;
109 if (!
parser->Parse(schematext.c_str(), include_paths_.data(),
110 schema.path_.c_str())) {
111 lasterror_ =
parser->error_;
122 std::string lasterror_;
124 std::vector<const char *> include_paths_;
125 std::map<std::string, Schema> schemas_;
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)
const char * GenText(const Parser &parser, const void *flatbuffer, std::string *text)
bool LoadFile(const char *name, bool binary, std::string *buf)