Tarantool Lua API

buffer_object

supers: ffi.cdata*

Methods11

function buffer_object.alloc(self: buffer_object, size: integer) -> ffi.cdata*

Allocate size bytes for the buffer.

function buffer_object.capacity(self: buffer_object) -> integer

Return the capacity of the buffer.

function buffer_object.checksize(self: buffer_object, size: integer) -> ffi.cdata*

Check if size bytes are available for reading.

function buffer_object.pos(self: buffer_object) -> integer

Return the size of the range occupied by data.

function buffer_object.read(self: buffer_object, size: integer) -> ffi.cdata*

Read size bytes from the buffer.

function buffer_object.consume(self: buffer_object, size: integer) -> nil

Consume size bytes from the buffer.

function buffer_object.recycle(self: buffer_object) -> nil

Clear the memory slots allocated by buffer_object.

Example:

tarantool> ibuf:recycle()
    ---
    ...
tarantool> ibuf.buf, ibuf.rpos, ibuf.wpos, ibuf.epos
    ---
    - 'cdata<char *>: NULL'
    - 'cdata<char *>: NULL'
    - 'cdata<char *>: NULL'
    - 'cdata<char *>: NULL'
    ...
function buffer_object.reset(self: buffer_object) -> nil

Clear the memory slots used by buffer_object. This method allows to keep the buffer but remove data from it. It is useful when you want to use the buffer further.

Example:

tarantool> ibuf:reset()
    ---
    ...
tarantool> ibuf.buf, ibuf.rpos, ibuf.wpos, ibuf.epos
    ---
    - 'cdata<char *>: 0x010cc28030'
    - 'cdata<char *>: 0x010cc28030'
    - 'cdata<char *>: 0x010cc28030'
    - 'cdata<char *>: 0x010cc2c000'
    ...
function buffer_object.reserve(self: buffer_object, size: integer) -> ffi.cdata*
function buffer_object.size(self: buffer_object) -> integer

Reserve memory for the buffer.

Return a range available for reading data.

function buffer_object.unused(self: buffer_object) -> integer

Return a range for writing data.

Fields4

buffer_object.buf : ffi.cdata*

A pointer to the beginning of the buffer

buffer_object.rpos : ffi.cdata*

A pointer to the beginning of the range; available for reading data ("read position")

buffer_object.wpos : ffi.cdata*

A pointer to the end of the range; available for reading data, and to the beginning of the range for writing new data ("write position")

buffer_object.epos : ffi.cdata*

A pointer to the end of the range; available for writing new data ("end position")