| ... | @@ -376,3 +376,11 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) ! | ... | @@ -376,3 +376,11 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) ! |
| 376 | else => |e| @compileError(@tagName(e)), | 376 | else => |e| @compileError(@tagName(e)), |
| 377 | }; | 377 | }; |
| 378 | } | 378 | } |
| | 379 | |
| | 380 | pub fn indexBufferT(bytes: []const u8, comptime T: type, endian: std.builtin.Endian, idx: usize, max_len: usize) T { |
| | 381 | std.debug.assert(idx < max_len); |
| | 382 | var fbs = std.io.fixedBufferStream(bytes[idx * (@sizeOf(T) / @sizeOf(u8)) ..]); |
| | 383 | return readType(fbs.reader(), T, endian) catch |err| switch (err) { |
| | 384 | error.EndOfStream => unreachable, // assert above has been violated |
| | 385 | }; |
| | 386 | } |