1 Star 13 Fork 4

JanKinCai / jppe-rs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_type_hex.rs 749 Bytes
一键复制 编辑 原始数据 按行查看 历史
use std::str::FromStr;
use jppe::{ByteDecode, ByteEncode};
use jppe::fields::HexString;
use jppe_derive::{ByteDecode, ByteEncode};
#[derive(Debug, PartialEq, Eq, ByteDecode, ByteEncode)]
pub struct HexExample {
pub length: u8,
#[jppe(length="length")]
pub value: HexString,
}
#[test]
fn test_type_hex() {
let (input, value) = HexExample::decode(b"\x09jankincai", None, None).unwrap();
assert_eq!(value.value.to_string(), "6a616e6b696e636169");
assert_eq!(value, HexExample {
length: 9,
value: HexString::from_str("6a616e6b696e636169").unwrap(),
});
assert_eq!(input.is_empty(), true);
let mut buf = Vec::new();
value.encode(&mut buf, None, None);
assert_eq!(buf, b"\x09jankincai");
}
Rust
1
https://gitee.com/JanKinCai/jppe-rs.git
git@gitee.com:JanKinCai/jppe-rs.git
JanKinCai
jppe-rs
jppe-rs
master

搜索帮助