Rename EbmlError

This commit is contained in:
Tangent 128 2018-04-04 00:16:35 -04:00
parent ee068bc887
commit 9686eb2713
5 changed files with 23 additions and 23 deletions

View file

@ -9,7 +9,7 @@ pub const DOC_TYPE_ID: u64 = 0x0282;
pub const VOID_ID: u64 = 0x6C; pub const VOID_ID: u64 = 0x6C;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum Error { pub enum EbmlError {
CorruptVarint, CorruptVarint,
UnknownElementId, UnknownElementId,
UnknownElementLength, UnknownElementLength,
@ -48,7 +48,7 @@ pub enum Varint {
/// Returns Ok(None) if more bytes are needed to get a result. /// Returns Ok(None) if more bytes are needed to get a result.
/// Returns Ok(Some((varint, size))) to return a varint value and /// Returns Ok(Some((varint, size))) to return a varint value and
/// the size of the parsed varint. /// the size of the parsed varint.
pub fn decode_varint(bytes: &[u8]) -> Result<Option<(Varint, usize)>, Error> { pub fn decode_varint(bytes: &[u8]) -> Result<Option<(Varint, usize)>, EbmlError> {
let mut value: u64 = 0; let mut value: u64 = 0;
let mut value_length = 1; let mut value_length = 1;
let mut mask: u8 = 0x80; let mut mask: u8 = 0x80;
@ -70,7 +70,7 @@ pub fn decode_varint(bytes: &[u8]) -> Result<Option<(Varint, usize)>, Error> {
} }
if mask == 0 { if mask == 0 {
return Err(Error::CorruptVarint) return Err(EbmlError::CorruptVarint)
} }
// check we have enough data to parse // check we have enough data to parse
@ -97,12 +97,12 @@ pub fn decode_varint(bytes: &[u8]) -> Result<Option<(Varint, usize)>, Error> {
/// Returns Ok(None) if more bytes are needed to get a result. /// Returns Ok(None) if more bytes are needed to get a result.
/// Returns Ok(Some((id, varint, size))) to return the element id, /// Returns Ok(Some((id, varint, size))) to return the element id,
/// the size of the payload, and the size of the parsed header. /// the size of the payload, and the size of the parsed header.
pub fn decode_tag(bytes: &[u8]) -> Result<Option<(u64, Varint, usize)>, Error> { pub fn decode_tag(bytes: &[u8]) -> Result<Option<(u64, Varint, usize)>, EbmlError> {
// parse element ID // parse element ID
match decode_varint(bytes) { match decode_varint(bytes) {
Ok(None) => Ok(None), Ok(None) => Ok(None),
Err(err) => Err(err), Err(err) => Err(err),
Ok(Some((Varint::Unknown, _))) => Err(Error::UnknownElementId), Ok(Some((Varint::Unknown, _))) => Err(EbmlError::UnknownElementId),
Ok(Some((Varint::Value(element_id), id_size))) => { Ok(Some((Varint::Value(element_id), id_size))) => {
// parse payload size // parse payload size
match decode_varint(&bytes[id_size..]) { match decode_varint(&bytes[id_size..]) {
@ -119,9 +119,9 @@ pub fn decode_tag(bytes: &[u8]) -> Result<Option<(u64, Varint, usize)>, Error> {
} }
} }
pub fn decode_uint(bytes: &[u8]) -> Result<u64, Error> { pub fn decode_uint(bytes: &[u8]) -> Result<u64, EbmlError> {
if bytes.len() < 1 || bytes.len() > 8 { if bytes.len() < 1 || bytes.len() > 8 {
return Err(Error::CorruptPayload); return Err(EbmlError::CorruptPayload);
} }
Ok(BigEndian::read_uint(bytes, bytes.len())) Ok(BigEndian::read_uint(bytes, bytes.len()))
@ -225,11 +225,11 @@ pub trait FromEbml<'a>: Sized {
/// Given an element's ID and its binary payload, if any, construct a suitable /// Given an element's ID and its binary payload, if any, construct a suitable
/// instance of this type to represent the event. The instance may contain /// instance of this type to represent the event. The instance may contain
/// references into the given buffer. /// references into the given buffer.
fn decode(element_id: u64, bytes: &'a[u8]) -> Result<Self, Error>; fn decode(element_id: u64, bytes: &'a[u8]) -> Result<Self, EbmlError>;
/// Check if enough space exists in the given buffer for decode_element() to /// Check if enough space exists in the given buffer for decode_element() to
/// be successful; parsing errors will be returned eagerly. /// be successful; parsing errors will be returned eagerly.
fn check_space(bytes: &[u8]) -> Result<Option<usize>, Error> { fn check_space(bytes: &[u8]) -> Result<Option<usize>, EbmlError> {
match decode_tag(bytes) { match decode_tag(bytes) {
Ok(None) => Ok(None), Ok(None) => Ok(None),
Err(err) => Err(err), Err(err) => Err(err),
@ -238,7 +238,7 @@ pub trait FromEbml<'a>: Sized {
let payload_size = match (should_unwrap, payload_size_tag) { let payload_size = match (should_unwrap, payload_size_tag) {
(true, _) => 0, (true, _) => 0,
(false, Varint::Unknown) => return Err(Error::UnknownElementLength), (false, Varint::Unknown) => return Err(EbmlError::UnknownElementLength),
(false, Varint::Value(size)) => size as usize (false, Varint::Value(size)) => size as usize
}; };
@ -254,7 +254,7 @@ pub trait FromEbml<'a>: Sized {
} }
/// Attempt to construct an instance of this type from the given byte slice /// Attempt to construct an instance of this type from the given byte slice
fn decode_element(bytes: &'a[u8]) -> Result<Option<(Self, usize)>, Error> { fn decode_element(bytes: &'a[u8]) -> Result<Option<(Self, usize)>, EbmlError> {
match decode_tag(bytes) { match decode_tag(bytes) {
Ok(None) => Ok(None), Ok(None) => Ok(None),
Err(err) => Err(err), Err(err) => Err(err),
@ -263,7 +263,7 @@ pub trait FromEbml<'a>: Sized {
let payload_size = match (should_unwrap, payload_size_tag) { let payload_size = match (should_unwrap, payload_size_tag) {
(true, _) => 0, (true, _) => 0,
(false, Varint::Unknown) => return Err(Error::UnknownElementLength), (false, Varint::Unknown) => return Err(EbmlError::UnknownElementLength),
(false, Varint::Value(size)) => size as usize (false, Varint::Value(size)) => size as usize
}; };
@ -291,7 +291,7 @@ pub trait EbmlEventSource {
mod tests { mod tests {
use bytes::{BytesMut}; use bytes::{BytesMut};
use ebml::*; use ebml::*;
use ebml::Error::{CorruptVarint, UnknownElementId}; use ebml::EbmlError::{CorruptVarint, UnknownElementId};
use ebml::Varint::{Unknown, Value}; use ebml::Varint::{Unknown, Value};
use std::io::Cursor; use std::io::Cursor;
use tests::TEST_FILE; use tests::TEST_FILE;
@ -414,8 +414,8 @@ mod tests {
#[test] #[test]
fn bad_uints() { fn bad_uints() {
assert_eq!(decode_uint(&[]), Err(Error::CorruptPayload)); assert_eq!(decode_uint(&[]), Err(EbmlError::CorruptPayload));
assert_eq!(decode_uint(&[0; 9]), Err(Error::CorruptPayload)); assert_eq!(decode_uint(&[0; 9]), Err(EbmlError::CorruptPayload));
} }
#[test] #[test]
@ -441,7 +441,7 @@ mod tests {
} }
} }
fn decode(element_id: u64, bytes: &'a[u8]) -> Result<GenericElement, Error> { fn decode(element_id: u64, bytes: &'a[u8]) -> Result<GenericElement, EbmlError> {
match element_id { match element_id {
_ => Ok(GenericElement(element_id, bytes.len())) _ => Ok(GenericElement(element_id, bytes.len()))
} }

View file

@ -1,5 +1,5 @@
use futures::Async; use futures::Async;
use ebml::Error as EbmlError; use ebml::EbmlError;
use ebml::EbmlEventSource; use ebml::EbmlEventSource;
use ebml::FromEbml; use ebml::FromEbml;
use webm::WebmElement; use webm::WebmElement;

View file

@ -9,7 +9,7 @@ pub mod webm_stream;
pub mod timecode_fixer; pub mod timecode_fixer;
pub mod webm; pub mod webm;
pub use ebml::{Error, FromEbml}; pub use ebml::{EbmlError, FromEbml};
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -49,7 +49,7 @@ impl<'b> FromEbml<'b> for WebmElement<'b> {
} }
} }
fn decode(element_id: u64, bytes: &'b[u8]) -> Result<WebmElement<'b>, Error> { fn decode(element_id: u64, bytes: &'b[u8]) -> Result<WebmElement<'b>, EbmlError> {
match element_id { match element_id {
EBML_HEAD_ID => Ok(WebmElement::EbmlHead), EBML_HEAD_ID => Ok(WebmElement::EbmlHead),
VOID_ID => Ok(WebmElement::Void), VOID_ID => Ok(WebmElement::Void),
@ -66,11 +66,11 @@ impl<'b> FromEbml<'b> for WebmElement<'b> {
} }
} }
fn decode_simple_block(bytes: &[u8]) -> Result<WebmElement, Error> { fn decode_simple_block(bytes: &[u8]) -> Result<WebmElement, EbmlError> {
if let Ok(Some((Varint::Value(track), track_field_len))) = decode_varint(bytes) { if let Ok(Some((Varint::Value(track), track_field_len))) = decode_varint(bytes) {
let header_len = track_field_len + 2 + 1; let header_len = track_field_len + 2 + 1;
if bytes.len() < header_len { if bytes.len() < header_len {
return Err(Error::CorruptPayload); return Err(EbmlError::CorruptPayload);
} }
let timecode = BigEndian::read_i16(&bytes[track_field_len..]); let timecode = BigEndian::read_i16(&bytes[track_field_len..]);
let flags = bytes[track_field_len + 2]; let flags = bytes[track_field_len + 2];
@ -81,7 +81,7 @@ fn decode_simple_block(bytes: &[u8]) -> Result<WebmElement, Error> {
data: &bytes[header_len..], data: &bytes[header_len..],
})) }))
} else { } else {
return Err(Error::CorruptPayload); return Err(EbmlError::CorruptPayload);
} }
} }

View file

@ -6,7 +6,7 @@ use futures::stream::Stream;
use ebml::*; use ebml::*;
pub enum ParsingError<E> { pub enum ParsingError<E> {
EbmlError(::ebml::Error), EbmlError(EbmlError),
OtherError(E) OtherError(E)
} }