Fix: get encoding for char arrays and sequences
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 11 Sep 2012 02:01:58 +0000 (22:01 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 11 Sep 2012 02:01:58 +0000 (22:01 -0400)
The bt_ctf_get_encoding works for strings and integer, but not for char
arrays or sequences. For these compound types, we need to return the
encoding of the integer contained inside. This patch adds the support of
char arrays and sequences.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/events.c
include/babeltrace/ctf/events.h

index 7619de74b9ac85993e4132325822ed2431b1045f..b837b128393baf87905c81b28fc444cb2f434c42 100644 (file)
@@ -373,6 +373,14 @@ get_declaration_array(const struct declaration *decl)
        return container_of(decl, const struct declaration_array, p);
 }
 
+static const struct declaration_sequence *
+get_declaration_sequence(const struct declaration *decl)
+{
+       if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_SEQUENCE)
+               return NULL;
+       return container_of(decl, const struct declaration_sequence, p);
+}
+
 int bt_ctf_get_int_signedness(const struct declaration *decl)
 {
        const struct declaration_integer *integer;
@@ -472,27 +480,49 @@ const char *bt_ctf_get_enum_str(const struct definition *field)
 enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl)
 {
        enum ctf_string_encoding ret = 0;
+       enum ctf_type_id type;
        const struct declaration_integer *integer;
        const struct declaration_string *string;
+       const struct declaration_array *array;
+       const struct declaration_sequence *sequence;
 
        if (!decl)
                goto error;
 
-       if (bt_ctf_field_type(decl) == CTF_TYPE_INTEGER) {
-               integer = get_declaration_integer(decl);
-               if (integer) {
-                       ret = integer->encoding;
-               } else {
+       type = bt_ctf_field_type(decl);
+
+       switch (type) {
+       case CTF_TYPE_ARRAY:
+               array = get_declaration_array(decl);
+               if (!array)
                        goto error;
-               }
-       } else if (bt_ctf_field_type(decl) == CTF_TYPE_STRING) {
+               integer = get_declaration_integer(array->elem);
+               if (!integer)
+                       goto error;
+               ret = integer->encoding;
+               break;
+       case CTF_TYPE_SEQUENCE:
+               sequence = get_declaration_sequence(decl);
+               if (!sequence)
+                       goto error;
+               integer = get_declaration_integer(sequence->elem);
+               if (!integer)
+                       goto error;
+               ret = integer->encoding;
+               break;
+       case CTF_TYPE_STRING:
                string = get_declaration_string(decl);
-               if (string) {
-                       ret = string->encoding;
-               } else {
+               if (!string)
                        goto error;
-               }
-       } else {
+               ret = string->encoding;
+               break;
+       case CTF_TYPE_INTEGER:
+               integer = get_declaration_integer(decl);
+               if (!integer)
+                       goto error;
+               ret = integer->encoding;
+               break;
+       default:
                goto error;
        }
        return ret;
index e4074037ac0430125efa1494b1846e6caaa912a8..461cf06ccdd9c63040e45719f1a48b88154e6f29 100644 (file)
@@ -191,7 +191,8 @@ int bt_ctf_get_int_byte_order(const struct declaration *decl);
 ssize_t bt_ctf_get_int_len(const struct declaration *decl);
 
 /*
- * bt_ctf_get_encoding: return the encoding of an int or a string.
+ * bt_ctf_get_encoding: return the encoding of an int, a string, or of
+ * the integer contained in a char array or a sequence.
  * return a negative value on error
  */
 enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl);
This page took 0.025513 seconds and 4 git commands to generate.