我如何用 flatbuffer schema 重写 protobuf scheam?

How can I rewrite the protobuf scheam with flatbuffer schema?

例如,这是protobuf模式代码,我想用flatbuffer模式重写它们?代码是什么样的?

    message Xx {
    required uint32 id = 1;
    optional string name = 2;
    message Yy {
        optional string name = 1;
    }
    repeated Yy y = 3;
}

谢谢兄弟

FlatBuffers内置了.proto翻译,试试flatc --proto myschema.proto,你会得到对应的.fbs文件

但在您的情况下,您有嵌套的消息定义,FlatBuffers 不支持。所以首先改变你的 .proto 这样的 message Yy 被移到 message Xx 之外。还给它一个包名。你会得到:

table Yy {
  name:string;
}

table Xx {
  id:uint (required);
  name:string;
  y:[Yy];
}

编辑:FlatBuffers 现在支持翻译嵌套的 .proto 定义。