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 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 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 increasesour_end
by exactlyour_amt
. Use wh…Same as
readAtLeast
but also increasesour_end
by exactlyour_amt
. Use whenour_amt
is calculated by us, not by them.