docs/versions/6.3.0/rules/lib/ProtoModule.mdx
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: <pre class=language-python>struct(field=123).to_proto() # field: 123struct(field=True).to_proto()
struct(field=[1, 2, 3]).to_proto()
struct(field='text').to_proto()
struct(field=struct(inner_field='text')).to_proto()
struct(field=[struct(inner_field=1), struct(inner_field=2)]).to_proto()
struct(field=struct(inner_field=struct(inner_inner_field='text'))).to_proto()
struct(foo={4: 3, 2: 1}).to_proto()
<!-- 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
</td>
</tr>
</tbody>
</table>