Module bin.saferbuf

Implements Safe binary Reader.

Example of usage ochaton/migrate

Same as bin.rbuf but safer. Always checks bounds of the buffer.

See also:

Class saferbuf

srbuf:ber() Decodes VLQ number Opposite to bin.basebuf.ber (LuaJIT >= 2.1).
srbuf:str(len) Reads len bytes from buffer and returns string.
srbuf:skip(len) Forwards cursor for len bytes (bounds checks inside)
srbuf:have([bytes=0[, lvl=2]]) Checks that buffer has at least bytes till the end
saferbuf.new(ptr[, size=#str]) Creates reader from given pointer


Class saferbuf

Safe rbuf implements everything bin.rbuf does but adds bounds checks. Has following structure.

struct bin_safe_rbuf {
    const char * buf;
    union {
        const char     *c;
        const int8_t   *i8;
        const uint8_t  *u8;
        const int16_t  *i16;
        const uint16_t *u16;
        const int32_t  *i32;
        const uint32_t *u32;
        const int64_t  *i64;
        const uint64_t *u64;
    } p;
    size_t len;
};
srbuf:ber()
Decodes VLQ number Opposite to bin.basebuf.ber (LuaJIT >= 2.1).

Returns:

    number decoded value
srbuf:str(len)
Reads len bytes from buffer and returns string.

Parameters:

  • len number

Returns:

    string
srbuf:skip(len)
Forwards cursor for len bytes (bounds checks inside)

Parameters:

  • len number number of bytes
srbuf:have([bytes=0[, lvl=2]])
Checks that buffer has at least bytes till the end

Parameters:

  • bytes number (default 0)
  • lvl number (default 2)

Returns:

    number bytes to the end of the buffer
saferbuf.new(ptr[, size=#str])
Creates reader from given pointer

Parameters:

  • ptr `char string or pointer
  • size number of the buffer (default #str)

Returns:

    saferbuf
generated by LDoc 1.4.6 Last updated 2022-05-19 12:17:27