pub struct DTVCCPacket { /* private fields */ }
Expand description

A packet in the cc_data bitstream

Implementations§

source§

impl DTVCCPacket

source

pub fn new(seq_no: u8) -> Self

Create a new DTVCCPacket with the specified sequence number.

§Panics
  • If seq_no >= 4
source

pub fn sequence_no(&self) -> u8

The sequence number of the DTVCCPacket

§Examples
let packet = DTVCCPacket::new(2);
assert_eq!(2, packet.sequence_no());
source

pub fn free_space(&self) -> usize

The amount of free space (in bytes) that can by placed inside this DTVCCPacket

source

pub fn len(&self) -> usize

The number of bytes this DTVCCPacket will use when written to a byte stream.

§Examples
let mut packet = DTVCCPacket::new(2);
assert_eq!(0, packet.len());
let mut service = Service::new(1);
service.push_code(&Code::LatinCapitalA).unwrap();
packet.push_service(service);
assert_eq!(3, packet.len());
source

pub fn push_service(&mut self, service: Service) -> Result<(), WriterError>

Push a completed service block into this DTVCCPacket

§Examples
let mut packet = DTVCCPacket::new(2);
assert_eq!(0, packet.len());
let mut service = Service::new(1);
service.push_code(&Code::LatinCapitalA).unwrap();
packet.push_service(service);
assert_eq!(3, packet.len());
source

pub fn parse(data: &[u8]) -> Result<Self, ParserError>

Parse bytes into a DTVCCPacket

Will return ParserError::LengthMismatch if the data is shorter than the length advertised in the DTVCCPacket header.

Will return errors from Service::parse if parsing the contained Services fails.

§Examples
let data = [0x02, 0x21, 0x41, 0x00];
let packet = DTVCCPacket::parse(&data).unwrap();
assert_eq!(3, packet.len());
assert_eq!(0, packet.sequence_no());
source

pub fn services(&self) -> &[Service]

Returns a copy of the Services for this DTVCCPacket

source

pub fn write<W: Write>(&self, w: &mut W) -> Result<(), Error>

Write the DTVCCPacket to a byte stream

§Examples
let mut packet = DTVCCPacket::new(2);
let mut service = Service::new(1);
service.push_code(&Code::LatinCapitalA).unwrap();
packet.push_service(service);
let mut written = vec![];
packet.write(&mut written);
let expected = [0x82, 0x21, 0x41, 0x00];
assert_eq!(written, expected);

Trait Implementations§

source§

impl Debug for DTVCCPacket

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