Expand description
use jbytes::{ByteEncode, ByteDecode};
use jbytes_derive::{ByteEncode, ByteDecode};
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
pub struct SimpleExample {
pub length: u16,
#[jbytes(length="length")]
pub value: String,
pub cmd: u8,
#[jbytes(branch="cmd")]
pub body: SimpleExampleBody,
}
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
pub enum SimpleExampleBody {
#[jbytes(branch_value=1)]
Read {
address: u8,
},
Write {
address: u8,
value: [u8; 3],
},
#[jbytes(branch_default)]
Unknown,
}
fn main() {
let input = b"\x00\x03\x31\x32\x33\x01\x05";
let value: SimpleExample = jbytes::decode(input).unwrap();
assert_eq!(value, SimpleExample { length: 3, value: "123".to_string(), cmd: 1, body: SimpleExampleBody::Read { address: 5 } });
assert_eq!(*jbytes::encode(value).unwrap(), input);
}Re-exports§
pub use buffer::Buffer;pub use bytes::Bytes;pub use bytes::ToBytes;pub use buf_mut_traits::BufReadMut;pub use buf_mut_traits::BufWriteMut;pub use buf_traits::BufRead;pub use buf_traits::BufWrite;pub use errors::JResult;pub use errors::ErrorKind;pub use errors::make_error;pub use modifiers::ContainerAttrModifiers;pub use modifiers::FieldAttrModifiers;pub use modifiers::get_byteorder;pub use byteorder::ByteOrder;pub use decode::ByteDecode;pub use decode::BorrowByteDecode;pub use encode::ByteEncode;pub use encode::BorrowByteEncode;
Modules§
Macros§
Functions§
- decode
- This is a decode function of byte stream.
- decode_
borrow - This is a decode function of byte stream.
- decode_
borrow2 - encode
- This is a encode function of byte stream.
- encode_
borrow - This is a encode function of byte stream.