Skip to content
uencoder

Protocol Buffers

Protocol Buffers is Google's language-neutral binary serialization format; it requires a .proto schema definition and is more compact and type-safe than JSON/XML.

Purpose

To provide strongly typed, compact, and efficient cross-language data exchange, with schemas guaranteeing compatibility.

Mechanism

A .proto IDL defines message types with field numbers. When encoding, each field starts with a (field_number<<3 | wire_type) tag; integers use varint, and strings and nested messages use length prefixes. Unknown fields stay forward-compatible. proto3 simplifies the syntax.

Use cases

  • gRPC transport protocol
  • Google internal data storage
  • Mobile APIs (saving bandwidth)
  • Configuration and persistence

Examples

  • Input
    message User { string name = 1; }
    Output
    Binary encoding

    Requires protoc compilation

Common errors

Changing field numbers breaks compatibility
Once assigned, numbers must not be reused or changed

Related terms

Related tools

References