Expand description
Serialization helpers for reducing allocation overhead.
§Reusable serialization buffers
SerBuffer provides a thread-local reusable Vec<u8> for
serde_json::to_writer. This eliminates the per-call buffer allocation
that dominates small-payload serialization cost (2.3× overhead at 64B).
use a2a_protocol_types::serde_helpers::SerBuffer;
use a2a_protocol_types::message::Part;
let part = Part::text("hello");
let bytes = SerBuffer::serialize(&part).expect("serialize");
assert!(bytes.starts_with(b"{"));§Borrowed deserialization
deser_from_str wraps serde_json::from_str which enables serde’s
visit_borrowed_str path. When deserializing from a &str (vs &[u8]),
serde_json can borrow string values directly from the input buffer instead
of allocating new String objects. This reduces deserialization allocations
by ~15-25% for types with many string fields.
Structs§
- SerBuffer
- Thread-local reusable serialization buffer.
Functions§
- deser_
from_ slice - Deserializes a value from a byte slice, first converting to
&strto enableserde_json’s borrowed-data optimizations. - deser_
from_ str - Deserializes a value from a
&strusingserde_json’s borrowed-data path.