Fix: re-introduce basic type serialization functions
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 11 Mar 2021 21:33:45 +0000 (16:33 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 11 Mar 2021 21:51:11 +0000 (16:51 -0500)
The basic type serialization functions were removed by mistake in the
recent type cleanup. Add them back, but targeting the new (non-legacy)
field members rather than the legacy field members which are now
removed.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I36ab9f8354982c9208eb0acd8a7d62ba4fbb85a1

liblttng-ust-comm/lttng-ust-comm.c

index 2cab469eb7cf0558cfe71be942448a8549fd4267..21adf1831731dbd919ac6faacf99109ef1361ed0 100644 (file)
@@ -949,6 +949,43 @@ ssize_t count_ctx_fields_recursive(size_t nr_fields,
        return count;
 }
 
+static
+int serialize_string_encoding(int32_t *ue,
+               enum lttng_string_encodings le)
+{
+       switch (le) {
+       case lttng_encode_none:
+               *ue = ustctl_encode_none;
+               break;
+       case lttng_encode_UTF8:
+               *ue = ustctl_encode_UTF8;
+               break;
+       case lttng_encode_ASCII:
+               *ue = ustctl_encode_ASCII;
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static
+int serialize_integer_type(struct ustctl_integer_type *uit,
+               const struct lttng_integer_type *lit)
+{
+       int32_t encoding;
+
+       uit->size = lit->size;
+       uit->signedness = lit->signedness;
+       uit->reverse_byte_order = lit->reverse_byte_order;
+       uit->base = lit->base;
+       if (serialize_string_encoding(&encoding, lit->encoding))
+               return -EINVAL;
+       uit->encoding = encoding;
+       uit->alignment = lit->alignment;
+       return 0;
+}
+
 static
 int serialize_dynamic_type(struct lttng_session *session,
                struct ustctl_field *fields, size_t *iter_output,
@@ -1022,8 +1059,66 @@ int serialize_one_type(struct lttng_session *session,
 
        switch (lt->atype) {
        case atype_integer:
+       {
+               struct ustctl_field *uf = &fields[*iter_output];
+               struct ustctl_type *ut = &uf->type;
+
+               if (field_name) {
+                       strncpy(uf->name, field_name, LTTNG_UST_SYM_NAME_LEN);
+                       uf->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+               } else {
+                       uf->name[0] = '\0';
+               }
+               ret = serialize_integer_type(&ut->u.integer, &lt->u.integer);
+               if (ret)
+                       return ret;
+               ut->atype = ustctl_atype_integer;
+               (*iter_output)++;
+               break;
+       }
        case atype_float:
+       {
+               struct ustctl_field *uf = &fields[*iter_output];
+               struct ustctl_type *ut = &uf->type;
+               struct ustctl_float_type *uft;
+               const struct lttng_float_type *lft;
+
+               if (field_name) {
+                       strncpy(uf->name, field_name, LTTNG_UST_SYM_NAME_LEN);
+                       uf->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+               } else {
+                       uf->name[0] = '\0';
+               }
+               uft = &ut->u._float;
+               lft = &lt->u._float;
+               uft->exp_dig = lft->exp_dig;
+               uft->mant_dig = lft->mant_dig;
+               uft->alignment = lft->alignment;
+               uft->reverse_byte_order = lft->reverse_byte_order;
+               ut->atype = ustctl_atype_float;
+               (*iter_output)++;
+               break;
+       }
        case atype_string:
+       {
+               struct ustctl_field *uf = &fields[*iter_output];
+               struct ustctl_type *ut = &uf->type;
+               int32_t encoding;
+
+               if (field_name) {
+                       strncpy(uf->name, field_name, LTTNG_UST_SYM_NAME_LEN);
+                       uf->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+               } else {
+                       uf->name[0] = '\0';
+               }
+               ret = serialize_string_encoding(&encoding, lt->u.string.encoding);
+               if (ret)
+                       return ret;
+               ut->u.string.encoding = encoding;
+               ut->atype = ustctl_atype_string;
+               (*iter_output)++;
+               break;
+       }
        case atype_array_nestable:
        {
                struct ustctl_field *uf = &fields[*iter_output];
This page took 0.026864 seconds and 4 git commands to generate.