sink.text.pretty: print option fields
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 12 Aug 2019 22:15:04 +0000 (18:15 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 15 Aug 2019 15:41:44 +0000 (11:41 -0400)
The component prints `<none>` when there's no current optional field,
and does the same as a variant field otherwise (printing the optional
field's value between `{` and `}`).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I7a42ca31d68562fa0994945b32dbb2935aa92ee4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1899
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/plugins/text/pretty/print.c

index 1fd168c519868b45b416077d16dc0df41eea2d3b..ea0b165c0260e8c9438e1ab0a81188bffb6f65d5 100644 (file)
@@ -915,6 +915,35 @@ end:
        return ret;
 }
 
+static
+int print_option(struct pretty_component *pretty,
+               const bt_field *option, bool print_names)
+{
+       int ret = 0;
+       const bt_field *field = NULL;
+
+       field = bt_field_option_borrow_field_const(option);
+       if (field) {
+               bt_common_g_string_append(pretty->string, "{ ");
+               pretty->depth++;
+               if (print_names) {
+                       // TODO: find tag's name using field path
+                       // print_field_name_equal(pretty, tag_choice);
+               }
+               ret = print_field(pretty, field, print_names);
+               if (ret != 0) {
+                       goto end;
+               }
+               pretty->depth--;
+               bt_common_g_string_append(pretty->string, " }");
+       } else {
+               bt_common_g_string_append(pretty->string, "<none>");
+       }
+
+end:
+       return ret;
+}
+
 static
 int print_variant(struct pretty_component *pretty,
                const bt_field *variant, bool print_names)
@@ -1009,6 +1038,8 @@ int print_field(struct pretty_component *pretty,
        }
        case BT_FIELD_CLASS_TYPE_STRUCTURE:
                return print_struct(pretty, field, print_names);
+       case BT_FIELD_CLASS_TYPE_OPTION:
+               return print_option(pretty, field, print_names);
        case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
        case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
        case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
This page took 0.026651 seconds and 4 git commands to generate.