Macro nom::i16[][src]

macro_rules! i16 {
    ($i:expr, $e:expr) => { ... };
}

if the parameter is nom::Endianness::Big, parse a big endian i16 integer, otherwise a little endian i16 integer

use nom::number::Endianness;

named!(be<i16>, i16!(Endianness::Big));

assert_eq!(be(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0001)));
assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));

named!(le<i16>, i16!(Endianness::Little));

assert_eq!(le(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0100)));
assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));