Crates.io | postbag |
lib.rs | postbag |
version | 0.4.1 |
created_at | 2025-09-04 13:56:11.746709+00 |
updated_at | 2025-09-09 10:56:27.360232+00 |
description | Postbag is a high-performance serde codec for Rust that provides efficient data encoding with configurable levels of forward and backward compatibility. |
homepage | |
repository | https://github.com/surban/postbag |
max_upload_size | |
id | 1824238 |
size | 115,435 |
Postbag is a high-performance binary serde codec for Rust that provides efficient data encoding with configurable levels of forward and backward compatibility.
Slim
) or forward/backward compatible encoding (Full
) with field identifiersuse serde::{Serialize, Deserialize};
use postbag::{to_full_vec, from_full_slice};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Person {
name: String,
age: u32,
}
let original = Person {
name: "Alice".to_string(),
age: 30,
};
// Serialize to a byte vector using Full configuration
let bytes = to_full_vec(&original).unwrap();
// Deserialize back to the original type
let deserialized: Person = from_full_slice(&bytes).unwrap();
assert_eq!(original, deserialized);
Full
ConfigurationThe Full
configuration provides maximum compatibility and schema evolution capabilities:
_0
through _59
are encoded with just a single byteWhen using Full
configuration, fields named _n
(where n
is 0-59) are encoded using just a single byte instead of the full string. Use #[serde(rename = "...")]
to specify the numerical id for each field.
This can significantly reduce serialized size for structs with many fields:
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct CompactData {
#[serde(rename = "_3")]
my_field: u32,
#[serde(rename = "_15")]
another_field: String,
// Regular field names work normally
normal_field: bool,
}
This feature is entirely optional; regular field names continue to work as expected. Fields with normal and numerical names can be mixed without limitations in a single struct.
Slim
ConfigurationThe Slim
configuration prioritizes performance and compact size:
Supported changes when using them Slim
configuration:
Important: Fields and enum variants must maintain their order for compatibility when using Slim
configuration.
Postbag started as a fork of postcard with the intent to add forward and backward compatibility to the serialized data format. While postcard provides excellent performance and compact encoding, postbag extends this foundation to support schema evolution and data format compatibility across different versions of your applications.
Postbag is licensed under the Apache 2.0 license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Postbag by you, shall be licensed as Apache 2.0, without any additional terms or conditions.