Make API CTF-agnostic
[babeltrace.git] / plugins / ctf / common / btr / btr.c
index e4776cf635871cdc369ed29f4cbe0aec37f08ff5..848e219198c961541cb8fb820be998f2aeba90c6 100644 (file)
  * SOFTWARE.
  */
 
-#define BT_LOG_OUTPUT_LEVEL btr_log_level
 #define BT_LOG_TAG "PLUGIN-CTF-BTR"
-#include <babeltrace/logging-internal.h>
-
-static int btr_log_level = BT_LOG_NONE;
+#include "logging.h"
 
 #include <stdlib.h>
 #include <stdint.h>
@@ -35,20 +32,17 @@ static int btr_log_level = BT_LOG_NONE;
 #include <stdio.h>
 #include <stddef.h>
 #include <stdbool.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
 #include <string.h>
 #include <babeltrace/bitfield-internal.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/field-types-internal.h>
+#include <babeltrace/common-internal.h>
+#include <babeltrace/babeltrace.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/align-internal.h>
 #include <glib.h>
 
 #include "btr.h"
-
-#define PRINT_ERR_STREAM       (btr ? btr->err_stream : stderr)
-#define PRINT_PREFIX           "ctf-btr"
-#include "../print.h"
+#include "../metadata/ctf-meta.h"
 
 #define DIV8(_x)                       ((_x) >> 3)
 #define BYTES_TO_BITS(_x)              ((_x) * 8)
@@ -65,22 +59,23 @@ struct stack_entry {
         *   * Array
         *   * Sequence
         *   * Variant
-        *
-        * Owned by this.
         */
-       struct bt_ctf_field_type *base_type;
+       struct ctf_field_type *base_type;
 
        /* Length of base field (always 1 for variant types) */
        int64_t base_len;
 
-       /* Lndex of next field to read */
+       /* Index of next field to read */
        int64_t index;
 };
 
 /* Visit stack */
 struct stack {
-       /* Entries (struct stack_entry *) (top is last element) */
-       GPtrArray *entries;
+       /* Entries (struct stack_entry) */
+       GArray *entries;
+
+       /* Number of active entries */
+       size_t size;
 };
 
 /* Reading states */
@@ -94,15 +89,12 @@ enum btr_state {
 };
 
 /* Binary type reader */
-struct bt_ctf_btr {
+struct bt_btr {
        /* Bisit stack */
        struct stack *stack;
 
-       /* Error stream */
-       FILE *err_stream;
-
        /* Current basic field type */
-       struct bt_ctf_field_type *cur_basic_field_type;
+       struct ctf_field_type *cur_basic_field_type;
 
        /* Current state */
        enum btr_state state;
@@ -114,13 +106,13 @@ struct bt_ctf_btr {
         * types for which the common boundary is not the boundary of
         * a byte cannot have different byte orders.
         *
-        * This is set to BT_CTF_BYTE_ORDER_UNKNOWN on reset and when
-        * the last basic field type was a string type.
+        * This is set to -1 on reset and when the last basic field type
+        * was a string type.
         */
-       enum bt_ctf_byte_order last_bo;
+       enum ctf_byte_order last_bo;
 
        /* Current byte order (copied to last_bo after a successful read) */
-       enum bt_ctf_byte_order cur_bo;
+       enum ctf_byte_order cur_bo;
 
        /* Stitch buffer infos */
        struct {
@@ -158,20 +150,13 @@ struct bt_ctf_btr {
        /* User stuff */
        struct {
                /* Callback functions */
-               struct bt_ctf_btr_cbs cbs;
+               struct bt_btr_cbs cbs;
 
                /* Private data */
                void *data;
        } user;
 };
 
-static
-void __attribute__((constructor)) logging_ctor(void)
-{
-       btr_log_level =
-               bt_log_get_level_from_env("BABELTRACE_PLUGIN_CTF_BTR_LOG_LEVEL");
-}
-
 static inline
 const char *btr_state_string(enum btr_state state)
 {
@@ -193,15 +178,6 @@ const char *btr_state_string(enum btr_state state)
        }
 }
 
-static
-void stack_entry_free_func(gpointer data)
-{
-       struct stack_entry *entry = data;
-
-       BT_PUT(entry->base_type);
-       g_free(entry);
-}
-
 static
 struct stack *stack_new(void)
 {
@@ -213,9 +189,9 @@ struct stack *stack_new(void)
                goto error;
        }
 
-       stack->entries = g_ptr_array_new_with_free_func(stack_entry_free_func);
+       stack->entries = g_array_new(FALSE, TRUE, sizeof(struct stack_entry));
        if (!stack->entries) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LOGE_STR("Failed to allocate a GArray.");
                goto error;
        }
 
@@ -224,7 +200,6 @@ struct stack *stack_new(void)
 
 error:
        g_free(stack);
-
        return NULL;
 }
 
@@ -236,94 +211,93 @@ void stack_destroy(struct stack *stack)
        }
 
        BT_LOGD("Destroying stack: addr=%p", stack);
-       g_ptr_array_free(stack->entries, TRUE);
+
+       if (stack->entries) {
+               g_array_free(stack->entries, TRUE);
+       }
+
        g_free(stack);
 }
 
+static
+int stack_push(struct stack *stack, struct ctf_field_type *base_type,
+       size_t base_len)
+{
+       struct stack_entry *entry;
+
+       BT_ASSERT(stack);
+       BT_ASSERT(base_type);
+       BT_LOGV("Pushing field type on stack: stack-addr=%p, "
+               "ft-addr=%p, ft-id=%d, base-length=%zu, "
+               "stack-size-before=%zu, stack-size-after=%zu",
+               stack, base_type, base_type->id,
+               base_len, stack->size, stack->size + 1);
+
+       if (stack->entries->len == stack->size) {
+               g_array_set_size(stack->entries, stack->size + 1);
+       }
+
+       entry = &g_array_index(stack->entries, struct stack_entry, stack->size);
+       entry->base_type = base_type;
+       entry->base_len = base_len;
+       entry->index = 0;
+       stack->size++;
+       return 0;
+}
+
 static inline
