3

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.

hash-X
  • 99
  • 1
  • 2
  • 9

1 Answers1

11

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.

Aardappel
  • 5,559
  • 1
  • 19
  • 22
  • Thank you. But I recommended maybe FlatBuffers support the nested message. Because existing message in ProtoBuffers have many nest mode. – hash-X Sep 25 '15 at 02:53
  • It is something with the code when I compiler the source. The compiler give the error about only non-scalar fields in tables may be 'required' And I think it is a Bug ??? Do you ? – hash-X Sep 25 '15 at 05:35
  • 1
    Yes, that's a bug, please file an issue on github. For now, just delete the `(required)`. – Aardappel Sep 25 '15 at 16:10
  • OK, thank you Aardappel , I will have an issue on github right now. – hash-X Sep 27 '15 at 03:46