@@ -238,36 +238,57 @@ const segment_file_header_magic_v1: u32 = 0x53474D31; // "SGM1" in big endian
238
238
const segment_file_footer_magic_v1 : u32 = @byteSwap (segment_file_header_magic_v1 );
239
239
240
240
pub const SegmentFileHeader = struct {
241
- magic : u32 = segment_file_header_magic_v1 ,
242
- block_size : u32 ,
241
+ magic : u32 ,
243
242
info : SegmentInfo ,
243
+ has_attributes : bool ,
244
+ has_docs : bool ,
245
+ block_size : u32 ,
244
246
245
247
pub fn msgpackFormat () msgpack.StructFormat {
246
248
return .{
247
249
.as_map = .{
248
- .key = .field_index ,
250
+ .key = .field_index , // FIXME
249
251
.omit_defaults = false ,
250
252
.omit_nulls = true ,
251
253
},
252
254
};
253
255
}
256
+
257
+ pub fn msgpackFieldKey (field : std .meta .FieldEnum (@This ())) u8 {
258
+ return switch (field ) {
259
+ .magic = > 0x00 ,
260
+ .info = > 0x01 ,
261
+ .has_attributes = > 0x02 ,
262
+ .has_docs = > 0x03 ,
263
+ .block_size = > 0x04 ,
264
+ };
265
+ }
254
266
};
255
267
256
268
pub const SegmentFileFooter = struct {
257
- magic : u32 = segment_file_footer_magic_v1 ,
269
+ magic : u32 ,
258
270
num_items : u32 ,
259
271
num_blocks : u32 ,
260
272
checksum : u64 ,
261
273
262
274
pub fn msgpackFormat () msgpack.StructFormat {
263
275
return .{
264
276
.as_map = .{
265
- .key = .field_index ,
277
+ .key = .field_index , // FIXME
266
278
.omit_defaults = false ,
267
279
.omit_nulls = true ,
268
280
},
269
281
};
270
282
}
283
+
284
+ pub fn msgpackFieldKey (field : std .meta .FieldEnum (@This ())) u8 {
285
+ return switch (field ) {
286
+ .magic = > 0x00 ,
287
+ .num_items = > 0x01 ,
288
+ .num_blocks = > 0x02 ,
289
+ .checksum = > 0x03 ,
290
+ };
291
+ }
271
292
};
272
293
273
294
pub fn deleteSegmentFile (dir : std.fs.Dir , info : SegmentInfo ) ! void {
@@ -299,11 +320,15 @@ pub fn writeSegmentFile(dir: std.fs.Dir, reader: anytype) !void {
299
320
const packer = msgpack .packer (writer );
300
321
301
322
const header = SegmentFileHeader {
323
+ .magic = segment_file_header_magic_v1 ,
302
324
.block_size = block_size ,
303
325
.info = segment .info ,
326
+ .has_attributes = true ,
327
+ .has_docs = true ,
304
328
};
305
329
try packer .write (SegmentFileHeader , header );
306
330
331
+ try packer .writeMap (segment .attributes );
307
332
try packer .writeMap (segment .docs );
308
333
309
334
try buffered_writer .flush ();
@@ -393,7 +418,18 @@ pub fn readSegmentFile(dir: fs.Dir, info: SegmentInfo, segment: *FileSegment) !v
393
418
segment .info = header .info ;
394
419
segment .block_size = header .block_size ;
395
420
396
- try unpacker .readMapInto (& segment .docs );
421
+ if (header .has_attributes ) {
422
+ // FIXME nicer api in msgpack.zig
423
+ var attributes = std .AutoHashMap (u64 , u64 ).init (segment .allocator );
424
+ defer attributes .deinit ();
425
+ try unpacker .readMapInto (& attributes );
426
+ segment .attributes .deinit (segment .allocator );
427
+ segment .attributes = attributes .unmanaged .move ();
428
+ }
429
+
430
+ if (header .has_docs ) {
431
+ try unpacker .readMapInto (& segment .docs );
432
+ }
397
433
398
434
const block_size = header .block_size ;
399
435
const padding_size = block_size - fixed_buffer_stream .pos % block_size ;
0 commit comments