MarkedData

Struct MarkedData 

Source
pub struct MarkedData<'a> {
    pub marker: u8,
    pub data: &'a [u8],
}
Expand description

Parses a standard dynamically-sized chuck from a JPEG file.

Not all markers in JPEG are followed by data, or even a data size. This only represents those markers that have data. Markers that are not followed by data include “Start of Image”, “End of Image”, and “Reset”.

One marker, the “Start of Segment” marker, is followed by data, but then that data is also followed by entropy-encoded data that is unmarked.

Fields§

§marker: u8§data: &'a [u8]

Implementations§

Source§

impl<'a> MarkedData<'a>

Source

pub fn parser<I>( marker: impl Parser<Input = I, Output = u8> + 'a, ) -> impl Parser<Input = I, Output = MarkedData<'a>> + 'a
where I: RangeStream<Item = u8, Range = &'a [u8]> + 'a, I::Error: ParseError<I::Item, I::Range, I::Position>,

Parses out marked data from a JPEG file with marker parser marker.

use exifsd::*;
use combine::*;

// 0xFF - Start of marker
// 0x11 - Marker
// 0x00, 0x03 - Length of data including length (so data length 1)
// 0x01 - The data
let input = &[0xFF, 0x11, 0x00, 0x03, 0x01][..];
let result = MarkedData::parser(token(0x11)).parse(input);
let expected = MarkedData { marker: 0x11, data: &[0x01] };
assert_eq!(result, Ok((expected, &[][..])));

// Length cannot be less than 2 (here it is 1).
MarkedData::parser(any()).parse(&[0xFF, 0x11, 0x00, 0x01][..]).unwrap_err();
Source

pub fn write<W: WriteBytesExt>(&self, writer: &mut W) -> Result<()>

Writes the binary representation of the MarkedData out to a file.

use exifsd::*;
use combine::*;

let input = &[0xFF, 0x11, 0x00, 0x03, 0x01][..];
let marked_data = MarkedData::parser(token(0x11)).parse(input).unwrap().0;
let mut written = vec![];
marked_data.write(&mut written).unwrap();
assert_eq!(input, &written[..]);

Trait Implementations§

Source§

impl<'a> Clone for MarkedData<'a>

Source§

fn clone(&self) -> MarkedData<'a>

Returns a duplicate 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<'a> Debug for MarkedData<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for MarkedData<'a>

Source§

fn eq(&self, other: &MarkedData<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for MarkedData<'a>

Source§

impl<'a> Eq for MarkedData<'a>

Source§

impl<'a> StructuralPartialEq for MarkedData<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for MarkedData<'a>

§

impl<'a> RefUnwindSafe for MarkedData<'a>

§

impl<'a> Send for MarkedData<'a>

§

impl<'a> Sync for MarkedData<'a>

§

impl<'a> Unpin for MarkedData<'a>

§

impl<'a> UnwindSafe for MarkedData<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

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

Source§

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.