Skip to main content

SegmentReader

Struct SegmentReader 

Source
pub struct SegmentReader<'a> { /* private fields */ }
Expand description

Zero-copy segment-aware partial account reader.

Construct with SegmentReader::new. the layout_id is verified up front so downstream read_* calls can be infallible w.r.t. identity.

Implementations§

Source§

impl<'a> SegmentReader<'a>

Source

pub fn new( bytes: &'a [u8], layout: &'a LayoutManifest, ) -> Result<Self, ReaderError>

Bind a LayoutManifest to raw bytes, verifying the fingerprint.

Source

pub unsafe fn new_unchecked(bytes: &'a [u8], layout: &'a LayoutManifest) -> Self

Bind without re-checking the fingerprint. Only use if you’ve already verified identity upstream.

§Safety

The caller promises bytes is a layout-shaped blob.

Source

pub const fn bytes(&self) -> &'a [u8]

Access the raw account buffer.

Source

pub const fn layout(&self) -> &'a LayoutManifest

Layout manifest this reader was constructed against.

Source

pub fn field(&self, name: &str) -> Option<&'a FieldDescriptor>

Look up a field descriptor by name.

Source

pub fn offset_of(&self, name: &str) -> Option<usize>

Absolute byte offset of a named field (accounts for the 12-byte Hopper header by using offset as field-start; since the manifest’s FieldDescriptor.offset is already absolute under the framework’s convention, this is a pass-through).

Source

pub fn read_raw(&self, name: &str) -> Result<&'a [u8], ReaderError>

Raw byte slice for a named field.

Source

pub fn read_u8(&self, name: &str) -> Result<u8, ReaderError>

Read a u8 field.

Source

pub fn read_u16(&self, name: &str) -> Result<u16, ReaderError>

Read a little-endian u16.

Source

pub fn read_u32(&self, name: &str) -> Result<u32, ReaderError>

Read a little-endian u32.

Source

pub fn read_u64(&self, name: &str) -> Result<u64, ReaderError>

Read a little-endian u64.

Source

pub fn read_u128(&self, name: &str) -> Result<u128, ReaderError>

Read a little-endian u128.

Source

pub fn read_pubkey(&self, name: &str) -> Result<[u8; 32], ReaderError>

Read a 32-byte Solana public key (Pubkey).

Source

pub fn layout_id(&self) -> [u8; 8]

Read the layout_id from the attached buffer.

Trait Implementations§

Source§

impl<'a> Debug for SegmentReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SegmentReader<'a>

§

impl<'a> RefUnwindSafe for SegmentReader<'a>

§

impl<'a> Send for SegmentReader<'a>

§

impl<'a> Sync for SegmentReader<'a>

§

impl<'a> Unpin for SegmentReader<'a>

§

impl<'a> UnsafeUnpin for SegmentReader<'a>

§

impl<'a> UnwindSafe for SegmentReader<'a>

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.