Skip to main content

AccountReader

Struct AccountReader 

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

Zero-copy account reader with header awareness.

Constructs from a borrowed &[u8], validates the header, and exposes a cursor over the body for sequential field reads.

Implementations§

Source§

impl<'a> AccountReader<'a>

Source

pub fn new(data: &'a [u8]) -> Result<Self, ProgramError>

Create a new reader, validating that the data is at least HEADER_LEN bytes.

Source

pub fn new_checked( data: &'a [u8], expected_disc: u8, min_version: u8, layout_id: &[u8; 8], ) -> Result<Self, ProgramError>

Create a reader and validate discriminator + minimum version + layout_id.

Source

pub fn header(&self) -> &AccountHeader

Read the header as a typed reference.

Source

pub fn discriminator(&self) -> u8

Get the discriminator byte.

Source

pub fn version(&self) -> u8

Get the version byte.

Source

pub fn flags(&self) -> u16

Get the flags field.

Source

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

Get the layout_id field (bytes 4..12).

Source

pub fn body(&self) -> SliceCursor<'a>

Get a cursor positioned at the start of the body (after the header).

Source

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

Get the raw body bytes.

Source

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

Get the full raw data including header.

Source

pub fn pubkey_at(&self, offset: usize) -> Result<&'a [u8; 32], ProgramError>

Read a pubkey from the body at a given byte offset.

Source

pub fn u64_at(&self, offset: usize) -> Result<u64, ProgramError>

Read a u64 from the body at a given byte offset.

Source

pub fn u32_at(&self, offset: usize) -> Result<u32, ProgramError>

Read a u32 from the body at a given byte offset.

Source

pub fn u16_at(&self, offset: usize) -> Result<u16, ProgramError>

Read a u16 from the body at a given byte offset.

Source

pub fn u8_at(&self, offset: usize) -> Result<u8, ProgramError>

Read a u8 from the body at a given byte offset.

Source

pub fn i64_at(&self, offset: usize) -> Result<i64, ProgramError>

Read an i64 from the body at a given byte offset.

Source

pub fn bool_at(&self, offset: usize) -> Result<bool, ProgramError>

Read a bool from the body at a given byte offset.

Source

pub fn bytes_at<const N: usize>( &self, offset: usize, ) -> Result<[u8; N], ProgramError>

Read a fixed-size byte array from the body at a given byte offset.

Source

pub fn body_len(&self) -> usize

Number of body bytes remaining after the header.

Auto Trait Implementations§

§

impl<'a> Freeze for AccountReader<'a>

§

impl<'a> RefUnwindSafe for AccountReader<'a>

§

impl<'a> Send for AccountReader<'a>

§

impl<'a> Sync for AccountReader<'a>

§

impl<'a> Unpin for AccountReader<'a>

§

impl<'a> UnsafeUnpin for AccountReader<'a>

§

impl<'a> UnwindSafe for AccountReader<'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.