protozoa/wire
Protocol Buffer Wire Format Module
This module defines the low-level wire format types and utilities for Protocol Buffer binary encoding and decoding. It provides the foundational types and functions needed to work with the Protocol Buffer binary wire format specification.
Wire Format Fundamentals
Protocol Buffers use a binary wire format for efficient serialization. Each field is encoded with a specific wire type that determines how the data is represented:
- Varint: Variable-length integers (most integers, bools, enums)
- Fixed64: 8-byte fixed-width values (double, fixed64, sfixed64)
- LengthDelimited: Length-prefixed data (strings, bytes, messages, maps)
- Fixed32: 4-byte fixed-width values (float, fixed32, sfixed32)
- StartGroup/EndGroup: Deprecated group encoding (proto2 only)
Capabilities
- Wire type definitions: Complete enumeration of Protocol Buffer wire types
- Tag manipulation: Functions for creating and parsing field tags
- Format validation: Utilities for validating wire format data
- Type safety: Compile-time guarantees about wire format correctness
Usage in Protozoa
This module is primarily used by the encode and decode modules to:
- Determine the correct wire type for each field type
- Create properly formatted field tags
- Parse field numbers and wire types from binary data
- Validate wire format compliance
Public API
The main public component is the WireType type which is used throughout
the encode/decode pipeline. Internal utility functions are marked with
@internal as they are implementation details.
Types
WireType represents the encoding format used for Protocol Buffer fields. Each wire type determines how the field value is encoded on the wire.
pub type WireType {
Varint
Fixed64
LengthDelimited
StartGroup
EndGroup
Fixed32
}
Constructors
-
VarintVariable-length encoding for integers (int32, int64, uint32, uint64, sint32, sint64, bool, enum)
-
Fixed64Fixed 64-bit value (fixed64, sfixed64, double)
-
LengthDelimitedLength-prefixed data (string, bytes, embedded messages, packed repeated fields)
-
StartGroupDeprecated: Start of a group (no longer used in proto3)
-
EndGroupDeprecated: End of a group (no longer used in proto3)
-
Fixed32Fixed 32-bit value (fixed32, sfixed32, float)