Module bin.buf
This module implements write buffer.
You should use it if you want to collect some data for write.
Example of usage moonlibs/connection-scribe
Class buf
buf:pv() | Returns raw pointer Doesn't grant ownership. |
buf:export() | Exports data from buffer for external use. |
buf.new(size) | Creates new buffer |
Class buf
Implements write buffer. Has following structure inside
struct bin_buf {
char *buf;
size_t cur;
size_t len;
};
- buf:pv()
-
Returns raw pointer Doesn't grant ownership.
You can't continue to use pointer after buffer modification or after free of original object
Mind GC!
Returns:
-
char *
start of the buffer -
size
of written bytes
-
- buf:export()
-
Exports data from buffer for external use.
Grants ownership of struct to the returned value (including gc) use object after export is prohibited
Returns:
-
char *
start of the buffer -
size
of written data inside buffer -
capacity
- allocated bytes of the buffer
-
- buf.new(size)
-
Creates new buffer
Parameters:
- size initial capacity of the buffer aligned to 64bytes
Returns:
-
buf buffer new empty buffer