2

チュートリアルをいろいろ見たのですが、プロトコルバッファの使い方がわかりません

なぜ「メッセージ ユーザー」なのですか? なぜ「クラスユーザー」ではないのですか?また、Eclipse はどのようにしてそのようなメッセージを作成したのでしょうか? なぜ name = 2 なのですか?名前=「マックス」ではない

ption java_outer_classname="ProtoUser";

message User {

   required int32  id = 1;  // DB record ID
   required string name = 2;
   required string firstname = 3;
   required string lastname = 4;
   required string ssn= 5; 



   // Embedded Address message spec

    message Address {
      required int32 id = 1;
      required string country = 2 [default = "US"];; 
      optional string state = 3;
      optional string city = 4;
      optional string street = 5;
      optional string zip = 6;



      enum Type {
         HOME = 0;

         WORK = 1; 

       }

       optional Type addrType = 7 [default = HOME]; 

 }
   repeated Address addr = 16;
}
4

2 に答える 2

4

なぜ「メッセージ ユーザー」なのですか? なぜ「クラスユーザー」ではないのですか?

classGoogle Protocol Buffers (GPB)の構文にはありませんが、message代わりに含まれています。 https://developers.google.com/protocol-buffers/docs/style

このファイルは単なるテキスト ファイルです.proto。拡張子が必要です。結局、プロジェクトでインポートして簡単に使用できる実際の Java クラスを生成するユーティリティを実行します。

https://developers.google.com/protocol-buffers/docs/javatutorial

プロトコル バッファのコンパイル

protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/addressbook.proto

required string lastname = 4;

4 は値ではなくフィールド idを表し、ビットストリームの生成に使用されます。

于 2013-03-14T15:12:28.983 に答える