-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtlv.vest
More file actions
76 lines (66 loc) · 1.14 KB
/
Copy pathtlv.vest
File metadata and controls
76 lines (66 loc) · 1.14 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
msg1 = {
a: u8,
b: u16,
c: [u8; 3],
data: Tail,
}
msg2 = {
a: u8,
b: u16,
c: u32,
}
msg3 = {
data: [u8; 6],
}
// will produce `Either::Left(1u8)`, etc.
// msg_type = choose {
// MSG1 { const msg1: u8 = 1, },
// MSG2 { const msg2: u8 = 2, },
// MSG3 { const msg3: u8 = 3, },
// }
// will have the same effect as `Int::<u8>`, except that the enum variants can be used as aliases
// for the integer values
msg_type = enum {
Msg1 = 1,
Msg2 = 2,
Msg3 = 3,
}
// const MSG_TYPE: choose {
// MSG1(u8 = 1),
// MSG2(u8 = 2),
// MSG3(u8 = 3),
// }
// const MSG1: u8 = 1
// const MSG2: u8 = 2
// const MSG3: u8 = 3
msg = {
@tag: msg_type,
@len: u16,
content: [u8; @len] >>= choose(@tag) {
Msg1 => msg1,
Msg2 => msg2,
Msg3 => msg3,
},
}
msg_param(@tag: msg_type) = choose(@tag) {
Msg1 => msg1,
Msg2 => msg2,
Msg3 => msg3,
}
// corresponds to the following Rust type:
// enum Msg {
// Msg1(msg1),
// Msg2(msg2),
// Msg3(msg3),
// }
// same as above
msg_alt = {
@tag: u8,
@len: u16,
content: [u8; @len] >>= choose(@tag) {
1 => msg1,
2 => msg2,
3 => msg3,
_ => [u8; @len],
},
}