Protocol Buffer Types: Difference between revisions
Jump to navigation
Jump to search
(→int32) |
(→enum) |
||
(16 intermediate revisions by the same user not shown) | |||
Line 19: | Line 19: | ||
int32 some_int = 1; | int32 some_int = 1; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The default value is 0. | |||
==<tt>uint32</tt>== | ==<tt>uint32</tt>== | ||
Line 31: | Line 33: | ||
==<tt>float</tt>== | ==<tt>float</tt>== | ||
==<tt>double</tt>== | ==<tt>double</tt>== | ||
=Bytes= | =<span id='byte'></span>Bytes= | ||
<syntaxhighlight lang='protobuf'> | <syntaxhighlight lang='protobuf'> | ||
bytes some_bytes = 1; | bytes some_bytes = 1; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The default value is the empty byte array. | |||
=<span id='repeated'></span>List (Array)= | |||
<syntaxhighlight lang='protobuf'> | |||
repeated <some_other_type> <field_name> = <tag>; | |||
</syntaxhighlight> | |||
Example: | |||
<syntaxhighlight lang='protobuf'> | |||
repeated int32 sizes = 1; | |||
repeated string names = 1; | |||
</syntaxhighlight> | |||
The default value is the empty list. | |||
=<span id='Enum'></span><tt>enum</tt>= | |||
The <code>enum</code> must start with the tag 0. The default value is the first value. Always start an <code>enum</code> | |||
<code>enum</code>s can be defined at the top level of a [[Protocol_Buffer_Concepts#.proto_Files|<code>.proto</code>]] file or they can be embedded. | |||
<syntaxhighlight lang='protobuf'> | |||
enum DayOfTheWeek { | |||
UNKNOWN_DAY_OF_WEEK = 0; | |||
MONDAY_DAY_OF_WEEK = 1; | |||
TUESDAY_DAY_OF_WEEK = 2; | |||
WEDNESDAY_DAY_OF_WEEK = 3; | |||
THURSDAY_DAY_OF_WEEK = 4; | |||
FRIDAY_DAY_OF_WEEK = 5; | |||
SATURDAY_DAY_OF_WEEK = 6; | |||
SUNDAY_DAY_OF_WEEK = 7; | |||
} | |||
message Something { | |||
DayOfTheWeek day_of_the_week = 1; | |||
} | |||
</syntaxhighlight> | |||
=Other Common Types= | |||
==Google Common Types== | |||
{{External|https://github.com/googleapis/googleapis/tree/master/google/type}} | |||
===<tt>date</tt>=== | |||
{{External|https://github.com/googleapis/googleapis/blob/master/google/type/date.proto}} | |||
===<tt>datetime</tt>=== | |||
===<tt>dayofweek</tt>=== | |||
{{External|https://github.com/googleapis/googleapis/blob/master/google/type/dayofweek.proto}} | |||
===<tt>decimal</tt>=== | |||
===<tt>expr</tt>=== | |||
===<tt>fraction</tt>=== | |||
===<tt>interval</tt>=== | |||
===<tt>money</tt>=== | |||
{{External|https://github.com/googleapis/googleapis/blob/master/google/type/money.proto}} | |||
===<tt>month</tt>=== | |||
===<tt>phone_number</tt>=== | |||
===<tt>postal_address</tt>=== | |||
===<tt>timeofday</tt>=== |
Revision as of 23:19, 7 May 2024
Internal
Overview
String
string some_string = 1;
The default value is empty string (""
). The field contains UTF-8 encoded or 7-bit ASCII text.
Boolean
bool some_bool = 1;
The default value is false
.
Scalar Number Types
int32
int32 some_int = 1;
The default value is 0.
uint32
sint32
fixed32
sfixed32
int64
uint64
sint64
fixed64
sfixed64
float
double
Bytes
bytes some_bytes = 1;
The default value is the empty byte array.
List (Array)
repeated <some_other_type> <field_name> = <tag>;
Example:
repeated int32 sizes = 1;
repeated string names = 1;
The default value is the empty list.
enum
The enum
must start with the tag 0. The default value is the first value. Always start an enum
enum
s can be defined at the top level of a .proto
file or they can be embedded.
enum DayOfTheWeek {
UNKNOWN_DAY_OF_WEEK = 0;
MONDAY_DAY_OF_WEEK = 1;
TUESDAY_DAY_OF_WEEK = 2;
WEDNESDAY_DAY_OF_WEEK = 3;
THURSDAY_DAY_OF_WEEK = 4;
FRIDAY_DAY_OF_WEEK = 5;
SATURDAY_DAY_OF_WEEK = 6;
SUNDAY_DAY_OF_WEEK = 7;
}
message Something {
DayOfTheWeek day_of_the_week = 1;
}