protocでProtocol Buffersエンコードする
protoc —encode=MESSAGE_TYPE コマンドでテキストフォーマットからProtocol Buffersメッセージにエンコードできる。
以下のプロトコル定義があるとき、
syntax = "proto3";
package api.v1;
message Users { repeated User users = 1;}message User { bytes name = 1; int age = 2;}フィールド名と値を : で区切ってテキストにする。ネストしている場合は {} で囲む。
users: { name: "user1" age: 10}これを、以下のコマンドで変換すればいい。
protoc --encode=api.v1.Users api.proto <msg.txt—decode_raw すると実際の内容を推測できる。
protoc --decode_raw <msg.raw