An abstraction to ensure that protocol-parsing code does not perform an out-of-bounds read.

Fields

buf: []u8,
idx: usize = 0,

Points to the next byte in buffer that will be decoded.

our_end: usize = 0,

Up to this point in buf we have already checked that cap is greater than it.

their_end: usize = 0,

Beyond this point in buf is extra tag-along bytes beyond the amount we requested with readAtLeast.

cap: usize = 0,

Points to the end within buffer that has been filled. Beyond this point in buf is undefined bytes.

disable_reads: bool = false,

Debug helper to prevent illegal calls to read functions.

Functions

fn array(d: *Decoder, comptime len: usize) *[len]u8

Use this function to increase idx.

fn decode(d: *Decoder, comptime T: type) T

Use this function to increase idx.

fn ensure(d: *Decoder, amt: usize) !void

Use this function to increase our_end. This should always be called with an a…

Use this function to increase our_end. This should always be called with an amount provided by us, not them.

fn eof(d: Decoder) bool

No documentation provided.

fn fromTheirSlice(buf: []u8) Decoder

No documentation provided.

fn readAtLeast(d: *Decoder, stream: anytype, their_amt: usize) !void

Use this function to increase their_end.

fn readAtLeastOurAmt(d: *Decoder, stream: anytype, our_amt: usize) !void

Same as readAtLeast but also increases our_end by exactly our_amt. Use wh…

Same as readAtLeast but also increases our_end by exactly our_amt. Use when our_amt is calculated by us, not by them.

fn rest(d: Decoder) []u8

No documentation provided.

fn skip(d: *Decoder, amt: usize) void

Use this function to increase idx.

fn slice(d: *Decoder, len: usize) []u8

Use this function to increase idx.

fn sub(d: *Decoder, their_len: usize) !Decoder

Provide the length they claim, and receive a sub-decoder specific to that slice….

Provide the length they claim, and receive a sub-decoder specific to that slice. The parent decoder is advanced to the end.