Typedefs | Functions
Binary Buffer

These functions provide string buffer management. More...

Typedefs

typedef struct _Eina_Strbuf Eina_Binbuf
 Type for a string buffer.
 

Functions

EAPI Eina_Binbufeina_binbuf_new (void) EINA_MALLOC EINA_WARN_UNUSED_RESULT
 Creates a new string buffer. More...
 
EAPI Eina_Binbufeina_binbuf_manage_new_length (unsigned char *str, size_t length) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_DEPRECATED
 Creates a new string buffer using the passed string. More...
 
EAPI Eina_Binbufeina_binbuf_manage_new (const unsigned char *str, size_t length, Eina_Bool ro) EINA_MALLOC EINA_WARN_UNUSED_RESULT
 Creates a new string buffer using the passed string. More...
 
EAPI Eina_Binbufeina_binbuf_manage_read_only_new_length (const unsigned char *str, size_t length) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_DEPRECATED
 Creates a new string buffer using the passed string. More...
 
EAPI void eina_binbuf_free (Eina_Binbuf *buf) EINA_ARG_NONNULL(1)
 Frees a string buffer. More...
 
EAPI void eina_binbuf_reset (Eina_Binbuf *buf) EINA_ARG_NONNULL(1)
 Resets a string buffer. More...
 
EAPI Eina_Rw_Slice eina_binbuf_expand (Eina_Binbuf *buf, size_t minimum_unused_space) EINA_ARG_NONNULL(1)
 Expands a buffer, making room for at least minimum_unused_space. More...
 
EAPI Eina_Bool eina_binbuf_use (Eina_Binbuf *buf, size_t extra_bytes) EINA_ARG_NONNULL(1)
 Marks more bytes as used. More...
 
