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>
impl<'a> MarkedData<'a>
Sourcepub fn parser<I>(
marker: impl Parser<Input = I, Output = u8> + 'a,
) -> impl Parser<Input = I, Output = MarkedData<'a>> + 'awhere
I: RangeStream<Item = u8, Range = &'a [u8]> + 'a,
I::Error: ParseError<I::Item, I::Range, I::Position>,
pub fn parser<I>(
marker: impl Parser<Input = I, Output = u8> + 'a,
) -> impl Parser<Input = I, Output = MarkedData<'a>> + 'awhere
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();Sourcepub fn write<W: WriteBytesExt>(&self, writer: &mut W) -> Result<()>
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>
impl<'a> Clone for MarkedData<'a>
Source§fn clone(&self) -> MarkedData<'a>
fn clone(&self) -> MarkedData<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for MarkedData<'a>
impl<'a> Debug for MarkedData<'a>
Source§impl<'a> PartialEq for MarkedData<'a>
impl<'a> PartialEq for MarkedData<'a>
impl<'a> Copy for MarkedData<'a>
impl<'a> Eq for MarkedData<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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