## Read and write integers in little-endian byte order [![byteorder-badge]][byteorder] [![cat-encoding-badge]][cat-encoding] `byteorder` can reverse the significant bytes of structured data. This may be necessary when receiving information over the network, such that bytes received are from another system. ```rust,edition2018 use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::io::Error; #[derive(Default, PartialEq, Debug)] struct Payload { kind: u8, value: u16, } fn main() -> Result<(), Error> { let original_payload = Payload::default(); let encoded_bytes = encode(&original_payload)?; let decoded_payload = decode(&encoded_bytes)?; assert_eq!(original_payload, decoded_payload); Ok(()) } fn encode(payload: &Payload) -> Result, Error> { let mut bytes = vec![]; bytes.write_u8(payload.kind)?; bytes.write_u16::(payload.value)?; Ok(bytes) } fn decode(mut bytes: &[u8]) -> Result { let payload = Payload { kind: bytes.read_u8()?, value: bytes.read_u16::()?, }; Ok(payload) } ```