Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there one-byte type in protobuf?

Tags:

I can't find if there is possible to have char / byte type in proto.

I can see various types here:

  • https://developers.google.com/protocol-buffers/docs/proto
  • https://developers.google.com/protocol-buffers/docs/encoding

but I can't find byte type and even int16 types there.

like image 785
cnd Avatar asked Jul 22 '13 05:07

cnd


People also ask

What is protobuf type?

Protocol Buffer (Protobuf) provides two simpler options for dealing with values that might be of more than one type. The Any type can represent any known Protobuf message type. And you can use the oneof keyword to specify that only one of a range of fields can be set in any message.

Is protobuf binary format?

A protocol buffer message is a series of key-value pairs. The binary version of a message just uses the field's number as the key – the name and declared type for each field can only be determined on the decoding end by referencing the message type's definition (i.e. the . proto file).

Is protobuf text or binary?

Protobuf is a binary format, so reading and writing should be done as binary, not text. If you don't want binary format, you should consider using something other than protobuf (there are lots of textual data formats, such as XML, JSON, CSV); just using text abstractions is not enough.

How big can a protobuf message be?

Protobuf has a hard limit of 2GB, because many implementations use 32-bit signed arithmetic. For security reasons, many implementations (especially the Google-provided ones) impose a size limit of 64MB by default, although you can increase this limit manually if you need to.


1 Answers

No, there is no fixed 1-byte type. Fixed length has 4 and 8 byte variants only. Most other numeric values are encoded as "varint"s, which is variable length depending on magnitude (and sign, but "zigzag" comes into play there). So you can store bytes with value 0-127 in one byte, and 128-255 in two bytes. 16-bit values will take between 1 and 3 bytes depending on magnitude (and sign /zigzag etc).

For multiples, there is "bytes" for the 8-bit version, and "packed" for the rest; this avoids the cost of a field-header per value.

like image 117
Marc Gravell Avatar answered Oct 13 '22 23:10

Marc Gravell