如何获取FlatBufferToString为联合类型生成有效的JSON?

我的flatbuffers模式中有一个联合类型:

union Quux { Foo,Bar,Baz }
table Root {
   quux: Quux
}

如果我使用flatc转换为json,则如下所示:

{
  quux_type: "Bar",quux: {...}
}

但是如果我使用flatBufferToString中的flatbuffers/minireflect.h,那么我得到的是无效的JSON。

{ 
  quux_type: Bar,quux: {...},}

我这样打电话给flatc

flatc --reflect-names --cpp -o include src/quux.fbs

如何获得minireflect来为联合类型生成有效的json输出?

iCMS 回答:如何获取FlatBufferToString为联合类型生成有效的JSON?

从注释中可以看到:https://github.com/google/flatbuffers/blob/4e45f7c9e8da64a9601eeba1231079c3ce0a6dc2/include/flatbuffers/minireflect.h#L282 minireflect字符串转换非常简单,并且仅尝试与JSON相似。

也就是说,如果您将true传递给https://github.com/google/flatbuffers/blob/4e45f7c9e8da64a9601eeba1231079c3ce0a6dc2/include/flatbuffers/minireflect.h#L396-L404中的tostring_visitor,看起来您将得到枚举值和字段名周围的引号。

本文链接:https://www.f2er.com/2157815.html

大家都在问