| Top |
| GflsByteArray * | gfls_byte_array_new () |
| GBytes * | gfls_byte_array_free_to_bytes () |
| void | gfls_byte_array_append () |
| guint8 * | gfls_byte_array_begin_write () |
| void | gfls_byte_array_end_write () |
Builds an array of bytes.
GflsByteArray is similar to GByteArray and GString but with a smaller and different API, and ensures that at the end of the operation, the resulting GBytes doesn't consume more memory than necessary by doing a reallocation at the final size.
GBytes *
gfls_byte_array_free_to_bytes (GflsByteArray *byte_array);
Transfers the data from byte_array
into a new immutable GBytes, and frees
byte_array
.
If no bytes have been added to byte_array
, NULL is returned.
A nul byte is added at the end, but should not be seen as part of the “real” data. In other words, the data contained in the resulting GBytes is always nul-terminated, but this is not included in the GBytes length.
Note that embedded nul bytes can also be present inside the “real” data.
This function ensures that the resulting GBytes doesn't consume more memory than necessary.
Since: 0.5
void gfls_byte_array_append (GflsByteArray *byte_array,const guint8 *data,gsize size);
Adds the given bytes to the end of byte_array
, by doing a copy.
If data
is NULL or if size
is 0, it will return immediately.
A write operation - as started with gfls_byte_array_begin_write() - must not
be ongoing.
Since: 0.5
guint8 * gfls_byte_array_begin_write (GflsByteArray *byte_array,gsize n_bytes_to_reserve);
Begins a new write operation, to add bytes to the end of byte_array
.
When a successful write operation is finished, call
gfls_byte_array_end_write(). If this function returns NULL, don't call
gfls_byte_array_end_write().
Only one write operation at a time is supported.
Be careful and avoid out-of-bounds writes! For a simpler method that copies
the bytes, see gfls_byte_array_append().
byte_array |
||
n_bytes_to_reserve |
the maximum number of bytes that this write operation will support. |
Since: 0.5
void gfls_byte_array_end_write (GflsByteArray *byte_array,gsize n_bytes_written);
Ends a successful write operation that was started with
gfls_byte_array_begin_write().
n_bytes_written
must be less than or equal to n_bytes_to_reserve
that was
provided at the beginning of this write operation.
After calling this function, you can call again gfls_byte_array_begin_write()
if you need to write more data to the byte_array
.
Since: 0.5