This PR extends the variants functionality to support referenced values. When adding strings or bytes as variants, the current API creates a copy of those, however there are cases where the caller control its own buffer only wants to have a reference but not a new copy to avoid memory duplication; this is the case of an optimization we are doing in Fluent Bit.
This is a refactor that affects variants, kvlist and arrays, the following is a summary of the new APIs that changed (these are the latest versions):
variants
struct cfl_variant *cfl_variant_create_from_string_s(char *value, size_t value_size, int referenced);
struct cfl_variant *cfl_variant_create_from_bytes(char *value, size_t length, int referenced);
This PR also adds two new functions to set and retrieve the size of such buffers:
int cfl_kvlist_insert_bytes(struct cfl_kvlist *list, char *key, char *value,
char *value, size_t value_length,
int referenced);
int cfl_kvlist_insert_bytes_s(struct cfl_kvlist *list,
char *key, size_t key_size,
char *value, size_t value_length,
int referenced);
int cfl_kvlist_insert_string_s(struct cfl_kvlist *list,
char *key, size_t key_size,
char *value, size_t value_size,
int referenced);
array
int cfl_array_append_string_s(struct cfl_array *array, char *str, size_t str_len, int referenced);
int cfl_array_append_bytes(struct cfl_array *array, char *value, size_t length, int referenced);
In addition to the changes in array, I have added a new unit test for the array API.
These are breaking changes that once this library is updated, we will need changes also in CMetrics and CTraces
Note: this PR bumps CFL to v0.5.0
This PR extends the variants functionality to support
referenced
values. When adding strings or bytes as variants, the current API creates a copy of those, however there are cases where the caller control its own buffer only wants to have a reference but not a new copy to avoid memory duplication; this is the case of an optimization we are doing in Fluent Bit.This is a refactor that affects variants, kvlist and arrays, the following is a summary of the new APIs that changed (these are the latest versions):
variants
This PR also adds two new functions to set and retrieve the size of such buffers:
kvlist
array
In addition to the changes in array, I have added a new unit test for the array API.
These are breaking changes that once this library is updated, we will need changes also in CMetrics and CTraces