pub struct JaguarSerializer { /* private fields */ }Expand description
Compact binary serializer, optimized for resource-constrained environments like Solana programs and embedded systems.
§Usage
use jaguar::{JaguarSerializer, JaguarDeserializer};
let pubkey = [1u8; 32];
let mut ser = JaguarSerializer::new();
pubkey.serialize(&mut ser).unwrap();
let data = ser.finish();§Derive Usage
#[derive(JaguarSerialize, JaguarDeserialize)]
struct MyStruct {
pubkey: [u8; 32],
}
let my_struct = MyStruct { pubkey };
let mut ser = JaguarSerializer::new();
my_struct.serialize(&mut ser).unwrap().finish();Implementations§
Source§impl JaguarSerializer
impl JaguarSerializer
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new serializer with the specified initial capacity.
Sourcepub fn finish(self) -> Vec<u8>
pub fn finish(self) -> Vec<u8>
Finalizes and returns the serialized data.
This truncates the internal buffer to the actual size of the serialized data and returns ownership of the buffer.
Sourcepub fn write_u8(&mut self, value: u8) -> Result<(), SerError>
pub fn write_u8(&mut self, value: u8) -> Result<(), SerError>
Writes a single byte to the serialized output.
Sourcepub fn write_bool_slice(&mut self, slice: &[bool]) -> Result<(), SerError>
pub fn write_bool_slice(&mut self, slice: &[bool]) -> Result<(), SerError>
Writes a slice of booleans as a bit-packed sequence.
Sourcepub fn write_varint(&mut self, value: u64) -> Result<(), SerError>
pub fn write_varint(&mut self, value: u64) -> Result<(), SerError>
Varint encoding for unsigned integers.
Sourcepub fn write_signed_varint(&mut self, value: i64) -> Result<(), SerError>
pub fn write_signed_varint(&mut self, value: i64) -> Result<(), SerError>
Writes a signed integer using variable-length encoding.
This uses zigzag encoding to represent signed integers, where the sign bit is interleaved with magnitude bits.
Sourcepub fn write_bool(&mut self, value: bool) -> Result<(), SerError>
pub fn write_bool(&mut self, value: bool) -> Result<(), SerError>
Writes a boolean value as a single byte.
Sourcepub fn write_f32(&mut self, value: f32) -> Result<(), SerError>
pub fn write_f32(&mut self, value: f32) -> Result<(), SerError>
Writes a 32-bit float with special handling for common values.
This optimizes for common float values (0.0, 1.0, -1.0), using a single byte marker. All other values are stored in full IEEE-754 format with a marker byte.
Sourcepub fn write_f64(&mut self, value: f64) -> Result<(), SerError>
pub fn write_f64(&mut self, value: f64) -> Result<(), SerError>
Writes a 64-bit float.
Similar to write_f32, but for double-precision floats.
Sourcepub fn write_str(&mut self, s: &str) -> Result<(), SerError>
pub fn write_str(&mut self, s: &str) -> Result<(), SerError>
Writes a string as a length-prefixed UTF-8 byte sequence.
Sourcepub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), SerError>
pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), SerError>
Writes a byte slice as a length-prefixed sequence.
Sourcepub fn write_u32_slice(&mut self, slice: &[u32]) -> Result<(), SerError>
pub fn write_u32_slice(&mut self, slice: &[u32]) -> Result<(), SerError>
Writes a slice of 32-bit integers.
Sourcepub fn write_string_vec(&mut self, vec: &[String]) -> Result<(), SerError>
pub fn write_string_vec(&mut self, vec: &[String]) -> Result<(), SerError>
Writes a vector of strings, each encoded as a length-prefixed UTF-8 sequence.
Sourcepub fn write_u8_slice(&mut self, slice: &[u8]) -> Result<(), SerError>
pub fn write_u8_slice(&mut self, slice: &[u8]) -> Result<(), SerError>
Writes a slice of 8-bit integers.
Sourcepub fn write_u16_slice(&mut self, slice: &[u16]) -> Result<(), SerError>
pub fn write_u16_slice(&mut self, slice: &[u16]) -> Result<(), SerError>
Writes a slice of 16-bit integers using varlen encoding.
Sourcepub fn write_u64_slice(&mut self, slice: &[u64]) -> Result<(), SerError>
pub fn write_u64_slice(&mut self, slice: &[u64]) -> Result<(), SerError>
Writes a slice of 64-bit integers using varlen encoding.
Sourcepub fn write_i8_slice(&mut self, slice: &[i8]) -> Result<(), SerError>
pub fn write_i8_slice(&mut self, slice: &[i8]) -> Result<(), SerError>
Writes a slice of signed 8-bit integers.
Sourcepub fn write_i16_slice(&mut self, slice: &[i16]) -> Result<(), SerError>
pub fn write_i16_slice(&mut self, slice: &[i16]) -> Result<(), SerError>
Writes a slice of signed 16-bit integers.
Sourcepub fn write_i64_slice(&mut self, slice: &[i64]) -> Result<(), SerError>
pub fn write_i64_slice(&mut self, slice: &[i64]) -> Result<(), SerError>
Writes a slice of signed 64-bit integers.