@@ -17,9 +17,9 @@ pub struct Meta {
1717 pub kind : Kind ,
1818}
1919
20+ #[ repr( u8 ) ]
2021#[ derive( Debug , Clone , Copy , PartialEq , Eq , strum:: Display ) ]
2122#[ strum( serialize_all = "lowercase" ) ]
22- #[ repr( u8 ) ]
2323pub enum Dependency {
2424 /// Just the plain name of a package
2525 #[ strum( serialize = "name" ) ]
@@ -50,10 +50,9 @@ pub enum Dependency {
5050
5151 /// An emul32-compatible pkgconfig .pc dependency (lib32/*.pc)
5252 PkgConfig32 ,
53-
54- Unknown = 255 ,
5553}
5654
55+ #[ repr( u8 ) ]
5756#[ derive( Debug , Clone , PartialEq , Eq ) ]
5857pub enum Kind {
5958 Int8 ( i8 ) ,
@@ -67,7 +66,6 @@ pub enum Kind {
6766 String ( String ) ,
6867 Dependency ( Dependency , String ) ,
6968 Provider ( Dependency , String ) ,
70- Unknown ( Vec < u8 > ) ,
7169}
7270
7371impl Kind {
@@ -87,61 +85,58 @@ impl Kind {
8785 Kind :: Dependency ( _, s) => s. len ( ) + 2 ,
8886 // Plus dep size & nul terminator
8987 Kind :: Provider ( _, s) => s. len ( ) + 2 ,
90- Kind :: Unknown ( data) => data. len ( ) ,
9188 }
9289 }
9390}
9491
95- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
9692#[ repr( u16 ) ]
93+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
9794pub enum Tag {
9895 // Name of the package
9996 Name = 1 ,
10097 // Architecture of the package
101- Architecture ,
98+ Architecture = 2 ,
10299 // Version of the package
103- Version ,
100+ Version = 3 ,
104101 // Summary of the package
105- Summary ,
102+ Summary = 4 ,
106103 // Description of the package
107- Description ,
104+ Description = 5 ,
108105 // Homepage for the package
109- Homepage ,
106+ Homepage = 6 ,
110107 // ID for the source package, used for grouping
111- SourceID ,
108+ SourceID = 7 ,
112109 // Runtime dependencies
113- Depends ,
110+ Depends = 8 ,
114111 // Provides some capability or name
115- Provides ,
112+ Provides = 9 ,
116113 // Conflicts with some capability or name
117- Conflicts ,
114+ Conflicts = 10 ,
118115 // Release number for the package
119- Release ,
116+ Release = 11 ,
120117 // SPDX license identifier
121- License ,
118+ License = 12 ,
122119 // Currently recorded build number
123- BuildRelease ,
120+ BuildRelease = 13 ,
124121 // Repository index specific (relative URI)
125- PackageURI ,
122+ PackageURI = 14 ,
126123 // Repository index specific (Package hash)
127- PackageHash ,
124+ PackageHash = 15 ,
128125 // Repository index specific (size on disk)
129- PackageSize ,
126+ PackageSize = 16 ,
130127 // A Build Dependency
131- BuildDepends ,
128+ BuildDepends = 17 ,
132129 // Upstream URI for the source
133- SourceURI ,
130+ SourceURI = 18 ,
134131 // Relative path for the source within the upstream URI
135- SourcePath ,
132+ SourcePath = 19 ,
136133 // Ref/commit of the upstream source
137- SourceRef ,
138-
139- Unknown = u16:: MAX ,
134+ SourceRef = 20 ,
140135}
141136
142137/// Helper to decode a dependency's encoded kind
143- fn decode_dependency ( i : u8 ) -> Dependency {
144- match i {
138+ fn decode_dependency ( i : u8 ) -> Result < Dependency , DecodeError > {
139+ let result = match i {
145140 0 => Dependency :: PackageName ,
146141 1 => Dependency :: SharedLibrary ,
147142 2 => Dependency :: PkgConfig ,
@@ -151,8 +146,9 @@ fn decode_dependency(i: u8) -> Dependency {
151146 6 => Dependency :: Binary ,
152147 7 => Dependency :: SystemBinary ,
153148 8 => Dependency :: PkgConfig32 ,
154- _ => Dependency :: Unknown ,
155- }
149+ _ => return Err ( DecodeError :: UnknownDependency ( i) ) ,
150+ } ;
151+ Ok ( result)
156152}
157153
158154impl Record for Meta {
@@ -180,7 +176,7 @@ impl Record for Meta {
180176 18 => Tag :: SourceURI ,
181177 19 => Tag :: SourcePath ,
182178 20 => Tag :: SourceRef ,
183- _ => Tag :: Unknown ,
179+ t => return Err ( DecodeError :: UnknownMetaTag ( t ) ) ,
184180 } ;
185181
186182 let kind = reader. read_u8 ( ) ?;
@@ -201,15 +197,15 @@ impl Record for Meta {
201197 9 => Kind :: String ( sanitize ( reader. read_string ( length as u64 ) ?) ) ,
202198 10 => Kind :: Dependency (
203199 // DependencyKind u8 subtracted from length
204- decode_dependency ( reader. read_u8 ( ) ?) ,
200+ decode_dependency ( reader. read_u8 ( ) ?) ? ,
205201 sanitize ( reader. read_string ( length as u64 - 1 ) ?) ,
206202 ) ,
207203 11 => Kind :: Provider (
208204 // DependencyKind u8 subtracted from length
209- decode_dependency ( reader. read_u8 ( ) ?) ,
205+ decode_dependency ( reader. read_u8 ( ) ?) ? ,
210206 sanitize ( reader. read_string ( length as u64 - 1 ) ?) ,
211207 ) ,
212- _ => Kind :: Unknown ( reader . read_vec ( length as usize ) ? ) ,
208+ k => return Err ( DecodeError :: UnknownMetaKind ( k ) ) ,
213209 } ;
214210
215211 Ok ( Self { tag, kind } )
@@ -228,7 +224,6 @@ impl Record for Meta {
228224 Kind :: String ( _) => 9 ,
229225 Kind :: Dependency ( _, _) => 10 ,
230226 Kind :: Provider ( _, _) => 11 ,
231- Kind :: Unknown ( _) => 255 ,
232227 } ;
233228
234229 writer. write_u32 ( self . kind . size ( ) as u32 ) ?;
@@ -255,9 +250,6 @@ impl Record for Meta {
255250 writer. write_all ( s. as_bytes ( ) ) ?;
256251 writer. write_u8 ( b'\0' ) ?;
257252 }
258- Kind :: Unknown ( data) => {
259- writer. write_all ( data) ?;
260- }
261253 }
262254
263255 Ok ( ( ) )
0 commit comments