lib: add internal bt_field_sequence_get_int_length()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 13 Feb 2018 22:17:31 +0000 (17:17 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 03:32:03 +0000 (23:32 -0400)
This new internal helper returns a sequence field's length as an
`int64_t` value instead of returning the integer field. Returns a
negative value on error or if the sequence fields's length field is not
set.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/babeltrace/ctf-ir/fields-internal.h
lib/ctf-ir/fields.c

index 43e79b72b7527d23c67c0721f1569f94f350482f..6c25b26ca4d61b5656ac1ce80968fffd355303c8 100644 (file)
@@ -102,4 +102,7 @@ int bt_field_serialize(struct bt_field *field,
 BT_HIDDEN
 void bt_field_freeze(struct bt_field *field);
 
+BT_HIDDEN
+int64_t bt_field_sequence_get_int_length(struct bt_field *field);
+
 #endif /* BABELTRACE_CTF_IR_FIELDS_INTERNAL_H */
index 1525934ed2703316e7841d73a44d8f2966f73896..0fe5630e232d400b8efed96fd5c54a38d0650a91 100644 (file)
@@ -406,6 +406,27 @@ bt_bool bt_field_is_variant(struct bt_field *field)
        return bt_field_get_type_id(field) == BT_FIELD_TYPE_ID_VARIANT;
 }
 
+BT_HIDDEN
+int64_t bt_field_sequence_get_int_length(struct bt_field *field)
+{
+       struct bt_field_sequence *sequence;
+       int64_t ret;
+
+       assert(field);
+       assert(bt_field_type_get_type_id(field->type) ==
+               BT_FIELD_TYPE_ID_SEQUENCE);
+       sequence = container_of(field, struct bt_field_sequence, parent);
+       if (!sequence->length) {
+               ret = -1;
+               goto end;
+       }
+
+       ret = (int64_t) sequence->elements->len;
+
+end:
+       return ret;
+}
+
 struct bt_field *bt_field_sequence_get_length(
                struct bt_field *field)
 {
This page took 0.02595 seconds and 4 git commands to generate.