Struct ogg_magic::ogg_page::OggPage

source ·
pub struct OggPage {
Show 15 fields pub ready: bool, pub buffer: Vec<u8>, pub structure_version: u8, pub header_type: u8, pub is_fresh_packet: bool, pub is_bos: bool, pub is_boe: bool, pub absolute_granule_position: u64, pub stream_serial_number: u32, pub page_sequence_number: u32, pub page_checksum: u32, pub page_segments: usize, pub segment_table: Vec<u8>, pub parsed_segment_table: Vec<usize>, pub page_size: usize,
}
Expand description

Represents an Ogg page with various metadata and methods to manipulate it.

Fields§

§ready: bool§buffer: Vec<u8>§structure_version: u8§header_type: u8§is_fresh_packet: bool§is_bos: bool§is_boe: bool§absolute_granule_position: u64§stream_serial_number: u32§page_sequence_number: u32§page_checksum: u32§page_segments: usize§segment_table: Vec<u8>§parsed_segment_table: Vec<usize>§page_size: usize

Implementations§

source§

impl OggPage

source

pub fn new(buffer: Vec<u8>) -> Result<Self, OggFormatError>

Creates a new OggPage from a buffer.

§Arguments
  • buffer - A vector of bytes representing the Ogg page.
§Returns
  • Result<Self, OggFormatError> - An instance of OggPage or an error if the buffer is invalid.
source

pub fn validate_page_size(&self) -> Result<(), OggFormatError>

Validates the size of the Ogg page.

§Returns
  • Result<(), OggFormatError> - Ok if the size is valid, otherwise an error.
source

pub fn get_page_segment(&self, index: usize) -> Result<Vec<u8>, OggFormatError>

Retrieves a specific segment from the Ogg page.

§Arguments
  • index - The index of the segment to retrieve.
§Returns
  • Result<Vec<u8>, OggFormatError> - The segment as a vector of bytes or an error if the index is out of range.
source

pub fn map_segments<T, F>(&self, callback: F) -> Vec<T>
where F: Fn(&[u8], usize) -> T,

Applies a callback function to each segment of the Ogg page.

§Arguments
  • callback - A function to apply to each segment.
§Returns
  • Vec<T> - A vector containing the results of applying the callback to each segment.
source

pub fn create_laced_vec(input: &[usize]) -> Vec<u8>

Creates a laced vector from a slice of segment lengths.

§Arguments
  • input - A slice of segment lengths.
§Returns
  • Vec<u8> - A vector of bytes representing the laced segments.
source

pub fn remove_page_segment_and_get_raw_result( &self, index: usize, n: usize, ) -> Result<Vec<u8>, OggFormatError>

Removes a segment from the Ogg page and returns the raw result.

§Arguments
  • index - The starting index of the segment to remove.
  • n - The number of segments to remove.
§Returns
  • Result<Vec<u8>, OggFormatError> - The new buffer as a vector of bytes or an error if the operation fails.
source

pub fn add_page_segment_and_get_raw_result( &self, segments: &[Vec<u8>], index: usize, ) -> Result<Vec<u8>, OggFormatError>

Adds segments to the Ogg page and returns the raw result.

§Arguments
  • segments - A slice of vectors, each representing a segment to add.
  • index - The index at which to add the segments.
§Returns
  • Result<Vec<u8>, OggFormatError> - The new buffer as a vector of bytes or an error if the operation fails.
source

pub fn replace_page_segment_and_get_raw_result( &self, segment: Vec<u8>, index: usize, ) -> Result<Vec<u8>, OggFormatError>

Replaces a segment in the Ogg page and returns the raw result.

§Arguments
  • segment - A vector of bytes representing the new segment.
  • index - The index of the segment to replace.
§Returns
  • Result<Vec<u8>, OggFormatError> - The new buffer as a vector of bytes or an error if the operation fails.
source

pub fn remove_page_segment( &self, index: usize, n: usize, ) -> Result<Self, OggFormatError>

Removes a segment from the Ogg page.

§Arguments
  • index - The starting index of the segment to remove.
  • n - The number of segments to remove.
§Returns
  • Result<Self, OggFormatError> - A new OggPage instance or an error if the operation fails.
source

pub fn add_page_segment( &self, segments: &[Vec<u8>], index: usize, ) -> Result<Self, OggFormatError>

Adds segments to the Ogg page.

§Arguments
  • segments - A slice of vectors, each representing a segment to add.
  • index - The index at which to add the segments.
§Returns
  • Result<Self, OggFormatError> - A new OggPage instance or an error if the operation fails.
source

pub fn replace_page_segment( &self, segment: Vec<u8>, index: usize, ) -> Result<Self, OggFormatError>

Replaces a segment in the Ogg page.

§Arguments
  • segment - A vector of bytes representing the new segment.
  • index - The index of the segment to replace.
§Returns
  • Result<Self, OggFormatError> - A new OggPage instance or an error if the operation fails.
source

pub fn calculate_page_checksum(&self) -> u32

Calculates the checksum of the Ogg page.

§Returns
  • u32 - The calculated checksum.
source

pub fn update_page_checksum(&mut self)

Updates the checksum of the Ogg page.

source

pub fn if_page_checksum_correct(&self) -> bool

Checks if the checksum of the Ogg page is correct.

§Returns
  • bool - true if the checksum is correct, false otherwise.

Trait Implementations§

source§

impl Clone for OggPage

source§

fn clone(&self) -> OggPage

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for OggPage

source§

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

Formats the value using the given formatter. Read more

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.