|
42 | 42 | (<code>Foo</code>) with this name or number, we enforce that the number, type, and full |
43 | 43 | name of the extension match what is forward-declared here.</li></ul><div class="alert alert-warning" role=alert><h4 class=alert-heading>Warning</h4>Avoid using declarations for extension range groups such as <code>extensions 4, 999</code>. |
44 | 44 | It is unclear which extension range the declarations apply to, and it is |
45 | | -currently |
46 | | -unsupported.</div><p>The extension declarations expect two extension fields with different packages:</p><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-proto data-lang=proto><span style=display:flex><span><span style=color:#204a87;font-weight:700>package</span> <span style=color:#000>my</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>package</span><span style=color:#000;font-weight:700>;</span><span style=color:#a40000> |
| 45 | +currently unsupported.</div><p>The extension declarations expect two extension fields with different packages:</p><div class=highlight><pre tabindex=0 style=background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-proto data-lang=proto><span style=display:flex><span><span style=color:#204a87;font-weight:700>package</span> <span style=color:#000>my</span><span style=color:#ce5c00;font-weight:700>.</span><span style=color:#000>package</span><span style=color:#000;font-weight:700>;</span><span style=color:#a40000> |
47 | 46 | </span></span></span><span style=display:flex><span><span style=color:#a40000></span><span style=color:#204a87;font-weight:700>extend</span> <span style=color:#000>Foo</span> <span style=color:#000;font-weight:700>{</span><span style=color:#a40000> |
48 | 47 | </span></span></span><span style=display:flex><span><span style=color:#a40000></span> <span style=color:#204a87;font-weight:700>repeated</span> <span style=color:#000>logs.proto.ValidationAnnotations</span> <span style=color:#000>event_annotations</span> <span style=color:#ce5c00;font-weight:700>=</span> <span style=color:#0000cf;font-weight:700>4</span><span style=color:#000;font-weight:700>;</span><span style=color:#a40000> |
49 | 48 | </span></span></span><span style=display:flex><span><span style=color:#a40000></span><span style=color:#000;font-weight:700>}</span><span style=color:#a40000> |
|
92 | 91 | declarations serve as a registry of all the parent message’s extensions, and |
93 | 92 | protoc will enforce that there are no field number conflicts. When you add a new |
94 | 93 | extension, choose the next available number usually by just incrementing by one |
95 | | -the previously added extension number.</p><p><strong>TIP:</strong> There is a <a href=#message-set>special guidance</a> for |
96 | | -<code>MessageSet</code> which provides a script to help pick |
| 94 | +the previously added extension number.</p><p><strong>TIP:</strong> There is a <a href=#message-set>special guidance</a> |
| 95 | +for <code>MessageSet</code> which provides a script to help pick |
97 | 96 | the next available number.</p><p>Whenever you delete an extension, make sure to mark the field number <code>reserved</code> |
98 | 97 | to eliminate the risk of accidentally reusing |
99 | 98 | it.</p><p>This convention is only a recommendation–the protobuf team does not have the |
|
113 | 112 | proto should be decoded from the wire format. The protobuf wire format is lean |
114 | 113 | and doesn’t provide a good way to detect fields encoded using one definition and |
115 | 114 | decoded using another.</p><p>This ambiguity can manifest in a short time frame, such as a client using one |
116 | | -extension definition and a server using another communicating |
117 | | -.</p><p>This ambiguity can also manifest over a longer time frame, such as storing data |
| 115 | +extension definition and a server using another |
| 116 | +communicating .</p><p>This ambiguity can also manifest over a longer time frame, such as storing data |
118 | 117 | encoded using one extension definition and later retrieving and decoding using |
119 | 118 | the second extension definition. This long-term case can be difficult to |
120 | 119 | diagnose if the first extension definition was deleted after the data was |
|
124 | 123 | debugging at a minimum. It could also cause data leaks or corruption that takes |
125 | 124 | months to clean up.</p><h2 id=usage-tips>Usage Tips</h2><h3 id=never-delete>Never Delete an Extension Declaration</h3><p>Deleting an extension declaration opens the door to accidental reuse in the |
126 | 125 | future. If the extension is no longer processed and the definition is deleted, |
127 | | -the extension declaration can be <a href=#reserved>marked reserved</a>.</p><h3 id=never-reuse-reserved>Never Use a Field Name or Number from the <code>reserved</code> List for a New Extension Declaration</h3><p>Reserved numbers may have been used for fields or other extensions in the past.</p><p>Using the <code>full_name</code> of a reserved field |
128 | | -is not recommended |
129 | | -due |
130 | | -to the possibility of ambiguity when using textproto.</p><h3 id=never-change-type>Never change the type of an existing extension declaration</h3><p>Changing the extension field’s type can result in data corruption.</p><p>If the extension field is of an enum or message type, and that enum or message |
| 126 | +the extension declaration can be <a href=#reserved>marked reserved</a>.</p><h3 id=never-reuse-reserved>Never Use a Field Name or Number from the <code>reserved</code> List for a New Extension Declaration</h3><p>Reserved numbers may have been used for fields or other extensions in the past.</p><p>Using the <code>full_name</code> of a reserved |
| 127 | +field is not |
| 128 | +recommended due to the possibility of ambiguity when using |
| 129 | +textproto.</p><h3 id=never-change-type>Never change the type of an existing extension declaration</h3><p>Changing the extension field’s type can result in data corruption.</p><p>If the extension field is of an enum or message type, and that enum or message |
131 | 130 | type is being renamed, updating the declaration name is required and safe. To |
132 | 131 | avoid breakages, the update of the type, the extension field definition, and |
133 | 132 | extension declaration should all happen in a single |
|
0 commit comments