Skip to content
Wire Types Recap
step 1/5

Reading — step 1 of 5

Read

~1 min readWire Format

Wire Types Recap

Wire TypeCodeUsed For
Varint0int32, int64, uint32, uint64, sint32, sint64, bool, enum
Fixed641fixed64, sfixed64, double
Length-delimited2string, bytes, message, packed repeated
Start Group3DEPRECATED (proto2 only)
End Group4DEPRECATED
Fixed325fixed32, sfixed32, float

The wire format intentionally LACKS schema info. To parse, you need the .proto.

Forward compatibility:

  • Old code reading new data: unknown fields preserved + skipped.
  • Each wire type knows how to skip itself:
    • Varint: read until top bit clear.
    • Fixed: read N bytes.
    • Length-delimited: read length, skip that many bytes.

Backward compatibility:

  • New code reading old data: missing fields default-filled.

Field type changes:

  • int32 ↔ int64 ↔ uint32 ↔ uint64 ↔ bool: COMPATIBLE (varint).
  • sint32 ↔ sint64: compatible (zigzag).
  • string ↔ bytes: compatible (length-delimited).
  • fixed32 ↔ sfixed32: compatible (4 bytes).
  • fixed64 ↔ sfixed64: compatible (8 bytes).
  • Cannot change wire type.
  • Cannot reuse a removed field number for different type.

Reserved tags / names:

message User {
    reserved 5, 6, 9 to 11;
    reserved "old_name", "another";

    string name = 1;
    ...
}

Prevents accidental reuse. Compiler errors if conflicting.

Field renaming:

  • Wire format unchanged (uses tag, not name).
  • Code generators may break if field accessed by name.
  • Reflection users beware.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…