1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Serialization and deserialization utilities using postcard.
//!
//! # Why postcard (not protobuf)?
//!
//! This crate uses two serialization formats:
//!
//! - **Protobuf**: gRPC transport framing only. The `.proto` definitions use
//! opaque `bytes` fields (`RaftRequest.data`, `VoteRequest.value`, etc.)
//! — protobuf does not participate in actual data serialization.
//! - **Postcard** (this module): all substantive serialization — RocksDB
//! storage, Raft log entries, forwarded requests, and internal metadata.
//!
//! Postcard is chosen for internal data because:
//! 1. OpenRaft's generic types (`VoteRequest<C>`, `Entry<C>`) require `serde`
//! and have no protobuf mapping. A single postcard codec serves both
//! storage and network paths.
//! 2. All nodes run the same Rust version — cross-language interop is not
//! a requirement, so protobuf's schema evolution adds no value.
//! 3. Postcard produces compact, heap-efficient output for `#[derive(Serialize)]`
//! types without schema boilerplate.
use crateResult;
use Serialize;
use DeserializeOwned;