Struct cea708_types::Service

source ·
pub struct Service { /* private fields */ }
Expand description

A Service in a DTVCCPacket

As specified in CEA-708, there can be a maximum of 63 services. Service 1 is the primary caption service and Service 2 is the secondary caption service. All other services are undefined.

Implementations§

source§

impl Service

source

pub fn new(service_no: u8) -> Self

Create a new Service

§Panics
  • if number >= 64
source

pub fn number(&self) -> u8

Returns the number of this Service

§Examples
let mut service = Service::new(1);
assert_eq!(service.number(), 1);
source

pub fn free_space(&self) -> usize

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

§Examples
let service = Service::new(1);
assert_eq!(service.free_space(), 31);
source

pub fn len(&self) -> usize

The length in bytes of this Service block

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

pub fn push_code(&mut self, code: &Code) -> Result<(), WriterError>

Push a tables::Code to the end of this Service

§Errors
§Examples
let mut service = Service::new(1);
service.push_code(&Code::LatinCapitalA).unwrap();
source

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

Parse a Service from a set of bytes

§Errors
§Examples
let bytes = [0x21, 0x41];
let service = Service::parse(&bytes).unwrap();
assert_eq!(service.number(), 1);
assert_eq!(service.codes()[0], Code::LatinCapitalA);
source

pub fn codes(&self) -> &[Code]

The ordered list of tables::Codes present in this Service block

§Examples
let mut service = Service::new(1);
service.push_code(&Code::LatinCapitalA).unwrap();
let codes = service.codes();
assert_eq!(codes, [Code::LatinCapitalA]);
source

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

Write the Service block to a byte stream

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

Trait Implementations§

source§

impl Clone for Service

source§

fn clone(&self) -> Service

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 Service

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.