@@ -71,7 +71,7 @@ impl RcxBin {
71
71
72
72
#[ derive( Clone , Debug , PartialEq , Eq ) ]
73
73
pub struct Chunk {
74
- pub ty : u8 ,
74
+ pub ty : ChunkType ,
75
75
pub number : u8 ,
76
76
pub length : u16 ,
77
77
pub data : Vec < u8 > ,
@@ -81,7 +81,7 @@ fn parse_chunk(i: &[u8]) -> IResult<&[u8], Chunk> {
81
81
let read_u16 = nom:: number:: complete:: u16 ( Endianness :: Little ) ;
82
82
let read_u8 = nom:: number:: complete:: u8;
83
83
84
- let ( i, ty) = read_u8 ( i) ?;
84
+ let ( i, ty) = ChunkType :: parse ( i) ?;
85
85
let ( i, number) = read_u8 ( i) ?;
86
86
let ( i, length) = read_u16 ( i) ?;
87
87
let ( i, data) = nom:: bytes:: complete:: take ( length) ( i) ?;
@@ -97,6 +97,36 @@ fn parse_chunk(i: &[u8]) -> IResult<&[u8], Chunk> {
97
97
) )
98
98
}
99
99
100
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
101
+ #[ repr( u8 ) ]
102
+ pub enum ChunkType {
103
+ Task = 0 ,
104
+ SubChunk ,
105
+ Sound ,
106
+ Animation ,
107
+ Count ,
108
+ }
109
+
110
+ impl ChunkType {
111
+ pub fn parse ( i : & [ u8 ] ) -> IResult < & [ u8 ] , Self > {
112
+ let ( i, ty) = nom:: number:: complete:: u8 ( i) ?;
113
+ let ty = match ty {
114
+ 0 => Self :: Task ,
115
+ 1 => Self :: SubChunk ,
116
+ 2 => Self :: Sound ,
117
+ 3 => Self :: Animation ,
118
+ 4 => Self :: Count ,
119
+ _ => {
120
+ return Err ( nom:: Err :: Failure ( nom:: error:: Error {
121
+ input : i,
122
+ code : nom:: error:: ErrorKind :: Verify ,
123
+ } ) ) ;
124
+ }
125
+ } ;
126
+ Ok ( ( i, ty) )
127
+ }
128
+ }
129
+
100
130
#[ derive( Clone , Debug , PartialEq , Eq ) ]
101
131
pub struct Symbol {
102
132
pub ty : u8 ,
@@ -183,7 +213,7 @@ mod test {
183
213
target_type: 0 ,
184
214
reserved: 0 ,
185
215
chunks: vec![ Chunk {
186
- ty: 0 ,
216
+ ty: ChunkType :: Task ,
187
217
number: 0 ,
188
218
length: 20 ,
189
219
data: vec![
0 commit comments