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>
impl<'a> AccountReader<'a>
Sourcepub fn new(data: &'a [u8]) -> Result<Self, ProgramError>
pub fn new(data: &'a [u8]) -> Result<Self, ProgramError>
Create a new reader, validating that the data is at least HEADER_LEN bytes.
Sourcepub fn new_checked(
data: &'a [u8],
expected_disc: u8,
min_version: u8,
layout_id: &[u8; 8],
) -> Result<Self, ProgramError>
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.
Sourcepub fn header(&self) -> &AccountHeader
pub fn header(&self) -> &AccountHeader
Read the header as a typed reference.
Sourcepub fn discriminator(&self) -> u8
pub fn discriminator(&self) -> u8
Get the discriminator byte.
Sourcepub fn body(&self) -> SliceCursor<'a>
pub fn body(&self) -> SliceCursor<'a>
Get a cursor positioned at the start of the body (after the header).
Sourcepub fn body_bytes(&self) -> &'a [u8]
pub fn body_bytes(&self) -> &'a [u8]
Get the raw body bytes.
Sourcepub fn pubkey_at(&self, offset: usize) -> Result<&'a [u8; 32], ProgramError>
pub fn pubkey_at(&self, offset: usize) -> Result<&'a [u8; 32], ProgramError>
Read a pubkey from the body at a given byte offset.
Sourcepub fn u64_at(&self, offset: usize) -> Result<u64, ProgramError>
pub fn u64_at(&self, offset: usize) -> Result<u64, ProgramError>
Read a u64 from the body at a given byte offset.
Sourcepub fn u32_at(&self, offset: usize) -> Result<u32, ProgramError>
pub fn u32_at(&self, offset: usize) -> Result<u32, ProgramError>
Read a u32 from the body at a given byte offset.
Sourcepub fn u16_at(&self, offset: usize) -> Result<u16, ProgramError>
pub fn u16_at(&self, offset: usize) -> Result<u16, ProgramError>
Read a u16 from the body at a given byte offset.
Sourcepub fn u8_at(&self, offset: usize) -> Result<u8, ProgramError>
pub fn u8_at(&self, offset: usize) -> Result<u8, ProgramError>
Read a u8 from the body at a given byte offset.
Sourcepub fn i64_at(&self, offset: usize) -> Result<i64, ProgramError>
pub fn i64_at(&self, offset: usize) -> Result<i64, ProgramError>
Read an i64 from the body at a given byte offset.
Sourcepub fn bool_at(&self, offset: usize) -> Result<bool, ProgramError>
pub fn bool_at(&self, offset: usize) -> Result<bool, ProgramError>
Read a bool from the body at a given byte offset.