代码拉取完成,页面将自动刷新
同步操作将从 JanKinCai/jppe-rs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#![feature(let_chains)]
use jppe::{BorrowByteEncode, BorrowByteDecode, FieldAttrModifiers};
// use jppe::prelude::*;
use jppe_derive::{BorrowByteDecode, BorrowByteEncode};
#[derive(Debug, PartialEq, Eq, BorrowByteDecode, BorrowByteEncode)]
pub struct StructLengthExample1<'a> {
#[jppe(length=3)]
pub a: u32,
#[jppe(length=1)]
pub b: &'a [u8],
#[jppe(length=1)]
pub c: Vec<u8,>
}
#[test]
fn test_struct_length_example1() {
let value = StructLengthExample1 { a: 1, b: &[1], c: vec![1]};
let mut buf = vec![];
value.encode(&mut buf, None, None);
assert_eq!(buf, vec![0x00, 0x00, 0x01, 0x01, 0x01]);
let (input, value2) = StructLengthExample1::decode(&[0x00, 0x00, 0x01, 0x01, 0x01], None, None).unwrap();
assert_eq!(value2, value);
assert_eq!(input.is_empty(), true);
}
#[derive(Debug, PartialEq, Eq, BorrowByteDecode, BorrowByteEncode)]
pub struct StructLengthExample2<'a> {
pub a: u8,
#[jppe(length="a")]
pub b: &'a [u8],
pub c: u8,
#[jppe(length="c - 1")]
pub d: &'a [u8],
}
#[test]
fn test_struct_length_example2() {
let input = vec![0x01, 0x01, 0x02, 0x01];
let value = StructLengthExample2 { a: 1, b: &[1], c: 2, d: &[1]};
let mut buf = vec![];
value.encode(&mut buf, None, None);
assert_eq!(buf, input);
let (input, value2) = StructLengthExample2::decode(&input, None, None).unwrap();
assert_eq!(value2, value);
assert_eq!(input.is_empty(), true);
}
#[derive(Debug, Default, PartialEq, Eq, BorrowByteDecode, BorrowByteEncode)]
pub enum EnumLengthExample1<'a> {
Jkc {
a: u8,
#[jppe(length="a")]
b: &'a [u8],
c: u8,
// #[jppe(length="c - 1")]
d: &'a [u8],
},
#[jppe(branch_default)]
#[default]
Unknown
}
#[test]
fn test_struct_length_example3() {
let input = vec![0x01, 0x01, 0x02, 0x01];
let value = EnumLengthExample1::Jkc { a: 1, b: &[1], c: 2, d: &[1]} ;
let mut buf = vec![];
value.encode(&mut buf, None, None);
assert_eq!(buf, input);
let fattr = FieldAttrModifiers { branch: Some(0), ..Default::default() };
let (input, value2) = EnumLengthExample1::decode(&input, None, Some(&fattr)).unwrap();
assert_eq!(value2, value);
assert_eq!(input.is_empty(), true);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。