1 Star 11 Fork 4

JanKinCai / jppe-rs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_modifier_branch_option.rs 958 Bytes
一键复制 编辑 原始数据 按行查看 历史
use jppe_derive::{ByteEncode, ByteDecode};
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
struct BranchOptionExample {
pub flags: bool,
#[jppe(if_expr="flags")]
pub cmd: Option<u16>,
#[jppe(branch_option="cmd")]
pub body: BranchOptionExampleBody,
}
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
enum BranchOptionExampleBody {
#[jppe(branch_value=0x0001)]
Read {
a: u8,
b: u16,
},
#[jppe(branch_value=0x0002)]
Write {
a: u8,
b: u16,
},
#[jppe(branch_default)]
Unknown,
}
#[test]
fn test_modifier_branch_option() {
let (input, value) = jppe::decode::<BranchOptionExample>(b"\x01\x00\x01\x02\x00\x03").unwrap();
assert_eq!(value, BranchOptionExample { flags: true, cmd: Some(1), body: BranchOptionExampleBody::Read { a: 2, b: 3 } });
assert_eq!(input.is_empty(), true);
assert_eq!(jppe::encode(value), b"\x01\x00\x01\x02\x00\x03");
}
Rust
1
https://gitee.com/JanKinCai/jppe-rs.git
git@gitee.com:JanKinCai/jppe-rs.git
JanKinCai
jppe-rs
jppe-rs
master

搜索帮助