Google Protocol Buffer Support(4.2)
This chapter describes the GPB (Google Protocol Buffers) addition to the Ultra Format Definition Language (UFDL). This addition enables you to compile GPB definitions, and to decode the GPB input data as well as encode data into the GPB format.
Both the proto2 and proto3 versions of the Google protocol buffers language are supported.
Overview
In you manage GPB parsing in UFDL by applying the gpb_block construct. The syntax differs whether you are using proto2 or proto3.
Syntax for proto2
gpb_block {
<GPB message elements>
};
Syntax for proto3
gpb_block {
syntax = "proto3";
<GPB message elements>
};The full description of the GPB language for proto2 and proto3 can be found at: https://developers.google.com/protocol-buffers/docs/proto or https://developers.google.com/protocol-buffers/docs/proto3.
The GPB Field Rules
You specify that message elements are formatted according to one of the following rules:
For proto2 only:
required
optional
For proto2 and proto3:
repeated
The GPB Scalar Value Types
The GPB message elements can be defined with any of the following types:
Type | Notes |
|---|---|
| 8 bytes signed |
| 4 bytes signed |
| Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. |
| Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. |
| Uses variable-length encoding. |
| Uses variable-length encoding. |
| Uses variable-length encoding. Signed int value. This more efficiently encode negative numbers than regular int32s. |
| Uses variable-length encoding. Signed int value. This more efficiently encode negative numbers than regular int64s. In |
| Always four bytes. More efficient encoded than uint32 if values are often greater than 228. |
| Always eight bytes. More efficient encoded than uint64 if values are often greater than 256. |
| Always four bytes. |
| Always eight bytes. |
|
|
|
|
| May contain any arbitrary sequence of bytes. |
Limitations
The following limitations apply for the GPB support for proto2 in :
Default specifiers are not supported.
Groups are not supported.
The
packedoption is not supported.Import statements with the
gpb_blockwill have no effect.Nested types are not fully supported, since their names will become a part of the global scope. However, you can avoid this problem by changing names on one of the sub types.
The
extensionsspecifier is not supported.The
packedspecifier is not supported.Options are not supported.
Packages are not supported.
Import public specifiers is not supported.
Definitions of services are not supported, only messages.
The following limitations apply for the GPB support for proto3 in :
The options that are supported are
allow_aliasin enums andpackedfor fields.Importing definitions with the
gpb_blockis not supported.Import public specifiers is not supported.
The parent message type is not supported.
The
anytype is not supported.Packages are not supported.
Definitions of services are not supported, only messages.