如何让 FlatBufferToString 为联合类型生成有效的 JSON?
How to get FlatBufferToString to generate valid JSON for union types?
我的 flatbuffers 架构中有一个联合类型:
union Quux { Foo, Bar, Baz }
table Root {
quux: Quux
}
如果我使用 flatc 转换为 json,它看起来像这样:
{
quux_type: "Bar",
quux: {...}
}
但是如果我使用 flatbuffers/minireflect.h
中的 FlatBufferToString
,那么我会得到这个,这是无效的 JSON。
{
quux_type: Bar,
quux: {...},
}
我这样调用 flatc
flatc --reflect-names --cpp -o include src/quux.fbs
如何让 minireflect 为联合类型生成有效的 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
,看起来您会在枚举值和字段名称周围得到引号。
我的 flatbuffers 架构中有一个联合类型:
union Quux { Foo, Bar, Baz }
table Root {
quux: Quux
}
如果我使用 flatc 转换为 json,它看起来像这样:
{
quux_type: "Bar",
quux: {...}
}
但是如果我使用 flatbuffers/minireflect.h
中的 FlatBufferToString
,那么我会得到这个,这是无效的 JSON。
{
quux_type: Bar,
quux: {...},
}
我这样调用 flatc
flatc --reflect-names --cpp -o include src/quux.fbs
如何让 minireflect 为联合类型生成有效的 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
,看起来您会在枚举值和字段名称周围得到引号。