-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_modifier_skip.rs
61 lines (46 loc) · 1.6 KB
/
test_modifier_skip.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use jbytes_derive::{ByteDecode, ByteEncode};
use jbytes::prelude::*;
#[derive(Debug, PartialEq, Eq, ByteDecode, ByteEncode)]
pub struct SkipExample {
#[jbytes(skip)]
pub version: u16,
pub command: u16,
}
#[test]
fn test_modifier_skip_example() {
let bytes = Bytes::new(b"\x00\x01");
assert_eq!(SkipExample::decode(&bytes).unwrap(), SkipExample { version: 0, command: 1 });
assert_eq!(bytes.remaining_len(), 0);
assert_eq!(*jbytes::encode(SkipExample { version: 0, command: 1 }).unwrap(), b"\x00\x01");
}
#[derive(Debug, PartialEq, Eq, ByteDecode, ByteEncode)]
pub struct SkipExample2 {
#[jbytes(skip_encode, skip_decode)]
pub version: u16,
pub command: u16,
}
#[test]
fn test_modifier_skip_example2() {
let bytes = Bytes::new(b"\x00\x01");
assert_eq!(SkipExample2::decode(&bytes).unwrap(), SkipExample2 { version: 0, command: 1 });
assert_eq!(bytes.remaining_len(), 0);
assert_eq!(*jbytes::encode(SkipExample2 { version: 0, command: 1 }).unwrap(), b"\x00\x01");
}
#[derive(Debug, PartialEq, Eq, ByteDecode, ByteEncode)]
pub enum SkipEnumExample {
#[jbytes(branch_value=1)]
Read {
#[jbytes(skip)]
version: u16,
command: u16,
},
#[jbytes(branch_default)]
Unknown
}
#[test]
fn test_modifier_skip_enum_example() {
let bytes = Bytes::new(b"\x01\x00\x01");
assert_eq!(SkipEnumExample::decode(&bytes).unwrap(), SkipEnumExample::Read { version: 0, command: 1 });
assert_eq!(bytes.remaining_len(), 0);
assert_eq!(*jbytes::encode(SkipEnumExample::Read { version: 0, command: 1 }).unwrap(), b"\x01\x00\x01");
}