-struct bt_ctf_field_type_enumeration_mapping_iterator *
-bt_ctf_field_enumeration_get_mappings(struct bt_ctf_field *field)
-{
- int ret;
- struct bt_ctf_field *container = NULL;
- struct bt_ctf_field_type *container_type = NULL;
- struct bt_ctf_field_type_integer *integer_type = NULL;
- struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
-
- container = bt_ctf_field_enumeration_get_container(field);
- if (!container) {
- goto end;
- }
-
- container_type = bt_ctf_field_get_type(container);
- if (!container_type) {
- goto error_put_container;
- }
-
- integer_type = container_of(container_type,
- struct bt_ctf_field_type_integer, parent);
-
- if (!integer_type->is_signed) {
- uint64_t value;
-
- ret = bt_ctf_field_unsigned_integer_get_value(container,
- &value);
- if (ret) {
- goto error_put_container_type;
- }
- iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
- field->type, value);
- } else {
- int64_t value;
-
- ret = bt_ctf_field_signed_integer_get_value(container,
- &value);
- if (ret) {
- goto error_put_container_type;
- }
- iter = bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
- field->type, value);
- }
-
-error_put_container_type:
- bt_put(container_type);
-error_put_container:
- bt_put(container);
-end:
- return iter;
-}
-
-int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *field,
- int64_t *value)
-{
- int ret = 0;
- struct bt_ctf_field_integer *integer;
- struct bt_ctf_field_type_integer *integer_type;
-
- if (!field || !value || !field->payload_set ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_INTEGER) {
- ret = -1;
- goto end;
- }
-
- integer_type = container_of(field->type,
- struct bt_ctf_field_type_integer, parent);
- if (!integer_type->is_signed) {
- ret = -1;
- goto end;
- }
-
- integer = container_of(field,
- struct bt_ctf_field_integer, parent);
- *value = integer->payload.signd;
-end:
- return ret;
-}
-
-int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *field,
- int64_t value)
-{
- int ret = 0;
- struct bt_ctf_field_integer *integer;
- struct bt_ctf_field_type_integer *integer_type;
- unsigned int size;
- int64_t min_value, max_value;
-
- if (!field || field->frozen ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_INTEGER) {
- ret = -1;
- goto end;
- }
-
- integer = container_of(field, struct bt_ctf_field_integer, parent);
- integer_type = container_of(field->type,
- struct bt_ctf_field_type_integer, parent);
- if (!integer_type->is_signed) {
- ret = -1;
- goto end;
- }
-
- size = integer_type->size;
- min_value = -(1ULL << (size - 1));
- max_value = (1ULL << (size - 1)) - 1;
- if (value < min_value || value > max_value) {
- ret = -1;
- goto end;
- }
-
- integer->payload.signd = value;
- integer->parent.payload_set = 1;
-end:
- return ret;
-}
-
-int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *field,
- uint64_t *value)
-{
- int ret = 0;
- struct bt_ctf_field_integer *integer;
- struct bt_ctf_field_type_integer *integer_type;
-
- if (!field || !value || !field->payload_set ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_INTEGER) {
- ret = -1;
- goto end;
- }
-
- integer_type = container_of(field->type,
- struct bt_ctf_field_type_integer, parent);
- if (integer_type->is_signed) {
- ret = -1;
- goto end;
- }
-
- integer = container_of(field,
- struct bt_ctf_field_integer, parent);
- *value = integer->payload.unsignd;
-end:
- return ret;
-}
-
-int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *field,
- uint64_t value)
-{
- int ret = 0;
- struct bt_ctf_field_integer *integer;
- struct bt_ctf_field_type_integer *integer_type;
- unsigned int size;
- uint64_t max_value;
-
- if (!field || field->frozen ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_INTEGER) {
- ret = -1;
- goto end;
- }
-
- integer = container_of(field, struct bt_ctf_field_integer, parent);
- integer_type = container_of(field->type,
- struct bt_ctf_field_type_integer, parent);
- if (integer_type->is_signed) {
- ret = -1;
- goto end;
- }
-
- size = integer_type->size;
- max_value = (size == 64) ? UINT64_MAX : ((uint64_t) 1 << size) - 1;
- if (value > max_value) {
- ret = -1;
- goto end;
- }
-
- integer->payload.unsignd = value;
- integer->parent.payload_set = 1;
-end:
- return ret;
-}
-
-int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *field,
- double *value)
-{
- int ret = 0;
- struct bt_ctf_field_floating_point *floating_point;
-
- if (!field || !value || !field->payload_set ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_FLOAT) {
- ret = -1;
- goto end;
- }
-
- floating_point = container_of(field,
- struct bt_ctf_field_floating_point, parent);
- *value = floating_point->payload;
-end:
- return ret;
-}
-
-int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *field,
- double value)
-{
- int ret = 0;
- struct bt_ctf_field_floating_point *floating_point;
-
- if (!field || field->frozen ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_FLOAT) {
- ret = -1;
- goto end;
- }
- floating_point = container_of(field, struct bt_ctf_field_floating_point,
- parent);
- floating_point->payload = value;
- floating_point->parent.payload_set = 1;
-end:
- return ret;
-}
-
-const char *bt_ctf_field_string_get_value(struct bt_ctf_field *field)
-{
- const char *ret = NULL;
- struct bt_ctf_field_string *string;
-
- if (!field || !field->payload_set ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_STRING) {
- goto end;
- }
-
- string = container_of(field,
- struct bt_ctf_field_string, parent);
- ret = string->payload->str;
-end:
- return ret;
-}
-
-int bt_ctf_field_string_set_value(struct bt_ctf_field *field,
- const char *value)
-{
- int ret = 0;
- struct bt_ctf_field_string *string;
-
- if (!field || !value || field->frozen ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_STRING) {
- ret = -1;
- goto end;
- }
-
- string = container_of(field, struct bt_ctf_field_string, parent);
- if (string->payload) {
- g_string_assign(string->payload, value);
- } else {
- string->payload = g_string_new(value);
- }
-
- string->parent.payload_set = 1;
-end:
- return ret;
-}
-
-int bt_ctf_field_string_append(struct bt_ctf_field *field,
- const char *value)
-{
- int ret = 0;
- struct bt_ctf_field_string *string_field;
-
- if (!field || !value || field->frozen ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_STRING) {
- ret = -1;
- goto end;
- }
-
- string_field = container_of(field, struct bt_ctf_field_string, parent);
-
- if (string_field->payload) {
- g_string_append(string_field->payload, value);
- } else {
- string_field->payload = g_string_new(value);
- }
-
- string_field->parent.payload_set = 1;
-
-end:
- return ret;
-}
-
-int bt_ctf_field_string_append_len(struct bt_ctf_field *field,
- const char *value, unsigned int length)
-{
- int i;
- int ret = 0;
- unsigned int effective_length = length;
- struct bt_ctf_field_string *string_field;
-
- if (!field || !value || field->frozen ||
- bt_ctf_field_type_get_type_id(field->type) !=
- BT_CTF_FIELD_TYPE_ID_STRING) {
- ret = -1;
- goto end;
- }
-
- string_field = container_of(field, struct bt_ctf_field_string, parent);
-
- /* make sure no null bytes are appended */
- for (i = 0; i < length; ++i) {
- if (value[i] == '\0') {
- effective_length = i;
- break;
- }
- }
-
- if (string_field->payload) {
- g_string_append_len(string_field->payload, value,
- effective_length);
- } else {
- string_field->payload = g_string_new_len(value,
- effective_length);
- }
-
- string_field->parent.payload_set = 1;
-
-end:
- return ret;
-}
-
-BT_HIDDEN
-int bt_ctf_field_validate(struct bt_ctf_field *field)
-{
- int ret = 0;
- enum bt_ctf_field_type_id type_id;
-
- if (!field) {
- ret = -1;
- goto end;
- }
-
- type_id = bt_ctf_field_type_get_type_id(field->type);
- if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
- ret = -1;
- goto end;
- }
-
- ret = field_validate_funcs[type_id](field);
-end:
- return ret;
-}
-
-BT_HIDDEN
-int bt_ctf_field_reset(struct bt_ctf_field *field)
-{
- int ret = 0;
- enum bt_ctf_field_type_id type_id;
-
- if (!field) {
- ret = -1;
- goto end;
- }
-
- type_id = bt_ctf_field_type_get_type_id(field->type);
- if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
- ret = -1;
- goto end;
- }
-
- ret = field_reset_funcs[type_id](field);
-end:
- return ret;
-}
-
-BT_HIDDEN
-int bt_ctf_field_serialize(struct bt_ctf_field *field,
- struct bt_ctf_stream_pos *pos,
- enum bt_ctf_byte_order native_byte_order)
-{
- int ret = 0;
- enum bt_ctf_field_type_id type_id;
-
- if (!field || !pos) {
- ret = -1;
- goto end;
- }
-
- type_id = bt_ctf_field_type_get_type_id(field->type);
- if (type_id <= BT_CTF_FIELD_TYPE_ID_UNKNOWN || type_id >= BT_CTF_NR_TYPE_IDS) {
- ret = -1;
- goto end;
- }
-
- ret = field_serialize_funcs[type_id](field, pos, native_byte_order);
-end:
- return ret;
-}
-
-
-BT_HIDDEN
-bt_bool bt_ctf_field_is_set(struct bt_ctf_field *field)
-{
- bt_bool is_set = BT_FALSE;
- enum bt_ctf_field_type_id type_id;
-
- if (!field) {
- goto end;
- }