[flac] Add FlexBuffers option for generating data (#5519)

Alongside --binary and --json, an additional
switch (--flexbuffers) can be passed to convert
data using FlexBuffers
This commit is contained in:
Paulo Pinheiro
2019-09-27 00:06:11 +02:00
committed by Wouter van Oortmerssen
parent a92039687a
commit cfb4ecf6f0
6 changed files with 52 additions and 4 deletions

View File

@@ -349,6 +349,12 @@ void AppendToString(std::string &s, T &&v, bool keys_quoted) {
class Reference {
public:
Reference()
: data_(nullptr),
parent_width_(0),
byte_width_(BIT_WIDTH_8),
type_(FBT_NULL) {}
Reference(const uint8_t *data, uint8_t parent_width, uint8_t byte_width,
Type type)
: data_(data),

View File

@@ -491,6 +491,8 @@ struct ServiceDef : public Definition {
// Container of options that may apply to any of the source/text generators.
struct IDLOptions {
// Use flexbuffers instead for binary and text generation
bool use_flexbuffers;
bool strict_json;
bool skip_js_exports;
bool use_goog_js_export_format;
@@ -573,7 +575,8 @@ struct IDLOptions {
bool set_empty_to_null;
IDLOptions()
: strict_json(false),
: use_flexbuffers(false),
strict_json(false),
skip_js_exports(false),
use_goog_js_export_format(false),
use_ES6_js_export_format(false),
@@ -707,6 +710,7 @@ class Parser : public ParserState {
explicit Parser(const IDLOptions &options = IDLOptions())
: current_namespace_(nullptr),
empty_namespace_(nullptr),
flex_builder_(256, flexbuffers::BUILDER_FLAG_SHARE_ALL),
root_struct_def_(nullptr),
opts(options),
uses_flexbuffers_(false),
@@ -908,6 +912,8 @@ class Parser : public ParserState {
std::string error_; // User readable error_ if Parse() == false
FlatBufferBuilder builder_; // any data contained in the file
flexbuffers::Builder flex_builder_;
flexbuffers::Reference flex_root_;
StructDef *root_struct_def_;
std::string file_identifier_;
std::string file_extension_;