pub trait EbmlSpecification<T>{
// Required methods
fn get_tag_data_type(id: u64) -> Option<TagDataType>;
fn get_path_by_id(id: u64) -> &'static [PathPart];
fn get_unsigned_int_tag(id: u64, data: u64) -> Option<T>;
fn get_signed_int_tag(id: u64, data: i64) -> Option<T>;
fn get_utf8_tag(id: u64, data: String) -> Option<T>;
fn get_binary_tag(id: u64, data: &[u8]) -> Option<T>;
fn get_float_tag(id: u64, data: f64) -> Option<T>;
fn get_master_tag(id: u64, data: Master<T>) -> Option<T>;
fn get_raw_tag(id: u64, data: &[u8]) -> T;
// Provided methods
fn get_tag_id(item: &T) -> u64 { ... }
fn get_path_by_tag(item: &T) -> &'static [PathPart] { ... }
}
Expand description
This trait, along with EbmlTag
, should be implemented to define a specification so that EBML can be parsed correctly. Typically implemented on an Enum of tag variants.
Any specification using EBML can take advantage of this library to parse or write binary data. As stated in the docs, TagWriter
needs nothing special if you stick with the write_raw
method, but TagIterator
requires a struct implementing this trait. Custom specification implementations can refer to webm-iterable as an example.
This trait and EbmlTag
are typically implemented simultaneously. They are separate traits as they have primarily different uses - EbmlSpecification
should be brought into scope when dealing with the specification as a whole, whereas EbmlTag
should be brought into scope when dealing with specific tags.
Required Methods§
Sourcefn get_tag_data_type(id: u64) -> Option<TagDataType>
fn get_tag_data_type(id: u64) -> Option<TagDataType>
Pulls the data type for a tag from the spec, based on the tag id.
This function must return None
if the input id is not in the specification. Implementors can reference webm-iterable for an example.
Sourcefn get_path_by_id(id: u64) -> &'static [PathPart]
fn get_path_by_id(id: u64) -> &'static [PathPart]
Gets the schema path of a specific tag.
This function is used to find the schema defined path of a tag. If the tag is a root element, this function should return an empty array.
Sourcefn get_unsigned_int_tag(id: u64, data: u64) -> Option<T>
fn get_unsigned_int_tag(id: u64, data: u64) -> Option<T>
Creates an unsigned integer type tag from the spec.
This function must return None
if the input id is not in the specification or if the input id data type is not TagDataType::UnsignedInt
. Implementors can reference webm-iterable for an example.
Sourcefn get_signed_int_tag(id: u64, data: i64) -> Option<T>
fn get_signed_int_tag(id: u64, data: i64) -> Option<T>
Creates a signed integer type tag from the spec.
This function must return None
if the input id is not in the specification or if the input id data type is not TagDataType::Integer
. Implementors can reference webm-iterable for an example.
Sourcefn get_utf8_tag(id: u64, data: String) -> Option<T>
fn get_utf8_tag(id: u64, data: String) -> Option<T>
Creates a utf8 type tag from the spec.
This function must return None
if the input id is not in the specification or if the input id data type is not TagDataType::Utf8
. Implementors can reference webm-iterable for an example.
Sourcefn get_binary_tag(id: u64, data: &[u8]) -> Option<T>
fn get_binary_tag(id: u64, data: &[u8]) -> Option<T>
Creates a binary type tag from the spec.
This function must return None
if the input id is not in the specification or if the input id data type is not TagDataType::Binary
. Implementors can reference webm-iterable for an example.
Sourcefn get_float_tag(id: u64, data: f64) -> Option<T>
fn get_float_tag(id: u64, data: f64) -> Option<T>
Creates a float type tag from the spec.
This function must return None
if the input id is not in the specification or if the input id data type is not TagDataType::Float
. Implementors can reference webm-iterable for an example.
Sourcefn get_master_tag(id: u64, data: Master<T>) -> Option<T>
fn get_master_tag(id: u64, data: Master<T>) -> Option<T>
Creates a master type tag from the spec.
This function must return None
if the input id is not in the specification or if the input id data type is not TagDataType::Master
. Implementors can reference webm-iterable for an example.
Sourcefn get_raw_tag(id: u64, data: &[u8]) -> T
fn get_raw_tag(id: u64, data: &[u8]) -> T
Creates a tag that does not conform to the spec.
This function should return a “RawTag” variant that contains the tag id and tag data. Tag data should only be retrievable as binary data. Implementors can reference webm-iterable for an example.
Provided Methods§
Sourcefn get_tag_id(item: &T) -> u64
fn get_tag_id(item: &T) -> u64
Gets the id of a specific tag variant.
Default implementation uses the EbmlTag
implementation. Implementors can reference webm-iterable for an example.
Sourcefn get_path_by_tag(item: &T) -> &'static [PathPart]
fn get_path_by_tag(item: &T) -> &'static [PathPart]
Gets the schema path of a specific tag variant.
Default implementation uses Self::get_path_by_id
after obtaining the tag id using the EbmlTag
implementation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.