プロトコル

問題を報告する ソースを表示

プロトコル メッセージ処理用のモジュール。

メンバー

encode_text

string proto.encode_text(x)

構造体引数のエンコードをテキスト形式のプロトコル メッセージとして返します。 データ構造体は、文字列、整数、浮動小数点数、ブール値、またはこれらの型の構造体、シーケンス、辞書で再帰的に構成されている必要があります。

構造体はメッセージに変換されます。フィールドは名前順に出力されます。値が None の各構造体フィールドは無視されます。

シーケンス(リストやタプルなど)は繰り返しフィールドに変換されます。要素をシーケンスまたは辞書にすることはできません。

dict 型は、「key」と「value」という名前のフィールドを持つメッセージの繰り返しフィールドに変換されます。エントリは反復(挿入)順に出力されます。dict のキーは文字列または int にする必要があります。値をシーケンスや辞書にすることはできません。例:

proto.encode_text(struct(field=123))
# field: 123

proto.encode_text(struct(field=True))
# field: true

proto.encode_text(struct(field=[1, 2, 3]))
# field: 1
# field: 2
# field: 3

proto.encode_text(struct(field='text', ignored_field=None))
# field: "text"

proto.encode_text(struct(field=struct(inner_field='text', ignored_field=None)))
# field {
#   inner_field: "text"
# }

proto.encode_text(struct(field=[struct(inner_field=1), struct(inner_field=2)]))
# field {
#   inner_field: 1
# }
# field {
#   inner_field: 2
# }

proto.encode_text(struct(field=struct(inner_field=struct(inner_inner_field='text'))))
# field {
#    inner_field {
#     inner_inner_field: "text"
#   }
# }

proto.encode_text(struct(foo={4: 3, 2: 1}))
# foo: {
#   key: 4
#   value: 3
# }
# foo: {
#   key: 2
#   value: 1
# }

パラメータ

パラメータ 説明
x 必須