Crate jppe

Source
Expand description
use jppe::{ByteEncode, ByteDecode};
use jppe_derive::{ByteEncode, ByteDecode};


#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
pub struct SimpleExample {
    pub length: u16,
    #[jppe(length="length")]
    pub value: String,
    pub cmd: u8,
    #[jppe(branch="cmd")]
    pub body: SimpleExampleBody,
}
 
 
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
#[repr(u8)]
pub enum SimpleExampleBody {
    Read {
        address: u8,
    } = 1,
    Write {
        address: u8,
        value: [u8; 3],
    },
    #[jppe(enum_default)]
    Unknown, 
}
 
 
fn main() {
    let input = b"\x00\x03\x31\x32\x33\x01\x05";
    let (input_remain, value) = jppe::decode::<SimpleExample>(input).unwrap();
    assert_eq!(value, SimpleExample { length: 3, value: "123".to_string(), cmd: 1, body: SimpleExampleBody::Read { address: 5 } });
    assert_eq!(input_remain.is_empty(), true);
    assert_eq!(jppe::encode(value), input);
}

Modules§

errors
fields
prelude

Structs§

ContainerAttrModifiers
Error
FieldAttrModifiers

Enums§

ByteOrder
ErrorKind
ModifierValue

Traits§

BorrowByteDecode
BorrowByteEncode
ByteDecode
ByteEncode
InputTrait
ParseError

Functions§

decode
Decode byte stream
decode_borrow
Decode byte stream
encode
Encode byte stream
encode_borrow
Encode byte stream
get_byteorder
input_take
int_to_vec
make_error
parse_subsequence
parse_subsequences
parse_u128
parse_usize

Type Aliases§

JResult

Derive Macros§

ThisError