| ... | @@ -384,3 +384,23 @@ pub fn indexBufferT(bytes: []const u8, comptime T: type, endian: std.builtin.End | ... | @@ -384,3 +384,23 @@ pub fn indexBufferT(bytes: []const u8, comptime T: type, endian: std.builtin.End |
| 384 | error.EndOfStream => unreachable, // assert above has been violated | 384 | error.EndOfStream => unreachable, // assert above has been violated |
| 385 | }; | 385 | }; |
| 386 | } | 386 | } |
| | 387 | |
| | 388 | pub fn BufIndexer(comptime T: type, comptime endian: std.builtin.Endian) type { |
| | 389 | return struct { |
| | 390 | bytes: []const u8, |
| | 391 | max_len: usize, |
| | 392 | |
| | 393 | const Self = @This(); |
| | 394 | |
| | 395 | pub fn init(bytes: []const u8, max_len: usize) Self { |
| | 396 | return .{ |
| | 397 | .bytes = bytes, |
| | 398 | .max_len = max_len, |
| | 399 | }; |
| | 400 | } |
| | 401 | |
| | 402 | pub fn at(self: *const Self, idx: usize) T { |
| | 403 | return indexBufferT(self.bytes, T, endian, idx, self.max_len); |
| | 404 | } |
| | 405 | }; |
| | 406 | } |