Json : Add --size-prefixed option to flatc (#4645)

to be able to convert to json size prefixed buffers.
This commit is contained in:
desqaz
2018-03-09 17:21:28 +01:00
committed by Wouter van Oortmerssen
parent cc158e7009
commit e78825e7a0
5 changed files with 28 additions and 11 deletions

View File

@@ -1664,13 +1664,14 @@ const T *GetTemporaryPointer(FlatBufferBuilder &fbb, Offset<T> offset) {
/// This function is UNDEFINED for FlatBuffers whose schema does not include
/// a file_identifier (likely points at padding or the start of a the root
/// vtable).
inline const char *GetBufferIdentifier(const void *buf) {
return reinterpret_cast<const char *>(buf) + sizeof(uoffset_t);
inline const char *GetBufferIdentifier(const void *buf, bool size_prefixed = false) {
return reinterpret_cast<const char *>(buf) +
((size_prefixed) ? 2 * sizeof(uoffset_t) : sizeof(uoffset_t));
}
// Helper to see if the identifier in a buffer has the expected value.
inline bool BufferHasIdentifier(const void *buf, const char *identifier) {
return strncmp(GetBufferIdentifier(buf), identifier,
inline bool BufferHasIdentifier(const void *buf, const char *identifier, bool size_prefixed = false) {
return strncmp(GetBufferIdentifier(buf, size_prefixed), identifier,
FlatBufferBuilder::kFileIdentifierLength) == 0;
}

View File

@@ -387,6 +387,7 @@ struct IDLOptions {
std::string go_namespace;
bool reexport_ts_modules;
bool protobuf_ascii_alike;
bool size_prefixed;
// Possible options for the more general generator below.
enum Language {
@@ -442,6 +443,7 @@ struct IDLOptions {
skip_flatbuffers_import(false),
reexport_ts_modules(true),
protobuf_ascii_alike(false),
size_prefixed(false),
lang(IDLOptions::kJava),
mini_reflect(IDLOptions::kNone),
lang_to_generate(0) {}