1 Star 13 Fork 4

JanKinCai / jppe-rs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_modifier_if_expr.rs 783 Bytes
一键复制 编辑 原始数据 按行查看 历史
use jppe::{ByteDecode, ByteEncode};
use jppe_derive::{ByteDecode, ByteEncode};
#[derive(Debug, PartialEq, Eq, ByteDecode, ByteEncode)]
pub struct OptionExample {
pub flags: bool,
#[jppe(if_expr="flags == true")]
pub value: Option<u16>,
}
#[test]
fn test_modifier_if_expr() {
let (input, value) = OptionExample::decode(b"\x00\x31", None, None).unwrap();
assert_eq!(value, OptionExample { flags: false, value: None });
assert_eq!(input, b"\x31");
let (input, value) = OptionExample::decode(b"\x01\x00\x31", None, None).unwrap();
assert_eq!(value, OptionExample { flags: true, value: Some(0x31) });
assert_eq!(input.is_empty(), true);
let mut buf = Vec::new();
value.encode(&mut buf, None, None);
assert_eq!(buf, b"\x01\x00\x31");
}
Rust
1
https://gitee.com/JanKinCai/jppe-rs.git
git@gitee.com:JanKinCai/jppe-rs.git
JanKinCai
jppe-rs
jppe-rs
master

搜索帮助