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)
class_id = bt_field_get_class_type(field);
switch (class_id) {
+ case BT_FIELD_CLASS_TYPE_BOOL:
+ {
+ bt_bool v;
+ const char *text;
+
+ v = bt_field_bool_get_value(field);
+ if (pretty->use_colors) {
+ bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE);
+ }
+ if (v) {
+ text = "true";
+ } else {
+ text = "false";
+ }
+ bt_common_g_string_append(pretty->string, text);
+ if (pretty->use_colors) {
+ bt_common_g_string_append(pretty->string, COLOR_RST);
+ }
+ return 0;
+ }
+ case BT_FIELD_CLASS_TYPE_BIT_ARRAY:
+ {
+ uint64_t v = bt_field_bit_array_get_value_as_integer(field);
+
+ if (pretty->use_colors) {
+ bt_common_g_string_append(pretty->string,
+ COLOR_NUMBER_VALUE);
+ }
+ bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64,
+ v);
+ if (pretty->use_colors) {
+ bt_common_g_string_append(pretty->string, COLOR_RST);
+ }
+ return 0;
+ }
case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
return print_integer(pretty, field);
- case BT_FIELD_CLASS_TYPE_REAL:
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
{
double v;
- v = bt_field_real_get_value(field);
+ if (class_id == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
+ v = (float) bt_field_real_single_precision_get_value(field);
+ } else {
+ v = bt_field_real_double_precision_get_value(field);
+ }
+
if (pretty->use_colors) {
bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE);
}
}
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: