代码拉取完成,页面将自动刷新
use jppe_derive::{ByteEncode, ByteDecode};
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
struct EnumByteCountExample {
pub version: u8,
#[jppe(byte_count=1)] // Fetches 1 byte mapping enum in advance.
pub body: EnumByteCountBody,
}
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
#[repr(u8)]
enum EnumByteCountBody {
Read {
value: u8,
} = 1,
Write {
address: u8,
}
}
#[test]
fn test_type_enum_byte_count() {
let (input, value) = jppe::decode::<EnumByteCountExample>(b"\x01\x01\x02").unwrap();
assert_eq!(value, EnumByteCountExample { version: 1, body: EnumByteCountBody::Read { value: 2 } });
assert_eq!(input.is_empty(), true);
assert_eq!(jppe::encode(value), b"\x01\x01\x02");
}
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
struct EnumByteCountExample2 {
pub version: u8,
#[jppe(byte_count=2)] // Fetches 2 byte mapping enum in advance.
pub body: EnumByteCountBody2,
}
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
#[repr(u8)]
enum EnumByteCountBody2 {
Read {
value: u8,
} = 1,
Write {
address: u8,
}
}
#[test]
fn test_type_enum_byte_count2() {
let (input, value) = jppe::decode::<EnumByteCountExample2>(b"\x01\x00\x01\x02").unwrap();
assert_eq!(value, EnumByteCountExample2 { version: 1, body: EnumByteCountBody2::Read { value: 2 } });
assert_eq!(input.is_empty(), true);
assert_eq!(jppe::encode(value), b"\x01\x00\x01\x02");
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。