CoderTools

Protocol Buffers Tool

Encode, decode and validate Protocol Buffers messages

Proto Schema

Sample Schemas:

Input

Parse schema and select a message type to generate form fields

Output

Protocol Buffers Documentation

What is Protocol Buffers?

Protocol Buffers (Protobuf) is a language-neutral, platform-neutral extensible mechanism for serializing structured data, developed by Google. It is smaller, faster, and simpler than XML and JSON for data serialization.

Key Features

  • Language-neutral and platform-neutral
  • Smaller and faster than XML/JSON
  • Strong typing with schema definition
  • Backward and forward compatibility
  • Automatic code generation
  • Efficient binary encoding

How to Use This Tool

  1. Enter your .proto schema definition in the schema editor
  2. Click Parse Schema to validate and parse the schema
  3. Select the message type you want to work with
  4. For encoding: Enter JSON data and click Encode
  5. For decoding: Enter binary data and click Decode
  6. Use Raw Decode to analyze binary data without schema

Tool Features

Encode

Convert JSON data to Protocol Buffers binary format. Supports form-based input for easy data entry with type validation.

Decode

Convert Protocol Buffers binary data back to readable JSON format. Supports Base64, Hex, and C-style hex input formats.

Raw Decode

Analyze protobuf binary data without schema. Useful for debugging, reverse engineering, or analyzing unknown messages.

Form Input

User-friendly form interface that generates input forms based on your schema. Supports nested messages, enums, and repeated fields.

Proto Syntax Reference

Protocol Buffers uses a simple syntax for defining message types:

syntax = "proto3";

message Person {
    string name = 1;
    int32 id = 2;
    string email = 3;
    
    enum PhoneType {
        MOBILE = 0;
        HOME = 1;
        WORK = 2;
    }
    
    message PhoneNumber {
        string number = 1;
        PhoneType type = 2;
    }
    
    repeated PhoneNumber phones = 4;
}
  • syntax: Specifies the protobuf version (proto2 or proto3)
  • message: Defines a message type with fields
  • field: Each field has a type, name, and unique number
  • enum: Defines enumeration types
  • repeated: Marks a field as repeated (array/list)
  • optional: Marks a field as optional (proto3)

Scalar Types

Protocol Buffers supports various scalar types:

Type Description Default
int32, int64Signed integers (variable-length encoding)0
uint32, uint64Unsigned integers0
sint32, sint64Signed integers with ZigZag encoding (efficient for negative numbers)0
fixed32, fixed64Fixed-width unsigned integers (4 or 8 bytes)0
sfixed32, sfixed64Fixed-width signed integers (4 or 8 bytes)0
float, doubleFloating point numbers (32 or 64 bit)0.0
boolBoolean values (true/false)false
stringUTF-8 encoded text strings""
bytesArbitrary binary dataempty

Wire Types

Protobuf uses wire types to determine how to read values from binary data:

Wire Type Meaning Used For
0Varintint32, int64, uint32, uint64, sint32, sint64, bool, enum
164-bitfixed64, sfixed64, double
2Length-delimitedstring, bytes, embedded messages, packed repeated
532-bitfixed32, sfixed32, float

Best Practices

  • Use proto3 syntax for new projects - it's simpler and more widely supported
  • Keep field numbers stable - never reuse or change numbers for existing fields
  • Use meaningful field names that clearly describe the data
  • Reserve field numbers 1-15 for frequently used fields (they use 1 byte)
  • Use 'repeated' keyword for arrays/lists of values
  • Define enums for fields that have a fixed set of possible values

FAQ

What's the difference between proto2 and proto3?

Proto3 simplifies the syntax by removing required fields - all fields are optional by default. It also changes default values and removes field presence detection for scalar types. Proto3 is recommended for new projects.

Can I decode protobuf without a schema?

Yes! Use the 'Raw Decode' feature to analyze binary data without a schema. Field names will be shown as numbers (field_1, field_2, etc.) and some type information may be ambiguous.

Why is my encoded data different from expected?

Protobuf encoding is deterministic, but default values (0, false, empty strings) are typically not encoded in proto3 to save space. Also, the order of fields in JSON doesn't affect the binary encoding.

How do I handle nested messages?

Define nested messages in your schema and use nested JSON objects. In form mode, click the nested field button to open a dialog for editing nested data.

Common Use Cases

  • Inter-service communication in microservices (gRPC)
  • Data storage and caching
  • Configuration files
  • Network protocols and APIs

References