プロトコル

問題を報告 ソースを表示 ナイトリー · 7.3 · 7.2 · 7.1 · 7.0 · 6.5

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

メンバー

encode_text

string proto.encode_text(x)

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

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

シーケンス(リストやタプルなど)は繰り返しフィールドに変換されます。 その要素はシーケンスや辞書であってはなりません。

辞書は「key」という名前のフィールドを持つメッセージの繰り返しフィールドに変換されます「value」を指定します。 エントリは反復(挿入)順に送られます。 辞書のキーは文字列または整数でなければならず、その値をシーケンスまたは辞書にすることはできません。 例:

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 必須