Struct OggPacket

Source
pub struct OggPacket {
    pub version: u8,
    pub packet_type: OggPacketType,
    pub granule_position: u64,
    pub stream_id: u32,
    pub packet_index: u32,
    pub checksum: u32,
    pub segment_table: Vec<u8>,
    pub data: Vec<u8>,
}
Expand description
  • An ogg packet as a stream container

Fields§

§version: u8

Ogg Version must be zero

§packet_type: OggPacketType
  • The first packet should be OggPacketType::BeginOfStream
  • The last packet should be OggPacketType::EndOfStream
  • The others should be OggPacketType::Continuation
§granule_position: u64
  • For vorbis, this field indicates when you had decoded from the first packet to this packet, and you had finished decoding this packet, how many of the audio frames you should get.
§stream_id: u32
  • The identifier for the streams. Every Ogg packet belonging to a stream should have the same stream_id.
§packet_index: u32
  • The index of the packet, beginning from zero.
§checksum: u32
  • The checksum of the packet.
§segment_table: Vec<u8>
  • A table indicates each segment’s size, the max is 255. And the size of the table also couldn’t exceed 255.
§data: Vec<u8>
  • The data encapsulated in the Ogg Stream

Implementations§

Source§

impl OggPacket

Source

pub fn new( stream_id: u32, packet_type: OggPacketType, packet_index: u32, ) -> Self

Create a new Ogg packet

Source

pub fn write(&mut self, data: &[u8]) -> usize

Write some data to the packet, returns the actual written bytes.

Source

pub fn clear(&mut self)

Clear all data inside the packet

Source

pub fn get_segments(&self) -> Vec<Vec<u8>>

Read all of the data as segments from the packet

Source

pub fn get_inner_data_size(&self) -> usize

Get inner data size

Source

pub fn get_inner_data(&self) -> Vec<u8>

Read all of the data as a flattened Vec<u8>

Source

pub fn into_inner(self) -> Vec<u8>

Read all of the data as a flattened Vec<u8> and consume self

Source

pub fn crc(crc: u32, data: &[u8]) -> u32

Calculate the checksum

Source

pub fn get_checksum(ogg_packet: &[u8]) -> Result<u32>

Source

pub fn fill_checksum_field(ogg_packet: &mut [u8]) -> Result<()>

Set the checksum for the Ogg packet

Source

pub fn into_bytes(self) -> Vec<u8>

Serialize the packet to bytes. Only in the bytes form can calculate the checksum.

Source

pub fn get_length(ogg_packet: &[u8]) -> Result<usize>

Retrieve the packet length in bytes

Source

pub fn from_bytes(ogg_packet: &[u8], packet_length: &mut usize) -> Result<Self>

Deserialize the packet

Source

pub fn from_cursor(cursor: &mut Cursor<Vec<u8>>) -> Vec<OggPacket>

Deserialize to multiple packets

Trait Implementations§

Source§

impl Clone for OggPacket

Source§

fn clone(&self) -> OggPacket

Returns a duplicate 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 OggPacket

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for OggPacket

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.