| <html devsite> | |
| <head> | |
| <meta name="project_path" value="/_project.yaml"> | |
| <meta name="book_path" value="/versions/6.4.0/_book.yaml"> | |
| </head> | |
| <body> | |
| <h1 class="page-title" id="modules.ProtoModule">ProtoModule</h1> | |
| <!-- {% raw %} --> | |
| A module for protocol message processing. | |
| <h2>Members</h2> | |
| <ul> | |
| <li> | |
| <a href="#encode_text">encode_text</a> | |
| </li> | |
| </ul> | |
| <h2 id="encode_text">encode_text</h2> | |
| <p><pre class="rule-signature"><a class="anchor" href="string.html">string</a> ProtoModule.encode_text(x)</pre></p> | |
| Returns the struct argument's encoding as a text-format protocol message. | |
| The data structure must be recursively composed of strings, ints, floats, or bools, or structs, sequences, and dicts of these types. | |
| <p>A struct is converted to a message. Fields are emitted in name order. | |
| <p>A sequence (such as a list or tuple) is converted to a repeated field. | |
| Its elements must not be sequences or dicts. | |
| <p>A dict is converted to a repeated field of messages with fields named 'key' and 'value'. | |
| Entries are emitted in iteration (insertion) order. | |
| The dict's keys must be strings, ints, or bools, and its values must not be sequences or dicts. | |
| Examples:<br><pre class=language-python>struct(field=123).to_proto() | |
| # field: 123 | |
| struct(field=True).to_proto() | |
| # field: true | |
| struct(field=[1, 2, 3]).to_proto() | |
| # field: 1 | |
| # field: 2 | |
| # field: 3 | |
| struct(field='text').to_proto() | |
| # field: "text" | |
| struct(field=struct(inner_field='text')).to_proto() | |
| # field { | |
| # inner_field: "text" | |
| # } | |
| struct(field=[struct(inner_field=1), struct(inner_field=2)]).to_proto() | |
| # field { | |
| # inner_field: 1 | |
| # } | |
| # field { | |
| # inner_field: 2 | |
| # } | |
| struct(field=struct(inner_field=struct(inner_inner_field='text'))).to_proto() | |
| # field { | |
| # inner_field { | |
| # inner_inner_field: "text" | |
| # } | |
| # } | |
| struct(foo={4: 3, 2: 1}).to_proto() | |
| # foo: { | |
| # key: 4 | |
| # value: 3 | |
| # } | |
| # foo: { | |
| # key: 2 | |
| # value: 1 | |
| # } | |
| </pre> | |
| <!-- hide-from-toc is a class used by DevSite for the public Bazel site | |
| (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) --> | |
| <h3 class="hide-from-toc">Parameters</h3> | |
| <table class="table table-bordered table-condensed table-params"> | |
| <colgroup> | |
| <col class="col-param"> | |
| <col class="param-description"> | |
| </colgroup> | |
| <thead> | |
| <tr> | |
| <th>Parameter</th> | |
| <th>Description</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr> | |
| <td id="encode_text.x"> | |
| <code>x</code> | |
| </td> | |
| <td> | |
| required<br/> | |
| </td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| </body> | |
| </html> | |
| <!-- {% endraw %} --> |