@@ -36,8 +36,6 @@ pub enum Id {
36
36
V1 ( [ u8 ; 18 ] ) ,
37
37
}
38
38
39
-
40
-
41
39
impl Id {
42
40
/// Construct V0 from uuid.
43
41
pub fn new_v0 ( ) -> Self {
@@ -241,20 +239,41 @@ impl TuplePack for Id {
241
239
w : & mut W ,
242
240
tuple_depth : TupleDepth ,
243
241
) -> std:: io:: Result < VersionstampOffset > {
242
+ let mut size = 1 ;
243
+
244
244
w. write_all ( & [ fdb_util:: codes:: ID ] ) ?;
245
+
246
+ // IMPORTANT: While the normal bytes representation of a v0 ID doesn't include the version, we write
247
+ // it here so that we can unpack without a terminating NIL.
248
+ if let Id :: V0 ( _) = self {
249
+ w. write_all ( & [ 0 ] ) ?;
250
+ size += 1 ;
251
+ }
252
+
245
253
let bytes = self . as_bytes ( ) ;
254
+
246
255
let len = u32:: try_from ( bytes. len ( ) )
247
256
. map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidData , err) ) ?;
257
+ size += len;
258
+
248
259
w. write_all ( & bytes) ?;
249
260
250
- Ok ( VersionstampOffset :: None { size : 1 + len } )
261
+ Ok ( VersionstampOffset :: None { size } )
251
262
}
252
263
}
253
264
254
265
impl < ' de > TupleUnpack < ' de > for Id {
255
266
fn unpack ( input : & [ u8 ] , tuple_depth : TupleDepth ) -> PackResult < ( & [ u8 ] , Self ) > {
256
267
let input = fdb_util:: parse_code ( input, fdb_util:: codes:: ID ) ?;
257
- let ( input, slice) = fdb_util:: parse_bytes ( input, 16 ) ?;
268
+ let ( input2, version) = fdb_util:: parse_byte ( input) ?;
269
+
270
+ let ( input, slice) = if version == 0 {
271
+ // Parse 16 bytes after version
272
+ fdb_util:: parse_bytes ( input2, 16 ) ?
273
+ } else {
274
+ // Parse 19 bytes including version
275
+ fdb_util:: parse_bytes ( input, 19 ) ?
276
+ } ;
258
277
259
278
let v = Id :: from_bytes ( slice)
260
279
. map_err ( |err| PackError :: Message ( format ! ( "bad id format: {err}" ) . into ( ) ) ) ?;
0 commit comments