-int64_t get_compound_field_type_length(struct bt_ctf_btr *btr,
-               struct bt_ctf_field_type *field_type)
+int64_t get_compound_field_type_length(struct bt_btr *btr,
+               struct ctf_field_type *ft)
 {
        int64_t length;
 
-       switch (bt_ctf_field_type_get_type_id(field_type)) {
-       case BT_CTF_FIELD_TYPE_ID_STRUCT:
-               length = (int64_t) bt_ctf_field_type_structure_get_field_count(
-                       field_type);
+       switch (ft->id) {
+       case CTF_FIELD_TYPE_ID_STRUCT:
+       {
+               struct ctf_field_type_struct *struct_ft = (void *) ft;
+
+               length = (int64_t) struct_ft->members->len;
                break;
-       case BT_CTF_FIELD_TYPE_ID_VARIANT:
+       }
+       case CTF_FIELD_TYPE_ID_VARIANT:
+       {
                /* Variant field types always "contain" a single type */
                length = 1;
                break;
-       case BT_CTF_FIELD_TYPE_ID_ARRAY:
-               length = bt_ctf_field_type_array_get_length(field_type);
+       }
+       case CTF_FIELD_TYPE_ID_ARRAY:
+       {
+               struct ctf_field_type_array *array_ft = (void *) ft;
+
+               length = (int64_t) array_ft->length;
                break;
-       case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
-               length = btr->user.cbs.query.get_sequence_length(field_type,
+       }
+       case CTF_FIELD_TYPE_ID_SEQUENCE:
+               length = btr->user.cbs.query.get_sequence_length(ft,
                        btr->user.data);
                break;
        default:
-               BT_LOGW("Cannot get field type's field count: btr-addr=%p, "
-                       "ft-addr=%p, ft-id=%s",
-                       btr, field_type,
-                       bt_ctf_field_type_id_string(
-                               bt_ctf_field_type_get_type_id(field_type)));
-               length = BT_CTF_BTR_STATUS_ERROR;
+               abort();
        }
 
        return length;
 }
 
 static
-int stack_push(struct stack *stack, struct bt_ctf_field_type *base_type,
-       size_t base_len)
+int stack_push_with_len(struct bt_btr *btr, struct ctf_field_type *base_type)
 {
-       int ret = 0;
-       struct stack_entry *entry;
-
-       assert(stack);
-       assert(base_type);
-
-       BT_LOGV("Pushing field type on stack: stack-addr=%p, "
-               "ft-addr=%p, ft-id=%s, base-length=%zu, "
-               "stack-size-before=%u, stack-size-after=%u",
-               stack, base_type, bt_ctf_field_type_id_string(
-                       bt_ctf_field_type_get_type_id(base_type)),
-               base_len, stack->entries->len, stack->entries->len + 1);
-       entry = g_new0(struct stack_entry, 1);
-       if (!entry) {
-               BT_LOGE("Failed to allocate one stack entry: stack-addr=%p",
-                       stack);
-               ret = BT_CTF_BTR_STATUS_ERROR;
-               goto end;
-       }
-
-       entry->base_type = base_type;
-       bt_get(entry->base_type);
-       entry->base_len = base_len;
-       g_ptr_array_add(stack->entries, entry);
-
-end:
-       return ret;
-}
-
-static
-int stack_push_with_len(struct bt_ctf_btr *btr,
-               struct bt_ctf_field_type *base_type)
-{
-       int ret = 0;
-       int64_t base_len = get_compound_field_type_length(btr, base_type);
+       int ret;
+       int64_t length = get_compound_field_type_length(btr, base_type);
 
-       if (base_len < 0) {
+       if (length < 0) {
                BT_LOGW("Cannot get compound field type's field count: "
-                       "btr-addr=%p, ft-addr=%p, ft-id=%s",
-                       btr, base_type, bt_ctf_field_type_id_string(
-                               bt_ctf_field_type_get_type_id(base_type)));
-               ret = BT_CTF_BTR_STATUS_ERROR;
+                       "btr-addr=%p, ft-addr=%p, ft-id=%d",
+                       btr, base_type, base_type->id);
+               ret = BT_BTR_STATUS_ERROR;
                goto end;
        }
 
-       ret = stack_push(btr->stack, base_type, (size_t) base_len);
+       ret = stack_push(btr->stack, base_type, (size_t) length);
 
 end:
        return ret;
@@ -332,20 +306,19 @@ end:
 static inline
 unsigned int stack_size(struct stack *stack)
 {
-       assert(stack);
-
-       return stack->entries->len;
+       BT_ASSERT(stack);
+       return stack->size;
 }
 
 static
 void stack_pop(struct stack *stack)
 {
-       assert(stack);
-       assert(stack_size(stack));
+       BT_ASSERT(stack);
+       BT_ASSERT(stack_size(stack));
        BT_LOGV("Popping from stack: "
                "stack-addr=%p, stack-size-before=%u, stack-size-after=%u",
                stack, stack->entries->len, stack->entries->len - 1);
-       g_ptr_array_remove_index(stack->entries, stack->entries->len - 1);
+       stack->size--;
 }
 
 static inline
@@ -357,32 +330,27 @@ bool stack_empty(struct stack *stack)
 static
 void stack_clear(struct stack *stack)
 {
-       assert(stack);
-
-       if (!stack_empty(stack)) {
-               g_ptr_array_remove_range(stack->entries, 0, stack_size(stack));
-       }
-
-       assert(stack_empty(stack));
+       BT_ASSERT(stack);
+       stack->size = 0;
 }
 
 static inline
 struct stack_entry *stack_top(struct stack *stack)
 {
-       assert(stack);
-       assert(stack_size(stack));
-
-       return g_ptr_array_index(stack->entries, stack->entries->len - 1);
+       BT_ASSERT(stack);
+       BT_ASSERT(stack_size(stack));
+       return &g_array_index(stack->entries, struct stack_entry,
+               stack->size - 1);
 }
 
 static inline
-size_t available_bits(struct bt_ctf_btr *btr)
+size_t available_bits(struct bt_btr *btr)
 {
        return btr->buf.sz - btr->buf.at;
 }
 
 static inline
-void consume_bits(struct bt_ctf_btr *btr, size_t incr)
+void consume_bits(struct bt_btr *btr, size_t incr)
 {
        BT_LOGV("Advancing cursor: btr-addr=%p, cur-before=%zu, cur-after=%zu",
                btr, btr->buf.at, btr->buf.at + incr);
@@ -390,25 +358,25 @@ void consume_bits(struct bt_ctf_btr *btr, size_t incr)
 }
 
 static inline
-bool has_enough_bits(struct bt_ctf_btr *btr, size_t sz)
+bool has_enough_bits(struct bt_btr *btr, size_t sz)
 {
        return available_bits(btr) >= sz;
 }
 
 static inline
-bool at_least_one_bit_left(struct bt_ctf_btr *btr)
+bool at_least_one_bit_left(struct bt_btr *btr)
 {
        return has_enough_bits(btr, 1);
 }
 
 static inline
-size_t packet_at(struct bt_ctf_btr *btr)
+size_t packet_at(struct bt_btr *btr)
 {
        return btr->buf.packet_offset + btr->buf.at;
 }
 
 static inline
-size_t buf_at_from_addr(struct bt_ctf_btr *btr)
+size_t buf_at_from_addr(struct bt_btr *btr)
 {
        /*
         * Considering this:
@@ -426,69 +394,25 @@ size_t buf_at_from_addr(struct bt_ctf_btr *btr)
        return btr->buf.offset + btr->buf.at;
 }
 
-static inline
-int get_basic_field_type_size(struct bt_ctf_btr *btr,
-               struct bt_ctf_field_type *field_type)
-{
-       int size;
-
-       switch (bt_ctf_field_type_get_type_id(field_type)) {
-       case BT_CTF_FIELD_TYPE_ID_INTEGER:
-               size = bt_ctf_field_type_integer_get_size(field_type);
-               break;
-       case BT_CTF_FIELD_TYPE_ID_FLOAT:
-       {
-               int exp_dig, mant_dig;
-
-               exp_dig =
-                       bt_ctf_field_type_floating_point_get_exponent_digits(
-                               field_type);
-               mant_dig =
-                       bt_ctf_field_type_floating_point_get_mantissa_digits(
-                               field_type);
-               assert(exp_dig >= 0);
-               assert(mant_dig >= 0);
-               size = exp_dig + mant_dig;
-               break;
-       }
-       case BT_CTF_FIELD_TYPE_ID_ENUM:
-       {
-               struct bt_ctf_field_type *int_type;
-
-               int_type = bt_ctf_field_type_enumeration_get_container_type(
-                       field_type);
-               assert(int_type);
-               size = get_basic_field_type_size(btr, int_type);
-               BT_PUT(int_type);
-               break;
-       }
-       default:
-               size = BT_CTF_BTR_STATUS_ERROR;
-               break;
-       }
-
-       return size;
-}
-
 static
-void stitch_reset(struct bt_ctf_btr *btr)
+void stitch_reset(struct bt_btr *btr)
 {
        btr->stitch.offset = 0;
        btr->stitch.at = 0;
 }
 
 static inline
-size_t stitch_at_from_addr(struct bt_ctf_btr *btr)
+size_t stitch_at_from_addr(struct bt_btr *btr)
 {
        return btr->stitch.offset + btr->stitch.at;
 }
 
 static
-void stitch_append_from_buf(struct bt_ctf_btr *btr, size_t sz)
+void stitch_append_from_buf(struct bt_btr *btr, size_t sz)
 {
        size_t stitch_byte_at;
        size_t buf_byte_at;
-       size_t nb_bytes;;
+       size_t nb_bytes;
 
        if (sz == 0) {
                return;
@@ -498,7 +422,8 @@ void stitch_append_from_buf(struct bt_ctf_btr *btr, size_t sz)
                BITS_TO_BYTES_FLOOR(stitch_at_from_addr(btr));
        buf_byte_at = BITS_TO_BYTES_FLOOR(buf_at_from_addr(btr));
        nb_bytes = BITS_TO_BYTES_CEIL(sz);
-       assert(nb_bytes > 0);
+       BT_ASSERT(nb_bytes > 0);
+       BT_ASSERT(btr->buf.addr);
        memcpy(&btr->stitch.buf[stitch_byte_at], &btr->buf.addr[buf_byte_at],
                nb_bytes);
        btr->stitch.at += sz;
@@ -506,13 +431,13 @@ void stitch_append_from_buf(struct bt_ctf_btr *btr, size_t sz)
 }
 
 static
-void stitch_append_from_remaining_buf(struct bt_ctf_btr *btr)
+void stitch_append_from_remaining_buf(struct bt_btr *btr)
 {
        stitch_append_from_buf(btr, available_bits(btr));
 }
 
 static
-void stitch_set_from_remaining_buf(struct bt_ctf_btr *btr)
+void stitch_set_from_remaining_buf(struct bt_btr *btr)
 {
        stitch_reset(btr);
        btr->stitch.offset = IN_BYTE_OFFSET(buf_at_from_addr(btr));
@@ -520,63 +445,52 @@ void stitch_set_from_remaining_buf(struct bt_ctf_btr *btr)
 }
 
 static inline
-enum bt_ctf_btr_status read_unsigned_bitfield(const uint8_t *buf, size_t at,
-               int64_t field_size, enum bt_ctf_byte_order bo, uint64_t *v)
+void read_unsigned_bitfield(const uint8_t *buf, size_t at,
+               unsigned int field_size, enum ctf_byte_order bo,
+               uint64_t *v)
 {
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
-
        switch (bo) {
-       case BT_CTF_BYTE_ORDER_BIG_ENDIAN:
-       case BT_CTF_BYTE_ORDER_NETWORK:
+       case CTF_BYTE_ORDER_BIG:
                bt_bitfield_read_be(buf, uint8_t, at, field_size, v);
                break;
-       case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
+       case CTF_BYTE_ORDER_LITTLE:
                bt_bitfield_read_le(buf, uint8_t, at, field_size, v);
                break;
        default:
-               BT_LOGF("Cannot read unsigned bit array: unknown byte order: bo=%d", bo);
                abort();
        }
 
-       BT_LOGV("Read unsigned bit array: cur=%zu, size=%" PRId64 ", "
-               "bo=%s, val=%" PRIu64, at, field_size,
-               bt_ctf_byte_order_string(bo), *v);
-       return status;
+       BT_LOGV("Read unsigned bit array: cur=%zu, size=%u, "
+               "bo=%d, val=%" PRIu64, at, field_size, bo, *v);
 }
 
 static inline
-enum bt_ctf_btr_status read_signed_bitfield(const uint8_t *buf, size_t at,
-               int64_t field_size, enum bt_ctf_byte_order bo, int64_t *v)
+void read_signed_bitfield(const uint8_t *buf, size_t at,
+               unsigned int field_size, enum ctf_byte_order bo, int64_t *v)
 {
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
-
        switch (bo) {
-       case BT_CTF_BYTE_ORDER_BIG_ENDIAN:
-       case BT_CTF_BYTE_ORDER_NETWORK:
+       case CTF_BYTE_ORDER_BIG:
                bt_bitfield_read_be(buf, uint8_t, at, field_size, v);
                break;
-       case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
+       case CTF_BYTE_ORDER_LITTLE:
                bt_bitfield_read_le(buf, uint8_t, at, field_size, v);
                break;
        default:
-               BT_LOGF("Cannot read signed bit array: unknown byte order: bo=%d", bo);
                abort();
        }
 
-       BT_LOGV("Read signed bit array: cur=%zu, size=%" PRId64 ", "
-               "bo=%s, val=%" PRId64, at, field_size,
-               bt_ctf_byte_order_string(bo), *v);
-       return status;
+       BT_LOGV("Read signed bit array: cur=%zu, size=%u, "
+               "bo=%d, val=%" PRId64, at, field_size, bo, *v);
 }
 
-typedef enum bt_ctf_btr_status (* read_basic_and_call_cb_t)(struct bt_ctf_btr *,
+typedef enum bt_btr_status (* read_basic_and_call_cb_t)(struct bt_btr *,
                const uint8_t *, size_t);
 
 static inline
-enum bt_ctf_btr_status validate_contiguous_bo(struct bt_ctf_btr *btr,
-               enum bt_ctf_byte_order next_bo)
+enum bt_btr_status validate_contiguous_bo(struct bt_btr *btr,
+               enum ctf_byte_order next_bo)
 {
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
 
        /* Always valid when at a byte boundary */
        if (packet_at(btr) % 8 == 0) {
@@ -584,56 +498,54 @@ enum bt_ctf_btr_status validate_contiguous_bo(struct bt_ctf_btr *btr,
        }
 
        /* Always valid if last byte order is unknown */
-       if (btr->last_bo == BT_CTF_BYTE_ORDER_UNKNOWN) {
+       if (btr->last_bo == -1) {
                goto end;
        }
 
        /* Always valid if next byte order is unknown */
-       if (next_bo == BT_CTF_BYTE_ORDER_UNKNOWN) {
+       if (next_bo == -1) {
                goto end;
        }
 
        /* Make sure last byte order is compatible with the next byte order */
        switch (btr->last_bo) {
-       case BT_CTF_BYTE_ORDER_BIG_ENDIAN:
-       case BT_CTF_BYTE_ORDER_NETWORK:
-               if (next_bo != BT_CTF_BYTE_ORDER_BIG_ENDIAN &&
-                               next_bo != BT_CTF_BYTE_ORDER_NETWORK) {
-                       status = BT_CTF_BTR_STATUS_ERROR;
+       case CTF_BYTE_ORDER_BIG:
+               if (next_bo != CTF_BYTE_ORDER_BIG) {
+                       status = BT_BTR_STATUS_ERROR;
                }
                break;
-       case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN:
-               if (next_bo != BT_CTF_BYTE_ORDER_LITTLE_ENDIAN) {
-                       status = BT_CTF_BTR_STATUS_ERROR;
+       case CTF_BYTE_ORDER_LITTLE:
+               if (next_bo != CTF_BYTE_ORDER_LITTLE) {
+                       status = BT_BTR_STATUS_ERROR;
                }
                break;
        default:
-               status = BT_CTF_BTR_STATUS_ERROR;
+               status = BT_BTR_STATUS_ERROR;
        }
 
 end:
-       if (status) {
+       if (status < 0) {
                BT_LOGW("Cannot read bit array: two different byte orders not at a byte boundary: "
-                       "btr-addr=%p, last-bo=%s, next-bo=%s",
-                       btr, bt_ctf_byte_order_string(btr->last_bo),
-                       bt_ctf_byte_order_string(next_bo));
+                       "btr-addr=%p, last-bo=%d, next-bo=%d",
+                       btr, btr->last_bo, next_bo);
        }
 
        return status;
 }
 
 static
-enum bt_ctf_btr_status read_basic_float_and_call_cb(struct bt_ctf_btr *btr,
+enum bt_btr_status read_basic_float_and_call_cb(struct bt_btr *btr,
                const uint8_t *buf, size_t at)
 {
-       int ret;
        double dblval;
-       int64_t field_size;
-       enum bt_ctf_byte_order bo;
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
-
-       field_size = get_basic_field_type_size(btr, btr->cur_basic_field_type);
-       bo = bt_ctf_field_type_get_byte_order(btr->cur_basic_field_type);
+       unsigned int field_size;
+       enum ctf_byte_order bo;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
+       struct ctf_field_type_float *ft = (void *) btr->cur_basic_field_type;
+
+       BT_ASSERT(ft);
+       field_size = ft->base.size;
+       bo = ft->base.byte_order;
        btr->cur_bo = bo;
 
        switch (field_size) {
@@ -645,20 +557,7 @@ enum bt_ctf_btr_status read_basic_float_and_call_cb(struct bt_ctf_btr *btr,
                        float f;
                } f32;
 
-               ret = bt_ctf_field_type_floating_point_get_mantissa_digits(
-                       btr->cur_basic_field_type);
-               assert(ret == 24);
-               ret = bt_ctf_field_type_floating_point_get_exponent_digits(
-                       btr->cur_basic_field_type);
-               assert(ret == 8);
-               status = read_unsigned_bitfield(buf, at, field_size, bo, &v);
-               if (status != BT_CTF_BTR_STATUS_OK) {
-                       BT_LOGW("Cannot read unsigned 32-bit bit array for floating point number field: "
-                               "btr-addr=%p, status=%s",
-                               btr, bt_ctf_btr_status_string(status));
-                       goto end;
-               }
-
+               read_unsigned_bitfield(buf, at, field_size, bo, &v);
                f32.u = (uint32_t) v;
                dblval = (double) f32.f;
                break;
@@ -670,30 +569,13 @@ enum bt_ctf_btr_status read_basic_float_and_call_cb(struct bt_ctf_btr *btr,
                        double d;
                } f64;
 
-               ret = bt_ctf_field_type_floating_point_get_mantissa_digits(
-                       btr->cur_basic_field_type);
-               assert(ret == 53);
-               ret = bt_ctf_field_type_floating_point_get_exponent_digits(
-                       btr->cur_basic_field_type);
-               assert(ret == 11);
-               status = read_unsigned_bitfield(buf, at, field_size, bo,
-                       &f64.u);
-               if (status != BT_CTF_BTR_STATUS_OK) {
-                       BT_LOGW("Cannot read unsigned 64-bit bit array for floating point number field: "
-                               "btr-addr=%p, status=%s",
-                               btr, bt_ctf_btr_status_string(status));
-                       goto end;
-               }
-
+               read_unsigned_bitfield(buf, at, field_size, bo, &f64.u);
                dblval = f64.d;
                break;
        }
        default:
                /* Only 32-bit and 64-bit fields are supported currently */
-               BT_LOGW("Only 32-bit and 64-bit floating point number fields are supported: "
-                       "btr-addr=%p", btr);
-               status = BT_CTF_BTR_STATUS_ERROR;
-               goto end;
+               abort();
        }
 
        BT_LOGV("Read floating point number value: btr=%p, cur=%zu, val=%f",
@@ -704,39 +586,27 @@ enum bt_ctf_btr_status read_basic_float_and_call_cb(struct bt_ctf_btr *btr,
                status = btr->user.cbs.types.floating_point(dblval,
                        btr->cur_basic_field_type, btr->user.data);
                BT_LOGV("User function returned: status=%s",
-                       bt_ctf_btr_status_string(status));
-               if (status != BT_CTF_BTR_STATUS_OK) {
+                       bt_btr_status_string(status));
+               if (status != BT_BTR_STATUS_OK) {
                        BT_LOGW("User function failed: btr-addr=%p, status=%s",
-                               btr, bt_ctf_btr_status_string(status));
+                               btr, bt_btr_status_string(status));
                }
        }
 
-end:
        return status;
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_int_and_call(struct bt_ctf_btr *btr,
-               const uint8_t *buf, size_t at,
-               struct bt_ctf_field_type *int_type,
-               struct bt_ctf_field_type *orig_type)
+enum bt_btr_status read_basic_int_and_call_cb(struct bt_btr *btr,
+               const uint8_t *buf, size_t at)
 {
-       int signd;
-       int64_t field_size;
-       enum bt_ctf_byte_order bo;
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
-
-       signd = bt_ctf_field_type_integer_get_signed(int_type);
-       field_size = get_basic_field_type_size(btr, int_type);
-       if (field_size < 1) {
-               BT_LOGW("Cannot get integer field type's size: "
-                       "btr=%p, at=%zu, ft-addr=%p",
-                       btr, at, int_type);
-               status = BT_CTF_BTR_STATUS_ERROR;
-               goto end;
-       }
+       unsigned int field_size;
+       enum ctf_byte_order bo;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
+       struct ctf_field_type_int *ft = (void *) btr->cur_basic_field_type;
 
-       bo = bt_ctf_field_type_get_byte_order(int_type);
+       field_size = ft->base.size;
+       bo = ft->base.byte_order;
 
        /*
         * Update current byte order now because we could be reading
@@ -745,122 +615,77 @@ enum bt_ctf_btr_status read_basic_int_and_call(struct bt_ctf_btr *btr,
         */
        btr->cur_bo = bo;
 
-       if (signd) {
+       if (ft->is_signed) {
                int64_t v;
 
-               status = read_signed_bitfield(buf, at, field_size, bo, &v);
-               if (status != BT_CTF_BTR_STATUS_OK) {
-                       BT_LOGW("Cannot read signed bit array for signed integer field: "
-                               "btr-addr=%p, status=%s",
-                               btr, bt_ctf_btr_status_string(status));
-                       goto end;
-               }
+               read_signed_bitfield(buf, at, field_size, bo, &v);
 
                if (btr->user.cbs.types.signed_int) {
                        BT_LOGV("Calling user function (signed integer).");
                        status = btr->user.cbs.types.signed_int(v,
                                btr->cur_basic_field_type, btr->user.data);
                        BT_LOGV("User function returned: status=%s",
-                               bt_ctf_btr_status_string(status));
-                       if (status != BT_CTF_BTR_STATUS_OK) {
+                               bt_btr_status_string(status));
+                       if (status != BT_BTR_STATUS_OK) {
                                BT_LOGW("User function failed: "
                                        "btr-addr=%p, status=%s",
-                                       btr, bt_ctf_btr_status_string(status));
+                                       btr, bt_btr_status_string(status));
                        }
                }
        } else {
                uint64_t v;
 
-               status = read_unsigned_bitfield(buf, at, field_size, bo, &v);
-               if (status != BT_CTF_BTR_STATUS_OK) {
-                       BT_LOGW("Cannot read unsigned bit array for unsigned integer field: "
-                               "btr-addr=%p, status=%s",
-                               btr, bt_ctf_btr_status_string(status));
-                       goto end;
-               }
+               read_unsigned_bitfield(buf, at, field_size, bo, &v);
 
                if (btr->user.cbs.types.unsigned_int) {
                        BT_LOGV("Calling user function (unsigned integer).");
                        status = btr->user.cbs.types.unsigned_int(v,
                                btr->cur_basic_field_type, btr->user.data);
                        BT_LOGV("User function returned: status=%s",
-                               bt_ctf_btr_status_string(status));
-                       if (status != BT_CTF_BTR_STATUS_OK) {
+                               bt_btr_status_string(status));
+                       if (status != BT_BTR_STATUS_OK) {
                                BT_LOGW("User function failed: "
                                        "btr-addr=%p, status=%s",
-                                       btr, bt_ctf_btr_status_string(status));
+                                       btr, bt_btr_status_string(status));
                        }
                }
        }
 
-end:
-       return status;
-}
-
-static
-enum bt_ctf_btr_status read_basic_int_and_call_cb(struct bt_ctf_btr *btr,
-               const uint8_t *buf, size_t at)
-{
-       return read_basic_int_and_call(btr, buf, at, btr->cur_basic_field_type,
-               btr->cur_basic_field_type);
-}
-
-static
-enum bt_ctf_btr_status read_basic_enum_and_call_cb(struct bt_ctf_btr *btr,
-               const uint8_t *buf, size_t at)
-{
-       struct bt_ctf_field_type *int_field_type;
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
-
-       int_field_type = bt_ctf_field_type_enumeration_get_container_type(
-               btr->cur_basic_field_type);
-       assert(int_field_type);
-       status = read_basic_int_and_call(btr, buf, at,
-               int_field_type, btr->cur_basic_field_type);
-       bt_put(int_field_type);
        return status;
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_type_and_call_continue(struct bt_ctf_btr *btr,
+enum bt_btr_status read_bit_array_type_and_call_continue(struct bt_btr *btr,
                read_basic_and_call_cb_t read_basic_and_call_cb)
 {
        size_t available;
-       int64_t field_size;
-       int64_t needed_bits;
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
+       size_t needed_bits;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
+       struct ctf_field_type_bit_array *ft =
+               (void *) btr->cur_basic_field_type;
 
        if (!at_least_one_bit_left(btr)) {
                BT_LOGV("Reached end of data: btr-addr=%p", btr);
-               status = BT_CTF_BTR_STATUS_EOF;
-               goto end;
-       }
-
-       field_size = get_basic_field_type_size(btr, btr->cur_basic_field_type);
-       if (field_size < 1) {
-               BT_LOGW("Cannot get basic field type's size: "
-                       "btr-addr=%p, ft-addr=%p",
-                       btr, btr->cur_basic_field_type);
-               status = BT_CTF_BTR_STATUS_ERROR;
+               status = BT_BTR_STATUS_EOF;
                goto end;
        }
 
        available = available_bits(btr);
-       needed_bits = field_size - btr->stitch.at;
+       needed_bits = ft->size - btr->stitch.at;
        BT_LOGV("Continuing basic field decoding: "
-               "btr-addr=%p, field-size=%" PRId64 ", needed-size=%" PRId64 ", "
+               "btr-addr=%p, field-size=%u, needed-size=%" PRId64 ", "
                "available-size=%zu",
-               btr, field_size, needed_bits, available);
+               btr, ft->size, needed_bits, available);
        if (needed_bits <= available) {
                /* We have all the bits; append to stitch, then decode */
                stitch_append_from_buf(btr, needed_bits);
                status = read_basic_and_call_cb(btr, btr->stitch.buf,
                        btr->stitch.offset);
-               if (status != BT_CTF_BTR_STATUS_OK) {
+               if (status != BT_BTR_STATUS_OK) {
                        BT_LOGW("Cannot read basic field: "
                                "btr-addr=%p, ft-addr=%p, status=%s",
                                btr, btr->cur_basic_field_type,
-                               bt_ctf_btr_status_string(status));
+                               bt_btr_status_string(status));
                        goto end;
                }
 
@@ -879,58 +704,49 @@ enum bt_ctf_btr_status read_basic_type_and_call_continue(struct bt_ctf_btr *btr,
        /* We are here; it means we don't have enough data to decode this */
        BT_LOGV_STR("Not enough data to read the next basic field: appending to stitch buffer.");
        stitch_append_from_remaining_buf(btr);
-       status = BT_CTF_BTR_STATUS_EOF;
+       status = BT_BTR_STATUS_EOF;
 
 end:
        return status;
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_type_and_call_begin(struct bt_ctf_btr *btr,
+enum bt_btr_status read_bit_array_type_and_call_begin(struct bt_btr *btr,
                read_basic_and_call_cb_t read_basic_and_call_cb)
 {
        size_t available;
-       int64_t field_size;
-       enum bt_ctf_byte_order bo;
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
+       struct ctf_field_type_bit_array *ft =
+               (void *) btr->cur_basic_field_type;
 
        if (!at_least_one_bit_left(btr)) {
                BT_LOGV("Reached end of data: btr-addr=%p", btr);
-               status = BT_CTF_BTR_STATUS_EOF;
-               goto end;
-       }
-
-       field_size = get_basic_field_type_size(btr, btr->cur_basic_field_type);
-       if (field_size < 1) {
-               BT_LOGW("Cannot get basic field type's size: "
-                       "btr-addr=%p, ft-addr=%p",
-                       btr, btr->cur_basic_field_type);
-               status = BT_CTF_BTR_STATUS_ERROR;
+               status = BT_BTR_STATUS_EOF;
                goto end;
        }
 
-       bo = bt_ctf_field_type_get_byte_order(btr->cur_basic_field_type);
-       status = validate_contiguous_bo(btr, bo);
-       if (status != BT_CTF_BTR_STATUS_OK) {
+       status = validate_contiguous_bo(btr, ft->byte_order);
+       if (status != BT_BTR_STATUS_OK) {
                /* validate_contiguous_bo() logs errors */
                goto end;
        }
 
        available = available_bits(btr);
 
-       if (field_size <= available) {
+       if (ft->size <= available) {
                /* We have all the bits; decode and set now */
+               BT_ASSERT(btr->buf.addr);
                status = read_basic_and_call_cb(btr, btr->buf.addr,
                        buf_at_from_addr(btr));
-               if (status != BT_CTF_BTR_STATUS_OK) {
+               if (status != BT_BTR_STATUS_OK) {
                        BT_LOGW("Cannot read basic field: "
                                "btr-addr=%p, ft-addr=%p, status=%s",
                                btr, btr->cur_basic_field_type,
-                               bt_ctf_btr_status_string(status));
+                               bt_btr_status_string(status));
                        goto end;
                }
 
-               consume_bits(btr, field_size);
+               consume_bits(btr, ft->size);
 
                if (stack_empty(btr->stack)) {
                        /* Root is a basic type */
@@ -949,78 +765,63 @@ enum bt_ctf_btr_status read_basic_type_and_call_begin(struct bt_ctf_btr *btr,
        BT_LOGV_STR("Not enough data to read the next basic field: setting stitch buffer.");
        stitch_set_from_remaining_buf(btr);
        btr->state = BTR_STATE_READ_BASIC_CONTINUE;
-       status = BT_CTF_BTR_STATUS_EOF;
+       status = BT_BTR_STATUS_EOF;
 
 end:
        return status;
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_int_type_and_call_begin(
-               struct bt_ctf_btr *btr)
+enum bt_btr_status read_basic_int_type_and_call_begin(
+               struct bt_btr *btr)
 {
-       return read_basic_type_and_call_begin(btr, read_basic_int_and_call_cb);
+       return read_bit_array_type_and_call_begin(btr, read_basic_int_and_call_cb);
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_int_type_and_call_continue(
-               struct bt_ctf_btr *btr)
+enum bt_btr_status read_basic_int_type_and_call_continue(
+               struct bt_btr *btr)
 {
-       return read_basic_type_and_call_continue(btr,
+       return read_bit_array_type_and_call_continue(btr,
                read_basic_int_and_call_cb);
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_float_type_and_call_begin(
-               struct bt_ctf_btr *btr)
+enum bt_btr_status read_basic_float_type_and_call_begin(
+               struct bt_btr *btr)
 {
-       return read_basic_type_and_call_begin(btr,
+       return read_bit_array_type_and_call_begin(btr,
                read_basic_float_and_call_cb);
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_float_type_and_call_continue(
-               struct bt_ctf_btr *btr)
+enum bt_btr_status read_basic_float_type_and_call_continue(
+               struct bt_btr *btr)
 {
-       return read_basic_type_and_call_continue(btr,
+       return read_bit_array_type_and_call_continue(btr,
                read_basic_float_and_call_cb);
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_enum_type_and_call_begin(
-               struct bt_ctf_btr *btr)
-{
-       return read_basic_type_and_call_begin(btr,
-               read_basic_enum_and_call_cb);
-}
-
-static inline
-enum bt_ctf_btr_status read_basic_enum_type_and_call_continue(
-               struct bt_ctf_btr *btr)
-{
-       return read_basic_type_and_call_continue(btr,
-               read_basic_enum_and_call_cb);
-}
-
-static inline
-enum bt_ctf_btr_status read_basic_string_type_and_call(
-               struct bt_ctf_btr *btr, bool begin)
+enum bt_btr_status read_basic_string_type_and_call(
+               struct bt_btr *btr, bool begin)
 {
        size_t buf_at_bytes;
        const uint8_t *result;
        size_t available_bytes;
        const uint8_t *first_chr;
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
 
        if (!at_least_one_bit_left(btr)) {
                BT_LOGV("Reached end of data: btr-addr=%p", btr);
-               status = BT_CTF_BTR_STATUS_EOF;
+               status = BT_BTR_STATUS_EOF;
                goto end;
        }
 
-       assert(buf_at_from_addr(btr) % 8 == 0);
+       BT_ASSERT(buf_at_from_addr(btr) % 8 == 0);
        available_bytes = BITS_TO_BYTES_FLOOR(available_bits(btr));
        buf_at_bytes = BITS_TO_BYTES_FLOOR(buf_at_from_addr(btr));
+       BT_ASSERT(btr->buf.addr);
        first_chr = &btr->buf.addr[buf_at_bytes];
        result = memchr(first_chr, '\0', available_bytes);
 
@@ -1029,10 +830,10 @@ enum bt_ctf_btr_status read_basic_string_type_and_call(
                status = btr->user.cbs.types.string_begin(
                        btr->cur_basic_field_type, btr->user.data);
                BT_LOGV("User function returned: status=%s",
-                       bt_ctf_btr_status_string(status));
-               if (status != BT_CTF_BTR_STATUS_OK) {
+                       bt_btr_status_string(status));
+               if (status != BT_BTR_STATUS_OK) {
                        BT_LOGW("User function failed: btr-addr=%p, status=%s",
-                               btr, bt_ctf_btr_status_string(status));
+                               btr, bt_btr_status_string(status));
                        goto end;
                }
        }
@@ -1046,18 +847,18 @@ enum bt_ctf_btr_status read_basic_string_type_and_call(
                                available_bytes, btr->cur_basic_field_type,
                                btr->user.data);
                        BT_LOGV("User function returned: status=%s",
-                               bt_ctf_btr_status_string(status));
-                       if (status != BT_CTF_BTR_STATUS_OK) {
+                               bt_btr_status_string(status));
+                       if (status != BT_BTR_STATUS_OK) {
                                BT_LOGW("User function failed: "
                                        "btr-addr=%p, status=%s",
-                                       btr, bt_ctf_btr_status_string(status));
+                                       btr, bt_btr_status_string(status));
                                goto end;
                        }
                }
 
                consume_bits(btr, BYTES_TO_BITS(available_bytes));
                btr->state = BTR_STATE_READ_BASIC_CONTINUE;
-               status = BT_CTF_BTR_STATUS_EOF;
+               status = BT_BTR_STATUS_EOF;
        } else {
                /* Found the null character */
                size_t result_len = (size_t) (result - first_chr);
@@ -1069,11 +870,11 @@ enum bt_ctf_btr_status read_basic_string_type_and_call(
                                result_len, btr->cur_basic_field_type,
                                btr->user.data);
                        BT_LOGV("User function returned: status=%s",
-                               bt_ctf_btr_status_string(status));
-                       if (status != BT_CTF_BTR_STATUS_OK) {
+                               bt_btr_status_string(status));
+                       if (status != BT_BTR_STATUS_OK) {
                                BT_LOGW("User function failed: "
                                        "btr-addr=%p, status=%s",
-                                       btr, bt_ctf_btr_status_string(status));
+                                       btr, bt_btr_status_string(status));
                                goto end;
                        }
                }
@@ -1083,11 +884,11 @@ enum bt_ctf_btr_status read_basic_string_type_and_call(
                        status = btr->user.cbs.types.string_end(
                                btr->cur_basic_field_type, btr->user.data);
                        BT_LOGV("User function returned: status=%s",
-                               bt_ctf_btr_status_string(status));
-                       if (status != BT_CTF_BTR_STATUS_OK) {
+                               bt_btr_status_string(status));
+                       if (status != BT_BTR_STATUS_OK) {
                                BT_LOGW("User function failed: "
                                        "btr-addr=%p, status=%s",
-                                       btr, bt_ctf_btr_status_string(status));
+                                       btr, bt_btr_status_string(status));
                                goto end;
                        }
                }
@@ -1110,32 +911,24 @@ end:
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_begin_state(struct bt_ctf_btr *btr)
+enum bt_btr_status read_basic_begin_state(struct bt_btr *btr)
 {
-       enum bt_ctf_btr_status status;
+       enum bt_btr_status status;
 
-       assert(btr->cur_basic_field_type);
+       BT_ASSERT(btr->cur_basic_field_type);
 
-       switch (bt_ctf_field_type_get_type_id(btr->cur_basic_field_type)) {
-       case BT_CTF_FIELD_TYPE_ID_INTEGER:
+       switch (btr->cur_basic_field_type->id) {
+       case CTF_FIELD_TYPE_ID_INT:
+       case CTF_FIELD_TYPE_ID_ENUM:
                status = read_basic_int_type_and_call_begin(btr);
                break;
-       case BT_CTF_FIELD_TYPE_ID_FLOAT:
+       case CTF_FIELD_TYPE_ID_FLOAT:
                status = read_basic_float_type_and_call_begin(btr);
                break;
-       case BT_CTF_FIELD_TYPE_ID_ENUM:
-               status = read_basic_enum_type_and_call_begin(btr);
-               break;
-       case BT_CTF_FIELD_TYPE_ID_STRING:
+       case CTF_FIELD_TYPE_ID_STRING:
                status = read_basic_string_type_and_call(btr, true);
                break;
        default:
-               BT_LOGF("Unknown basic field type ID: "
-                       "btr-addr=%p, ft-addr=%p, ft-id=%s",
-                       btr, btr->cur_basic_field_type,
-                       bt_ctf_field_type_id_string(
-                               bt_ctf_field_type_get_type_id(
-                                       btr->cur_basic_field_type)));
                abort();
        }
 
@@ -1143,32 +936,24 @@ enum bt_ctf_btr_status read_basic_begin_state(struct bt_ctf_btr *btr)
 }
 
 static inline
-enum bt_ctf_btr_status read_basic_continue_state(struct bt_ctf_btr *btr)
+enum bt_btr_status read_basic_continue_state(struct bt_btr *btr)
 {
-       enum bt_ctf_btr_status status;
+       enum bt_btr_status status;
 
-       assert(btr->cur_basic_field_type);
+       BT_ASSERT(btr->cur_basic_field_type);
 
-       switch (bt_ctf_field_type_get_type_id(btr->cur_basic_field_type)) {
-       case BT_CTF_FIELD_TYPE_ID_INTEGER:
+       switch (btr->cur_basic_field_type->id) {
+       case CTF_FIELD_TYPE_ID_INT:
+       case CTF_FIELD_TYPE_ID_ENUM:
                status = read_basic_int_type_and_call_continue(btr);
                break;
-       case BT_CTF_FIELD_TYPE_ID_FLOAT:
+       case CTF_FIELD_TYPE_ID_FLOAT:
                status = read_basic_float_type_and_call_continue(btr);
                break;
-       case BT_CTF_FIELD_TYPE_ID_ENUM:
-               status = read_basic_enum_type_and_call_continue(btr);
-               break;
-       case BT_CTF_FIELD_TYPE_ID_STRING:
+       case CTF_FIELD_TYPE_ID_STRING:
                status = read_basic_string_type_and_call(btr, false);
                break;
        default:
-               BT_LOGF("Unknown basic field type ID: "
-                       "btr-addr=%p, ft-addr=%p, ft-id=%s",
-                       btr, btr->cur_basic_field_type,
-                       bt_ctf_field_type_id_string(
-                               bt_ctf_field_type_get_type_id(
-                                       btr->cur_basic_field_type)));
                abort();
        }
 
@@ -1176,7 +961,7 @@ enum bt_ctf_btr_status read_basic_continue_state(struct bt_ctf_btr *btr)
 }
 
 static inline
-size_t bits_to_skip_to_align_to(struct bt_ctf_btr *btr, size_t align)
+size_t bits_to_skip_to_align_to(struct bt_btr *btr, size_t align)
 {
        size_t aligned_packet_at;
 
@@ -1185,35 +970,24 @@ size_t bits_to_skip_to_align_to(struct bt_ctf_btr *btr, size_t align)
 }
 
 static inline
-enum bt_ctf_btr_status align_type_state(struct bt_ctf_btr *btr,
-               struct bt_ctf_field_type *field_type, enum btr_state next_state)
+enum bt_btr_status align_type_state(struct bt_btr *btr,
+               struct ctf_field_type *field_type, enum btr_state next_state)
 {
-       int field_alignment;
+       unsigned int field_alignment;
        size_t skip_bits;
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
 
        /* Get field's alignment */
-       field_alignment = bt_ctf_field_type_get_alignment(field_type);
-       if (field_alignment < 0) {
-               BT_LOGW("Cannot get field type's alignment: "
-                       "btr-addr=%p, ft-addr=%p, ft-id=%s",
-                       btr, field_type,
-                       bt_ctf_field_type_id_string(
-                               bt_ctf_field_type_get_type_id(field_type)));
-               status = BT_CTF_BTR_STATUS_ERROR;
-               goto end;
-       }
+       field_alignment = field_type->alignment;
 
        /*
         * 0 means "undefined" for variants; what we really want is 1
         * (always aligned)
         */
-       if (field_alignment == 0) {
-               field_alignment = 1;
-       }
+       BT_ASSERT(field_alignment >= 1);
 
        /* Compute how many bits we need to skip */
-       skip_bits = bits_to_skip_to_align_to(btr, field_alignment);
+       skip_bits = bits_to_skip_to_align_to(btr, (size_t) field_alignment);
 
        /* Nothing to skip? aligned */
        if (skip_bits == 0) {
@@ -1223,7 +997,7 @@ enum bt_ctf_btr_status align_type_state(struct bt_ctf_btr *btr,
 
        /* Make sure there's at least one bit left */
        if (!at_least_one_bit_left(btr)) {
-               status = BT_CTF_BTR_STATUS_EOF;
+               status = BT_BTR_STATUS_EOF;
                goto end;
        }
 
@@ -1239,7 +1013,7 @@ enum bt_ctf_btr_status align_type_state(struct bt_ctf_btr *btr,
        } else {
                /* No: need more data */
                BT_LOGV("Reached end of data when aligning: btr-addr=%p", btr);
-               status = BT_CTF_BTR_STATUS_EOF;
+               status = BT_BTR_STATUS_EOF;
        }
 
 end:
@@ -1247,21 +1021,12 @@ end:
 }
 
 static inline
-bool is_compound_type(struct bt_ctf_field_type *field_type)
-{
-       enum bt_ctf_field_type_id id = bt_ctf_field_type_get_type_id(field_type);
-
-       return id == BT_CTF_FIELD_TYPE_ID_STRUCT || id == BT_CTF_FIELD_TYPE_ID_ARRAY ||
-               id == BT_CTF_FIELD_TYPE_ID_SEQUENCE || id == BT_CTF_FIELD_TYPE_ID_VARIANT;
-}
-
-static inline
-enum bt_ctf_btr_status next_field_state(struct bt_ctf_btr *btr)
+enum bt_btr_status next_field_state(struct bt_btr *btr)
 {
        int ret;
        struct stack_entry *top;
-       struct bt_ctf_field_type *next_field_type = NULL;
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
+       struct ctf_field_type *next_field_type = NULL;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
 
        if (stack_empty(btr->stack)) {
                goto end;
@@ -1276,10 +1041,10 @@ enum bt_ctf_btr_status next_field_state(struct bt_ctf_btr *btr)
                        status = btr->user.cbs.types.compound_end(
                                top->base_type, btr->user.data);
                        BT_LOGV("User function returned: status=%s",
-                               bt_ctf_btr_status_string(status));
-                       if (status != BT_CTF_BTR_STATUS_OK) {
+                               bt_btr_status_string(status));
+                       if (status != BT_BTR_STATUS_OK) {
                                BT_LOGW("User function failed: btr-addr=%p, status=%s",
-                                       btr, bt_ctf_btr_status_string(status));
+                                       btr, bt_btr_status_string(status));
                                goto end;
                        }
                }
@@ -1297,29 +1062,24 @@ enum bt_ctf_btr_status next_field_state(struct bt_ctf_btr *btr)
        }
 
        /* Get next field's type */
-       switch (bt_ctf_field_type_get_type_id(top->base_type)) {
-       case BT_CTF_FIELD_TYPE_ID_STRUCT:
-               ret = bt_ctf_field_type_structure_get_field(
-                       top->base_type, NULL, &next_field_type,
-                       top->index);
-               if (ret) {
-                       next_field_type = NULL;
-               }
+       switch (top->base_type->id) {
+       case CTF_FIELD_TYPE_ID_STRUCT:
+               next_field_type = ctf_field_type_struct_borrow_member_by_index(
+                       (void *) top->base_type, (uint64_t) top->index)->ft;
                break;
-       case BT_CTF_FIELD_TYPE_ID_ARRAY:
-               next_field_type =
-                       bt_ctf_field_type_array_get_element_type(
-                               top->base_type);
-               break;
-       case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
-               next_field_type =
-                       bt_ctf_field_type_sequence_get_element_type(
-                               top->base_type);
+       case CTF_FIELD_TYPE_ID_ARRAY:
+       case CTF_FIELD_TYPE_ID_SEQUENCE:
+       {
+               struct ctf_field_type_array_base *array_ft =
+                       (void *) top->base_type;
+
+               next_field_type = array_ft->elem_ft;
                break;
-       case BT_CTF_FIELD_TYPE_ID_VARIANT:
+       }
+       case CTF_FIELD_TYPE_ID_VARIANT:
                /* Variant types are dynamic: query the user, he should know! */
                next_field_type =
-                       btr->user.cbs.query.get_variant_type(
+                       btr->user.cbs.query.borrow_variant_selected_field_type(
                                top->base_type, btr->user.data);
                break;
        default:
@@ -1328,26 +1088,23 @@ enum bt_ctf_btr_status next_field_state(struct bt_ctf_btr *btr)
 
        if (!next_field_type) {
                BT_LOGW("Cannot get the field type of the next field: "
-                       "btr-addr=%p, base-ft-addr=%p, base-ft-id=%s, "
+                       "btr-addr=%p, base-ft-addr=%p, base-ft-id=%d, "
                        "index=%" PRId64,
-                       btr, top->base_type,
-                       bt_ctf_field_type_id_string(
-                               bt_ctf_field_type_get_type_id(top->base_type)),
-                       top->index);
-               status = BT_CTF_BTR_STATUS_ERROR;
+                       btr, top->base_type, top->base_type->id, top->index);
+               status = BT_BTR_STATUS_ERROR;
                goto end;
        }
 
-       if (is_compound_type(next_field_type)) {
+       if (next_field_type->is_compound) {
                if (btr->user.cbs.types.compound_begin) {
                        BT_LOGV("Calling user function (compound, begin).");
                        status = btr->user.cbs.types.compound_begin(
                                next_field_type, btr->user.data);
                        BT_LOGV("User function returned: status=%s",
-                               bt_ctf_btr_status_string(status));
-                       if (status != BT_CTF_BTR_STATUS_OK) {
+                               bt_btr_status_string(status));
+                       if (status != BT_BTR_STATUS_OK) {
                                BT_LOGW("User function failed: btr-addr=%p, status=%s",
-                                       btr, bt_ctf_btr_status_string(status));
+                                       btr, bt_btr_status_string(status));
                                goto end;
                        }
                }
@@ -1355,7 +1112,7 @@ enum bt_ctf_btr_status next_field_state(struct bt_ctf_btr *btr)
                ret = stack_push_with_len(btr, next_field_type);
                if (ret) {
                        /* stack_push_with_len() logs errors */
-                       status = BT_CTF_BTR_STATUS_ERROR;
+                       status = BT_BTR_STATUS_ERROR;
                        goto end;
                }
 
@@ -1367,22 +1124,20 @@ enum bt_ctf_btr_status next_field_state(struct bt_ctf_btr *btr)
                        "btr-addr=%p, cur-basic-ft-addr=%p, "
                        "next-basic-ft-addr=%p",
                        btr, btr->cur_basic_field_type, next_field_type);
-               BT_MOVE(btr->cur_basic_field_type, next_field_type);
+               btr->cur_basic_field_type = next_field_type;
 
                /* Next state: align a basic type */
                btr->state = BTR_STATE_ALIGN_BASIC;
        }
 
 end:
-       BT_PUT(next_field_type);
-
        return status;
 }
 
 static inline
-enum bt_ctf_btr_status handle_state(struct bt_ctf_btr *btr)
+enum bt_btr_status handle_state(struct bt_btr *btr)
 {
-       enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
+       enum bt_btr_status status = BT_BTR_STATUS_OK;
 
        BT_LOGV("Handling state: btr-addr=%p, state=%s",
                btr, btr_state_string(btr->state));
@@ -1410,17 +1165,17 @@ enum bt_ctf_btr_status handle_state(struct bt_ctf_btr *btr)
        }
 
        BT_LOGV("Handled state: btr-addr=%p, status=%s",
-               btr, bt_ctf_btr_status_string(status));
+               btr, bt_btr_status_string(status));
        return status;
 }
 
-struct bt_ctf_btr *bt_ctf_btr_create(struct bt_ctf_btr_cbs cbs, void *data,
-       FILE *err_stream)
+BT_HIDDEN
+struct bt_btr *bt_btr_create(struct bt_btr_cbs cbs, void *data)
 {
-       struct bt_ctf_btr *btr;
+       struct bt_btr *btr;
 
        BT_LOGD_STR("Creating binary type reader (BTR).");
-       btr = g_new0(struct bt_ctf_btr, 1);
+       btr = g_new0(struct bt_btr, 1);
        if (!btr) {
                BT_LOGE_STR("Failed to allocate one binary type reader.");
                goto end;
@@ -1429,7 +1184,7 @@ struct bt_ctf_btr *bt_ctf_btr_create(struct bt_ctf_btr_cbs cbs, void *data,
        btr->stack = stack_new();
        if (!btr->stack) {
                BT_LOGE_STR("Cannot create BTR's stack.");
-               bt_ctf_btr_destroy(btr);
+               bt_btr_destroy(btr);
                btr = NULL;
                goto end;
        }
@@ -1437,37 +1192,35 @@ struct bt_ctf_btr *bt_ctf_btr_create(struct bt_ctf_btr_cbs cbs, void *data,
        btr->state = BTR_STATE_NEXT_FIELD;
        btr->user.cbs = cbs;
        btr->user.data = data;
-       btr->err_stream = err_stream;
        BT_LOGD("Created BTR: addr=%p", btr);
 
 end:
        return btr;
 }
 
-void bt_ctf_btr_destroy(struct bt_ctf_btr *btr)
+BT_HIDDEN
+void bt_btr_destroy(struct bt_btr *btr)
 {
        if (btr->stack) {
                stack_destroy(btr->stack);
        }
 
        BT_LOGD("Destroying BTR: addr=%p", btr);
-       BT_PUT(btr->cur_basic_field_type);
        g_free(btr);
 }
 
 static
-void reset(struct bt_ctf_btr *btr)
+void reset(struct bt_btr *btr)
 {
        BT_LOGD("Resetting BTR: addr=%p", btr);
        stack_clear(btr->stack);
-       BT_PUT(btr->cur_basic_field_type);
        stitch_reset(btr);
        btr->buf.addr = NULL;
-       btr->last_bo = BT_CTF_BYTE_ORDER_UNKNOWN;
+       btr->last_bo = -1;
 }
 
 static
-void update_packet_offset(struct bt_ctf_btr *btr)
+void update_packet_offset(struct bt_btr *btr)
 {
        BT_LOGV("Updating packet offset for next call: "
                "btr-addr=%p, cur-packet-offset=%zu, next-packet-offset=%zu",
@@ -1476,15 +1229,14 @@ void update_packet_offset(struct bt_ctf_btr *btr)
        btr->buf.packet_offset += btr->buf.at;
 }
 
-size_t bt_ctf_btr_start(struct bt_ctf_btr *btr,
-       struct bt_ctf_field_type *type, const uint8_t *buf,
+BT_HIDDEN
+size_t bt_btr_start(struct bt_btr *btr,
+       struct ctf_field_type *type, const uint8_t *buf,
        size_t offset, size_t packet_offset, size_t sz,
-       enum bt_ctf_btr_status *status)
+       enum bt_btr_status *status)
 {
-       assert(btr);
-       assert(buf);
-       assert(sz > 0);
-       assert(BYTES_TO_BITS(sz) > offset);
+       BT_ASSERT(btr);
+       BT_ASSERT(BYTES_TO_BITS(sz) >= offset);
        reset(btr);
        btr->buf.addr = buf;
        btr->buf.offset = offset;
@@ -1492,7 +1244,7 @@ size_t bt_ctf_btr_start(struct bt_ctf_btr *btr,
        btr->buf.packet_offset = packet_offset;
        btr->buf.buf_sz = sz;
        btr->buf.sz = BYTES_TO_BITS(sz) - offset;
-       *status = BT_CTF_BTR_STATUS_OK;
+       *status = BT_BTR_STATUS_OK;
 
        BT_LOGV("Starting decoding: btr-addr=%p, ft-addr=%p, "
                "buf-addr=%p, buf-size=%zu, offset=%zu, "
@@ -1500,7 +1252,7 @@ size_t bt_ctf_btr_start(struct bt_ctf_btr *btr,
                btr, type, buf, sz, offset, packet_offset);
 
        /* Set root type */
-       if (is_compound_type(type)) {
+       if (type->is_compound) {
                /* Compound type: push on visit stack */
                int stack_ret;
 
@@ -1509,10 +1261,10 @@ size_t bt_ctf_btr_start(struct bt_ctf_btr *btr,
                        *status = btr->user.cbs.types.compound_begin(
                                type, btr->user.data);
                        BT_LOGV("User function returned: status=%s",
-                               bt_ctf_btr_status_string(*status));
-                       if (*status != BT_CTF_BTR_STATUS_OK) {
+                               bt_btr_status_string(*status));
+                       if (*status != BT_BTR_STATUS_OK) {
                                BT_LOGW("User function failed: btr-addr=%p, status=%s",
-                                       btr, bt_ctf_btr_status_string(*status));
+                                       btr, bt_btr_status_string(*status));
                                goto end;
                        }
                }
@@ -1520,7 +1272,7 @@ size_t bt_ctf_btr_start(struct bt_ctf_btr *btr,
                stack_ret = stack_push_with_len(btr, type);
                if (stack_ret) {
                        /* stack_push_with_len() logs errors */
-                       *status = BT_CTF_BTR_STATUS_ERROR;
+                       *status = BT_BTR_STATUS_ERROR;
                        goto end;
                }
 
@@ -1528,7 +1280,6 @@ size_t bt_ctf_btr_start(struct bt_ctf_btr *btr,
        } else {
                /* Basic type: set as current basic type */
                btr->cur_basic_field_type = type;
-               bt_get(btr->cur_basic_field_type);
                btr->state = BTR_STATE_ALIGN_BASIC;
        }
 
@@ -1537,9 +1288,8 @@ size_t bt_ctf_btr_start(struct bt_ctf_btr *btr,
 
        while (true) {
                *status = handle_state(btr);
-               if (*status != BT_CTF_BTR_STATUS_OK) {
-                       break;
-               } else if (btr->state == BTR_STATE_DONE) {
+               if (*status != BT_BTR_STATUS_OK ||
+                               btr->state == BTR_STATE_DONE) {
                        break;
                }
        }
@@ -1551,19 +1301,19 @@ end:
        return btr->buf.at;
 }
 
-size_t bt_ctf_btr_continue(struct bt_ctf_btr *btr,
-       const uint8_t *buf, size_t sz,
-       enum bt_ctf_btr_status *status)
+BT_HIDDEN
+size_t bt_btr_continue(struct bt_btr *btr, const uint8_t *buf, size_t sz,
+               enum bt_btr_status *status)
 {
-       assert(btr);
-       assert(buf);
-       assert(sz > 0);
+       BT_ASSERT(btr);
+       BT_ASSERT(buf);
+       BT_ASSERT(sz > 0);
        btr->buf.addr = buf;
        btr->buf.offset = 0;
        btr->buf.at = 0;
        btr->buf.buf_sz = sz;
        btr->buf.sz = BYTES_TO_BITS(sz);
-       *status = BT_CTF_BTR_STATUS_OK;
+       *status = BT_BTR_STATUS_OK;
 
        BT_LOGV("Continuing decoding: btr-addr=%p, buf-addr=%p, buf-size=%zu",
                btr, buf, sz);
@@ -1573,9 +1323,8 @@ size_t bt_ctf_btr_continue(struct bt_ctf_btr *btr,
 
        while (true) {
                *status = handle_state(btr);
-               if (*status != BT_CTF_BTR_STATUS_OK) {
-                       break;
-               } else if (btr->state == BTR_STATE_DONE) {
+               if (*status != BT_BTR_STATUS_OK ||
+                               btr->state == BTR_STATE_DONE) {
                        break;
                }
        }
@@ -1584,3 +1333,12 @@ size_t bt_ctf_btr_continue(struct bt_ctf_btr *btr,
        update_packet_offset(btr);
        return btr->buf.at;
 }
+
+BT_HIDDEN
+void bt_btr_set_unsigned_int_cb(struct bt_btr *btr,
+               bt_btr_unsigned_int_cb_func cb)
+{
+       BT_ASSERT(btr);
+       BT_ASSERT(cb);
+       btr->user.cbs.types.unsigned_int = cb;
+}
This page took 0.048536 seconds and 4 git commands to generate.