Skip to content

Whether a field holding its zero value reaches the wire at all is a per-field choice, set by its field presence mode.

On the wire, an implicit presence field holding its zero value writes no bytes, not even a tag. An explicit presence field writes its tag and the value, 08 00 for an int32 in field 1 set to zero, as soon as your code sets it. Message fields and members of a oneof always have explicit presence, regardless of the file's default.

Edition 2024 defaults to EXPLICIT. Set features.field_presence = IMPLICIT; on a file or a field to leave default-valued fields off the wire instead.

IMPLICIT PRESENCE
Schema Definition
int32 count = 1 [features.field_presence = IMPLICIT];
Assigned Value
0
OMITTED
Wire Representation
(Zero Bytes)

Omitted from the wire whenever it holds the zero value, so a reader cannot tell this from never set.

EXPLICIT PRESENCE
Schema Definition
int32 count = 1;
Assigned Value
0 (set)
SERIALIZED
Wire Representation
08
Tag
00
Data

Edition 2024's default. Once set, the field is written even when the value is zero.

Further Reading

Next

Parse Loop

The Protobuf parse loop, field by field: read a tag, dispatch on the wire type, consume the value, and repeat until the bytes run out.