1 Star 12 Fork 4

JanKinCai / jppe-rs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_modifier_byte_count.rs 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
use std::str::FromStr;
use jppe_derive::{ByteEncode, ByteDecode};
use jppe::prelude::HexString;
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
pub struct ByteCountExample {
#[jppe(byte_count=2)] // Fetches 2 byte mapping length in advance.
pub value: String,
}
#[test]
fn test_modifier_byte_count() {
let (input, value) = jppe::decode::<ByteCountExample>(b"\x00\x03\x31\x32\x33").unwrap();
assert_eq!(value, ByteCountExample { value: "123".to_string() });
assert_eq!(input.is_empty(), true);
assert_eq!(jppe::encode(value), b"\x00\x03\x31\x32\x33");
}
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
pub struct ByteCountExample2 {
#[jppe(byte_count=2)] // Fetches 2 byte mapping length in advance.
pub value: HexString,
}
#[test]
fn test_modifier_byte_count2() {
let (input, value) = jppe::decode::<ByteCountExample2>(b"\x00\x03\x31\x32\x33").unwrap();
assert_eq!(value, ByteCountExample2 { value: HexString::from_str("313233").unwrap() });
assert_eq!(input.is_empty(), true);
assert_eq!(jppe::encode(value), b"\x00\x03\x31\x32\x33");
}
Rust
1
https://gitee.com/JanKinCai/jppe-rs.git
git@gitee.com:JanKinCai/jppe-rs.git
JanKinCai
jppe-rs
jppe-rs
master

搜索帮助