1 Star 11 Fork 4

JanKinCai / jppe-rs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_type_hashset.rs 872 Bytes
一键复制 编辑 原始数据 按行查看 历史
use std::collections::HashSet;
#[allow(unused_imports)]
use jppe_derive::{ByteEncode, ByteDecode};
#[allow(unused_imports)]
use jppe::{ByteDecode, ByteEncode};
#[derive(Debug, PartialEq, Eq, ByteDecode)]
pub struct HashSetExample {
pub count: u8,
#[jppe(count="count")] // or #[jppe(count=3)]
pub hashset: HashSet<u16>,
}
#[test]
fn test_type_hashmap() {
let (input, value) = HashSetExample::decode(b"\x03\x00\x01\x00\x02\x00\x02", None, None).unwrap();
assert_eq!(value, HashSetExample { count: 3, hashset: HashSet::from([1, 2]) });
assert_eq!(input.is_empty(), true);
// Encode is dangerous function with out-of-order and coding problems.
// count=3 only have 2 elements.
// let mut buf = Vec::new();
// value.encode(&mut buf, None, None);
// assert!(buf == b"\x03\x00\x01\x00\x02" || buf == b"\x03\x00\x02\x00\x01");
}
Rust
1
https://gitee.com/JanKinCai/jppe-rs.git
git@gitee.com:JanKinCai/jppe-rs.git
JanKinCai
jppe-rs
jppe-rs
master

搜索帮助