EAPI Eina_Bool eina_binbuf_append_length (Eina_Binbuf *buf, const unsigned char *str, size_t length) EINA_ARG_NONNULL(1
 Appends a string of exact length to a buffer, reallocating as necessary. More...
 
EAPI Eina_Bool EAPI Eina_Bool eina_binbuf_append_slice (Eina_Binbuf *buf, const Eina_Slice slice) EINA_ARG_NONNULL(1)
 Appends a slice to a buffer, reallocating as necessary. More...
 
EAPI Eina_Bool eina_binbuf_append_buffer (Eina_Binbuf *buf, const Eina_Binbuf *data) EINA_ARG_NONNULL(1
 Appends an Eina_Binbuf to a buffer, reallocating as necessary. More...
 
EAPI Eina_Bool EAPI Eina_Bool eina_binbuf_append_char (Eina_Binbuf *buf, unsigned char c) EINA_ARG_NONNULL(1)
 Appends a character to a string buffer, reallocating as necessary. More...
 
EAPI Eina_Bool eina_binbuf_insert_length (Eina_Binbuf *buf, const unsigned char *str, size_t length, size_t pos) EINA_ARG_NONNULL(1
 Inserts a string of exact length to a buffer, reallocating as necessary. More...
 
EAPI Eina_Bool EAPI Eina_Bool eina_binbuf_insert_slice (Eina_Binbuf *buf, const Eina_Slice slice, size_t pos) EINA_ARG_NONNULL(1)
 Inserts a slice to a buffer, reallocating as necessary. More...
 
EAPI Eina_Bool eina_binbuf_insert_char (Eina_Binbuf *buf, unsigned char c, size_t pos) EINA_ARG_NONNULL(1)
 Inserts a character to a string buffer, reallocating as necessary. More...
 
EAPI Eina_Bool eina_binbuf_remove (Eina_Binbuf *buf, size_t start, size_t end) EINA_ARG_NONNULL(1)
 Removes a slice of the given string buffer. More...
 
EAPI const unsigned char * eina_binbuf_string_get (const Eina_Binbuf *buf) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT
 Retrieves a pointer to the contents of a string buffer. More...
 
EAPI unsigned char * eina_binbuf_string_steal (Eina_Binbuf *buf) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1)
 Steals the contents of a string buffer. More...
 
EAPI void eina_binbuf_string_free (Eina_Binbuf *buf) EINA_ARG_NONNULL(1)
 Frees the contents of a string buffer but not the buffer. More...
 
EAPI size_t eina_binbuf_length_get (const Eina_Binbuf *buf) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT
 Retrieves the length of the string buffer content. More...
 
EAPI Eina_Slice eina_binbuf_slice_get (const Eina_Binbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1)
 Gets a read-only slice representing the current binbuf contents. More...
 
EAPI Eina_Rw_Slice eina_binbuf_rw_slice_get (const Eina_Binbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1)
 Gets a read-write slice representing the current binbuf contents. More...
 
EAPI unsigned char * eina_binbuf_release (Eina_Binbuf *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1)
 Gets the content of the buffer and free the buffer. More...
 

Detailed Description

These functions provide string buffer management.

The Binary Buffer data type is designed to be a mutable string, allowing to append, prepend or insert a string to a buffer.

Function Documentation

◆ eina_binbuf_new()

EAPI Eina_Binbuf* eina_binbuf_new ( void  )

Creates a new string buffer.

Returns
Newly allocated string buffer instance.

This function creates a new string buffer. On error, NULL is returned. To free the resources, use eina_binbuf_free().

See also
eina_binbuf_free()
eina_binbuf_append()
eina_binbuf_string_get()

◆ eina_binbuf_manage_new_length()

EAPI Eina_Binbuf* eina_binbuf_manage_new_length ( unsigned char *  str,
size_t  length 
)

Creates a new string buffer using the passed string.

The passed string is used directly as the buffer, it's somehow the opposite function of eina_binbuf_string_steal . The passed string must be malloced.

Parameters
strThe string to manage.
lengthThe length of the string.
Returns
Newly allocated string buffer instance.

This function creates a new string buffer. On error, NULL is returned. To free the resources, use eina_binbuf_free().

See also
eina_binbuf_manage_new()
Since
1.2.0

◆ eina_binbuf_manage_new()

EAPI Eina_Binbuf* eina_binbuf_manage_new ( const unsigned char *  str,
size_t  length,
Eina_Bool  ro 
)

Creates a new string buffer using the passed string.

The passed string is used directly as the buffer, it's somehow the opposite function of eina_binbuf_string_steal .

Parameters
strThe string to start from.
lengthThe length of the string.
roThe passed string will not be touched if set to EINA_TRUE.
Returns
Newly allocated string buffer instance.

This function creates a new string buffer. On error, NULL is returned. To free the resources, use eina_binbuf_free(). It will not touch the buffer if ro is set to EINA_TRUE, but it will also not copy it. If ro is set to EINA_TRUE any change operation will create a fresh new memory, copy old data there and starting modifying that one.

See also
eina_binbuf_manage_new()
eina_binbuf_manage_new_length()
eina_binbuf_manage_read_only_new_length()
Since
1.14.0

Referenced by eet_alias(), eet_identity_certificate_print(), eet_list_entries(), eet_write_cipher(), and emile_decompress().

◆ eina_binbuf_manage_read_only_new_length()

EAPI Eina_Binbuf* eina_binbuf_manage_read_only_new_length ( const unsigned char *  str,
size_t  length 
)

Creates a new string buffer using the passed string.

The passed string is used directly as the buffer, it's somehow the opposite function of eina_binbuf_string_steal . The passed string will not be touched.

Parameters
strThe string to start from.
lengthThe length of the string.
Returns
Newly allocated string buffer instance.

This function creates a new string buffer. On error, NULL is returned. To free the resources, use eina_binbuf_free(). It will not touch the internal buffer. Any changing operation will create a fresh new memory, copy old data there and starting modifying that one.

See also
eina_binbuf_manage_new()
Since
1.9.0

◆ eina_binbuf_free()

EAPI void eina_binbuf_free ( Eina_Binbuf buf)

Frees a string buffer.

Parameters
bufThe string buffer to free.

This function frees the memory of buf. buf must have been created by eina_binbuf_new().

Referenced by eet_alias_get(), eet_read_direct(), and emile_decompress().

◆ eina_binbuf_reset()

EAPI void eina_binbuf_reset ( Eina_Binbuf buf)

Resets a string buffer.

Parameters
bufThe string buffer to reset.

This function resets buf: the buffer len is set to 0, and the string is set to '\0'. No memory is freed.

◆ eina_binbuf_expand()

EAPI Eina_Rw_Slice eina_binbuf_expand ( Eina_Binbuf buf,
size_t  minimum_unused_space 
)

Expands a buffer, making room for at least minimum_unused_space.

One of the properties of the buffer is that it may overallocate space, thus it may have more than eina_binbuf_length_get() bytes allocated. How much depends on buffer growing logic, but this function allows one to request a minimum amount of bytes to be allocated at the end of the buffer.

This is particularly useful to write directly to buffer's memory (ie: a call to read(2)). After the bytes are used call eina_binbuf_use() to mark them as such, so eina_binbuf_length_get() will consider the new bytes.

Parameters
bufThe Buffer to expand.
minimum_unused_spaceThe minimum unused allocated space, in bytes, at the end of the buffer. Zero can be used to query the available slice of unused bytes.
Returns
The slice of unused bytes. The slice length may be zero if minimum_unused_space couldn't be allocated, otherwise it will be at least minimum_unused_space. After bytes are used, mark them as such using eina_binbuf_use().
See also
eina_binbuf_rw_slice_get()
eina_binbuf_use()
Since
1.19

◆ eina_binbuf_use()

EAPI Eina_Bool eina_binbuf_use ( Eina_Binbuf buf,
size_t  extra_bytes 
)

Marks more bytes as used.

This function should be used after eina_binbuf_expand(), marking the extra bytes returned there as used, then they will be considered in all other functions, such as eina_binbuf_length_get().

Parameters
bufThe buffer to mark extra bytes as used.
extra_bytesthe number of bytes to be considered used, must be between zero and the length of the slice returned by eina_binbuf_expand().
Returns
EINA_TRUE on success, EINA_FALSE on failure, such as extra_bytes is too big or buf is NULL.
See also
eina_binbuf_expand()
Since
1.19

◆ eina_binbuf_append_length()

EAPI Eina_Bool eina_binbuf_append_length ( Eina_Binbuf buf,
const unsigned char *  str,
size_t  length 
)

Appends a string of exact length to a buffer, reallocating as necessary.

Parameters
bufThe string buffer to append to.
strThe string to append.
lengthThe exact length to use.
Returns
EINA_TRUE on success, EINA_FALSE on failure.

This function appends str to buf. str must be of size at most length. It is slightly faster than eina_binbuf_append() as it does not compute the size of str. It is useful when dealing with strings of known size, such as eina_stringshare. If buf can't append it, EINA_FALSE is returned, otherwise EINA_TRUE is returned.

See also
eina_stringshare_length()
eina_binbuf_append()
eina_binbuf_append_n()

◆ eina_binbuf_append_slice()

EAPI Eina_Bool EAPI Eina_Bool eina_binbuf_append_slice ( Eina_Binbuf buf,
const Eina_Slice  slice 
)

Appends a slice to a buffer, reallocating as necessary.

Parameters
bufThe string buffer to append to.
sliceThe slice to append.
Returns
EINA_TRUE on success, EINA_FALSE on failure.

This function appends slice to buf. If buf can't append it, EINA_FALSE is returned, otherwise EINA_TRUE is returned.

Since
1.19

◆ eina_binbuf_append_buffer()

EAPI Eina_Bool eina_binbuf_append_buffer ( Eina_Binbuf buf,
const Eina_Binbuf data 
)

Appends an Eina_Binbuf to a buffer, reallocating as necessary.

Parameters
bufThe string buffer to append to.
dataThe string buffer to append.
Returns
EINA_TRUE on success, EINA_FALSE on failure.

This function appends data to buf. data must be allocated and different from NULL. It is slightly faster than eina_binbuf_append() as it does not compute the size of str. If buf can't append it, EINA_FALSE is returned, otherwise EINA_TRUE is returned.

See also
eina_binbuf_append()
eina_binbuf_append_n()
eina_binbuf_append_length()
Since
1.9.0

◆ eina_binbuf_append_char()

EAPI Eina_Bool EAPI Eina_Bool eina_binbuf_append_char ( Eina_Binbuf buf,
unsigned char  c 
)

Appends a character to a string buffer, reallocating as necessary.

Parameters
bufThe string buffer to append to.
cThe char to append.
Returns
EINA_TRUE on success, EINA_FALSE on failure.

This function inserts c to buf. If it can not insert it, EINA_FALSE is returned, otherwise EINA_TRUE is returned.

◆ eina_binbuf_insert_length()

EAPI Eina_Bool eina_binbuf_insert_length ( Eina_Binbuf buf,
const unsigned char *  str,
size_t  length,
size_t  pos 
)

Inserts a string of exact length to a buffer, reallocating as necessary.

Parameters
bufThe string buffer to insert to.
strThe string to insert.
lengthThe exact length to use.
posThe position to insert the string.
Returns
EINA_TRUE on success, EINA_FALSE on failure.

This function inserts str to buf. str must be of size at most length. It is slightly faster than eina_binbuf_insert() as it does not compute the size of str. It is useful when dealing with strings of known size, such as eina_stringshare. If buf can't insert it, EINA_FALSE is returned, otherwise EINA_TRUE is returned.

See also
eina_stringshare_length()
eina_binbuf_insert()
eina_binbuf_insert_n()

◆ eina_binbuf_insert_slice()

EAPI Eina_Bool EAPI Eina_Bool eina_binbuf_insert_slice ( Eina_Binbuf buf,
const Eina_Slice  slice,
size_t  pos 
)

Inserts a slice to a buffer, reallocating as necessary.

Parameters
bufThe string buffer to insert to.
sliceThe slice to insert.
posThe position to insert the string.
Returns
EINA_TRUE on success, EINA_FALSE on failure.

This function inserts slice to buf at position pos. If buf can't insert it, EINA_FALSE is returned, otherwise EINA_TRUE is returned.

Since
1.19.0

◆ eina_binbuf_insert_char()

EAPI Eina_Bool eina_binbuf_insert_char ( Eina_Binbuf buf,
unsigned char  c,
size_t  pos 
)

Inserts a character to a string buffer, reallocating as necessary.

Parameters
bufThe string buffer to insert to.
cThe char to insert.
posThe position to insert the char.
Returns
EINA_TRUE on success, EINA_FALSE on failure.

This function inserts c to buf at position pos. If buf can't append it, EINA_FALSE is returned, otherwise EINA_TRUE is returned.

◆ eina_binbuf_remove()

EAPI Eina_Bool eina_binbuf_remove ( Eina_Binbuf buf,
size_t  start,
size_t  end 
)

Removes a slice of the given string buffer.

Parameters
bufThe string buffer to remove a slice.
startThe initial (inclusive) slice position to start removing, in bytes.
endThe final (non-inclusive) slice position to finish removing, in bytes.
Returns
EINA_TRUE on success, EINA_FALSE on failure.

This function removes a slice of buf, starting at start (inclusive) and ending at end (non-inclusive). Both values are in bytes. It returns EINA_FALSE on failure, EINA_TRUE otherwise.

◆ eina_binbuf_string_get()

EAPI const unsigned char* eina_binbuf_string_get ( const Eina_Binbuf buf)

Retrieves a pointer to the contents of a string buffer.

Parameters
bufThe string buffer.
Returns
The current string in the string buffer.

This function returns the string contained in buf. The returned value must not be modified and will no longer be valid if buf is modified. In other words, any eina_binbuf_append() or similar will make that pointer invalid.

See also
eina_binbuf_string_steal()

Referenced by eet_alias_get(), and eet_read_direct().

◆ eina_binbuf_string_steal()

EAPI unsigned char* eina_binbuf_string_steal ( Eina_Binbuf buf)

Steals the contents of a string buffer.

Parameters
bufThe string buffer to steal.
Returns
The current string in the string buffer.

This function returns the string contained in buf. buf is then initialized and does not own the returned string anymore. The caller must release the memory of the returned string by calling free().

See also
eina_binbuf_string_get()

Referenced by eet_alias_get().

◆ eina_binbuf_string_free()

EAPI void eina_binbuf_string_free ( Eina_Binbuf buf)

Frees the contents of a string buffer but not the buffer.

Parameters
bufThe string buffer to free the string of.

This function frees the string contained in buf without freeing buf.

◆ eina_binbuf_length_get()

EAPI size_t eina_binbuf_length_get ( const Eina_Binbuf buf)

Retrieves the length of the string buffer content.

Parameters
bufThe string buffer.
Returns
The current length of the string, in bytes.

This function returns the length of buf.

Referenced by eet_alias_get(), and eet_read_direct().

◆ eina_binbuf_slice_get()

EAPI Eina_Slice eina_binbuf_slice_get ( const Eina_Binbuf buf)

Gets a read-only slice representing the current binbuf contents.

Parameters
bufthe src buffer.
Returns
a read-only slice for the current contents. It may become invalid as soon as the buf is changed.
Since
1.19

◆ eina_binbuf_rw_slice_get()

EAPI Eina_Rw_Slice eina_binbuf_rw_slice_get ( const Eina_Binbuf buf)

Gets a read-write slice representing the current binbuf contents.

Parameters
bufthe src buffer.
Returns
a read-write slice for the current contents. It may become invalid as soon as the buf is changed with calls such as eina_binbuf_append(), eina_binbuf_remove()
See also
eina_binbuf_expand()
Since
1.19

◆ eina_binbuf_release()

EAPI unsigned char* eina_binbuf_release ( Eina_Binbuf buf)

Gets the content of the buffer and free the buffer.

Parameters
bufthe buffer to get the content from and which will be freed
Returns
The content contained by buf. The caller must release the memory of the returned content by calling free().
Since
1.19