Search code examples
protocol-buffersflatbuffers

How can I rewrite the protobuf scheam with flatbuffer schema?


For example , Here is the protobuf schema code, I want to rewrite them by flatbuffer schema? what is the code like ?

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

thank you my bro.


Solution

  • FlatBuffers has .proto translation built-in, try flatc --proto myschema.proto, and you will get the corresponding .fbs file.

    In your case though, you have nested message definitions, which FlatBuffers doesn't support. So first change your .proto such message Yy is moved outside of message Xx. Also give it a package name. You'll get:

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

    EDIT: FlatBuffers now supports translating even nested .proto definitions.