1 Star 0 Fork 4

连建锋 / jppe-rs

forked from JanKinCai / jppe-rs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_modifier_variable_name.rs 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
#![feature(let_chains)]
use jppe_derive::ByteDecode;
#[derive(Debug, PartialEq, Eq, ByteDecode)]
pub struct VariableExample {
pub cmd: u8,
#[jppe(variable_name="length")]
pub length: u8,
pub body: VariableExampleBody,
#[jppe(branch="cmd")]
pub enum_body: VariableExampleEnumBody,
}
#[derive(Debug, PartialEq, Eq, ByteDecode)]
#[jppe(get_variable_name="length")]
pub struct VariableExampleBody {
#[jppe(length="length")]
value: String,
}
#[derive(Debug, PartialEq, Eq, ByteDecode)]
#[jppe(get_variable_name="length")]
#[repr(u8)]
pub enum VariableExampleEnumBody {
Read {
#[jppe(length="length")]
value: String,
} = 1,
Write {
#[jppe(length="length")]
value: String,
} = 2,
#[jppe(branch_default)]
Unknown,
}
#[cfg(test)]
mod tests {
use jppe::ByteDecode;
use super::*;
#[test]
fn test_modifier_variable_name() {
let input = b"\x01\x02abcd";
let (input, value) = VariableExample::decode(input, None, None).unwrap();
assert_eq!(value, VariableExample {
cmd: 1,
length: 2,
body: VariableExampleBody { value: "ab".to_string() },
enum_body: VariableExampleEnumBody::Read { value: "cd".to_string() },
});
assert_eq!(input.is_empty(), true);
// Because the value is not stored in the new type, it cannot encode.
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/lian_jianfeng/jppe-rs.git
git@gitee.com:lian_jianfeng/jppe-rs.git
lian_jianfeng
jppe-rs
jppe-rs
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891