Skip to main content

JaguarSerializer

Struct JaguarSerializer 

Source
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

Source

pub fn new() -> Self

Creates a new serializer with a default capacity of 1024 bytes.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new serializer with the specified initial capacity.

Source

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.

Source

pub fn data(&self) -> &[u8]

Returns a slice containing the currently serialized data.

Source

pub fn reset(&mut self)

Resets the serializer to its initial state, allowing reuse.

Source

pub fn write_u8(&mut self, value: u8) -> Result<(), SerError>

Writes a single byte to the serialized output.

Source

pub fn write_bool_slice(&mut self, slice: &[bool]) -> Result<(), SerError>

Writes a slice of booleans as a bit-packed sequence.

Source

pub fn write_varint(&mut self, value: u64) -> Result<(), SerError>

Varint encoding for unsigned integers.

Source

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.

Source

pub fn write_bool(&mut self, value: bool) -> Result<(), SerError>

Writes a boolean value as a single byte.

Source

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.

Source

pub fn write_f64(&mut self, value: f64) -> Result<(), SerError>

Writes a 64-bit float.

Similar to write_f32, but for double-precision floats.

Source

pub fn write_str(&mut self, s: &str) -> Result<(), SerError>

Writes a string as a length-prefixed UTF-8 byte sequence.

Source

pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), SerError>

Writes a byte slice as a length-prefixed sequence.

Source

pub fn write_u32_slice(&mut self, slice: &[u32]) -> Result<(), SerError>

Writes a slice of 32-bit integers.

Source

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.

Source

pub fn write_u8_slice(&mut self, slice: &[u8]) -> Result<(), SerError>

Writes a slice of 8-bit integers.

Source

pub fn write_u16_slice(&mut self, slice: &[u16]) -> Result<(), SerError>

Writes a slice of 16-bit integers using varlen encoding.

Source

pub fn write_u64_slice(&mut self, slice: &[u64]) -> Result<(), SerError>

Writes a slice of 64-bit integers using varlen encoding.

Source

pub fn write_i8_slice(&mut self, slice: &[i8]) -> Result<(), SerError>

Writes a slice of signed 8-bit integers.

Source

pub fn write_i16_slice(&mut self, slice: &[i16]) -> Result<(), SerError>

Writes a slice of signed 16-bit integers.

Source

pub fn write_i64_slice(&mut self, slice: &[i64]) -> Result<(), SerError>

Writes a slice of signed 64-bit integers.

Source

pub fn write_f32_slice(&mut self, slice: &[f32]) -> Result<(), SerError>

Writes a slice of 32-bit floats.

Source

pub fn write_f64_slice(&mut self, slice: &[f64]) -> Result<(), SerError>

Writes a slice of 64-bit floats.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.