1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
//! [Format Identifier](https://smpte-ra.org/registered-mpeg-ts-ids) value on record with the
//! [SMPTE Registration Authority](https://smpte-ra.org/) for use in _MPEG Transport Stream_ data.
//!
//! (This create is automatically generated from a
//! [mirror of the SMPTE-RA data](https://github.com/dholroyd/smptera-format-identifiers)
//! by code in the
//! [smptera-format-identifiers-rust](https://github.com/dholroyd/smptera-format-identifiers-rust)
//! project.)
//!
//! The simple wrapper type [`FormatIdentifier`](struct.FormatIdentifier.html) defines a constant
//! for each _format identifier_ in the SMPTE-RA data,
//!
//! ```rust
//! # use smptera_format_identifiers_rust::FormatIdentifier;
//! use std::io::stdout;
//! println!("{:?}", FormatIdentifier::AC_3);
//! // prints: FormatIdentifier(FourCC{AC-3})
//! ```
//!
//! ## Usage
//!
//! Create from a slice,
//!
//! ```rust
//! # use smptera_format_identifiers_rust::FormatIdentifier;
//! let descriptor_data = b"\x05\x04CUEI";
//! let id = FormatIdentifier::from(&descriptor_data[2..6]);
//! assert_eq!(id, FormatIdentifier::CUEI);
//! ```
//!
//! Wrap an existing FourCC value,
//!
//! ```rust
//! # use smptera_format_identifiers_rust::FormatIdentifier;
//! # use four_cc::FourCC;
//! let fcc = FourCC(*b"CUEI");
//! let id = FormatIdentifier(fcc);
//! assert_eq!(id, FormatIdentifier::CUEI);
//! ```
//!
//! Use provided constants in matches,
//!
//! ```rust
//! # use smptera_format_identifiers_rust::FormatIdentifier;
//! # let descriptor_data = b"\x05\x04CUEI";
//! match FormatIdentifier::from(&descriptor_data[2..6]) {
//! FormatIdentifier::CUEI => println!("SCTE-35 suspected"),
//! FormatIdentifier::KLVA => println!("SMPTE RP 217-2001 KLV Packets?"),
//! other_id => println!("Some other kinda stuff: {:?}", other_id),
//! }
//! ```
//!
//! Write bytes values,
//!
//! ```rust
//! # use smptera_format_identifiers_rust::FormatIdentifier;
//! # use std::io::{Cursor, Write};
//! let mut data = vec![];
//! let mut io = Cursor::new(data);
//!
//! let id = &FormatIdentifier::ID3;
//! io.write(id.into())
//! .expect("write failed");
//!
//! assert_eq!(io.into_inner(), [b'I', b'D', b'3', b' ']);
//! ```
#![forbid(unsafe_code)]
#![deny(missing_docs)]
use four_cc::FourCC;
/// Identifier for data formats used in MPEG Transport Streams
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct FormatIdentifier(pub FourCC);
impl<'a> From<&'a [u8]> for FormatIdentifier {
fn from(buf: &[u8]) -> Self {
FormatIdentifier(FourCC::from(buf))
}
}
impl<'a> From<&'a FormatIdentifier> for &'a [u8] {
fn from(id: &'a FormatIdentifier) -> Self {
&(id.0).0
}
}
include!("generated.rs");
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn smoke() {
assert_eq!(FormatIdentifier::CUEI, FormatIdentifier::from(&b"CUEI"[..]));
assert_eq!(&b"CUEI"[..], <&[u8]>::from(&FormatIdentifier::CUEI));
}
}