Comparison table

.proto Type introduce C++ Type Java Type Python Type Go Type Ruby Type C# Type PHP Type
double double double float float64 Float double float
float float float float float32 Float float float
int32 Variable length encoding is used. Negative values cannot be encoded. If a field may have negative values, it is recommendedsint32 int32 int int int32 Fixnum or Bignum (on demand) int integer
int64 Variable length encoding is used. Negative values cannot be encoded. If a field may have negative values, it is recommendedsint64 int64 long int/long int64 Bignum long integer/string
uint32 Use variable length encoding uint32 int int/long uint32 Fixnum or Bignum (on demand) uint integer
uint64 Use variable length encoding uint64 long int/long uint64 Bignum ulong integer/string
sint32 Variable length encoding, signed int, better than INT32 for negative numbers int32 int int int32 Fixnum or Bignum (on demand) int integer
sint64 Variable length encoding, signed int, better than INT64 for negative numbers int64 long int/long int64 Bignum long integer/string
fixed32 Always four bytes with a value greater than2 ^ 28Is more effective than the uint32 uint32 int int uint32 Fixnum or Bignum (on demand) uint integer
fixed64 Always four bytes with a value greater than2 ^ 56Is more valid than uint64 uint64 long int/long uint64 Bignum ulong integer/string
sfixed32 It is always four bytes int32 int int int32 Fixnum or Bignum (on demand) int integer
sfixed64 It is always four bytes int64 long int/long int64 Bignum long integer/string
bool bool boolean bool bool TrueClass/FalseClass bool boolean
string The string must always contain UTF-8 encoding or 7-bit ASCII text string String str/unicode string String (UTF-8) string string
bytes Can contain any sequence of bytes string ByteString str []byte String (ASCII-8BIT) ByteString string

For more information on coding, check out Google Docs (Protobuf coding)

Field defaults

When a message is parsed, if the encoded message does not contain a particular individual element (field), the corresponding field in the parsed object is set to the default value for that field. These defaults are type specific:

  • For strings, the default is an empty string
  • For bytes, the default value is null bytes.
  • For bools, the default is false.
  • For numeric types, the default value is zero.
  • For enumerations, the default value is the first enumerated value defined, which must be 0.
  • For message fields, this depends on the language in which they are implemented