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.
...
The GPB message elements can be defined with any of the following types:
Type | Notes |
---|
double | 8 bytes signed. |
float | 4 bytes signed. |
int32 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. |
int64 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. |
uint32 | Uses variable-length encoding. |
uint64 | Uses variable-length encoding. |
sint32 | Uses variable-length encoding. Signed int value. This more efficiently encode negative numbers than regular int32s. |
sint64 | Uses variable-length encoding. Signed int value. This more efficiently encode negative numbers than regular int64s. In sint64 will be more efficient than uint64. |
fixed32 | Always four bytes. More efficient encoded than uint32 if values are often greater than 228. |
fixed64 | Always eight bytes. More efficient encoded than uint64 if values are often greater than 256. |
sfixed32 | Always four bytes. |
sfixed64 | Always eight bytes. |
bool | Use the bool type to define the GPB message elements. |
string | Use the string type to define the GPB message elements. |
bytes | May contain any arbitrary sequence of bytes. |
Info |
---|
title | Example - GPB format using proto2 |
---|
|
Code Block |
---|
gpb_block {
message MyData{
required string myName =1;
required string myText =2;
required string extraName =3;
required int32 myPriority =4;
required uint32 myId =5;
required uint32 equipmentId =6;
required MyParam myParams = 7;
}
message MyParam {
repeated string someField = 1;
}
message MyAdditional {
required uint32 action = 1;
required string alias = 2;
required int64 content = 3;
optional int32 newId = 4;
optional int32 newType = 5;
optional uint64 myKey = 6;
}
message FlashEx {
required string someField = 1;
}
message MyExtras {
repeated FlashEx ex = 1;
}
message MyList {
repeated string list = 1;
}
message SysmanData {
required string someField = 1;
}
};
external Wrapper {
int dataSize: static_size(4), encode_value(udr_size-4);
SysmanData data : dynamic_size(dataSize);
};
in_map Wrapper_inMap: external(Wrapper),
target_internal(Wrapper_int) {
automatic;
};
out_map Wrapper_outMap: external(Wrapper),
internal(Wrapper_int) {
automatic;
};
decoder Wrapper_decoder: in_map(Wrapper_inMap);
encoder Wrapper_encoder: out_map(Wrapper_outMap); |
|
Info |
---|
title | Example - GPB format using proto3 |
---|
|
Code Block |
---|
gpb_block {
syntax = "proto3";
message MyData{
string myName =1;
string myText =2;
string extraName =3;
int32 myPriority =4;
uint32 myId =5;
uint32 equipmentId =6;
MyParam myParams = 7;
map<string, MyParam> myMap = 8;
AnEnum anEnum = 9;
AnotherEnum anotherEnum = 10;
}
enum AnEnum {
V0 = 0;
V1 = 1;
}
enum AnotherEnum {
option allow_alias = true;
V0 = 0;
V1 = 0;
}
message MyParam {
repeated string someField = 1;
}
message MyAdditional {
uint32 action = 1;
string alias = 2;
int64 content = 3;
int32 newId = 4;
int32 newType = 5;
uint64 myKey = 6;
}
message FlashEx {
string someField = 1;
}
message MyExtras {
repeated FlashEx ex = 1;
}
message MyList {
repeated string list = 1;
}
message SysmanData {
string someField = 1;
}
};
external Wrapper {
int dataSize: static_size(4), encode_value(udr_size-4);
SysmanData data : dynamic_size(dataSize);
};
in_map Wrapper_inMap: external(Wrapper),
target_internal(Wrapper_int) {
automatic;
};
out_map Wrapper_outMap: external(Wrapper),
internal(Wrapper_int) {
automatic;
};
decoder Wrapper_decoder: in_map(Wrapper_inMap);
encoder Wrapper_encoder: out_map(Wrapper_outMap); |
|
Note |
---|
|
Since GPB does not specify the size, this has to be done externally, which is why int dataSize has to be included in the external unless the size is previously known. |