3 unstable releases
Uses new Rust 2024
| new 0.2.1 | Jan 12, 2026 |
|---|---|
| 0.2.0 | Jan 11, 2026 |
| 0.1.0 | Oct 15, 2025 |
#865 in Encoding
Used in 2 crates
135KB
2.5K
SLoC
protobuf-core
A primitive utility library for Protocol Buffers in Rust.
This library provides common definitions, constants, enums, and basic logic for implementing Protocol Buffers. It is designed to minimize entry barriers for developers who want to implement Protocol Buffers functionality.
Features
- Wire Format Constants: Fundamental protobuf wire format definitions and limits
- Varint Encoding/Decoding: Core varint operations with support for all protobuf integer types
- Tag Operations: Tag construction and parsing (field number + wire type)
- Field I/O: Low-level utilities for reading and writing raw protobuf fields
- Field Number Validation: Type-safe field number handling with range validation
Usage
Add this to your Cargo.toml:
[dependencies]
protobuf-core = "0.2.0"
Feature Flags
read(enabled by default): Enables field reading utilitieswrite(enabled by default): Enables field writing utilities
You can use features independently:
[dependencies]
protobuf-core = { version = "0.2.1", default-features = false, features = ["read"] }
Quick Start
Reading Fields
use protobuf_core::{Field, IteratorExtProtobuf};
let bytes = vec![0x08, 0x96, 0x01]; // field 1: 150
let fields: Vec<Field<Vec<u8>>> = bytes
.into_iter()
.protobuf_fields()
.collect::<Result<Vec<Field<Vec<u8>>>, _>>()
.unwrap();
Writing Fields
use protobuf_core::{WriteExtProtobuf, Field, FieldValue, FieldNumber};
let mut buffer = Vec::new();
let field: Field<Vec<u8>> = Field::new(
FieldNumber::try_from(1)?,
FieldValue::from_uint64(150)
);
buffer.write_protobuf_field(&field)?;
# Ok::<(), protobuf_core::ProtobufError>(())
Design Philosophy
This library provides building blocks for implementing Protocol Buffers, not a complete message parser or serializer. It focuses on:
- Low-level primitives: Raw field I/O without semantic interpretation
- Flexibility: Support for both owned and borrowed data
- Minimal dependencies: Only depends on
thiserrorfor error handling - Clear API: Trait-based extension methods following Rust conventions
For comprehensive API documentation, see docs.rs.
License
Licensed under the Apache License, Version 2.0.
Dependencies
~155–560KB
~13K SLoC