- unsigned char *uuid = trace->uuid;
- int ret = 0;
-
- if (trace->native_byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
- BT_LOGW("Invalid parameter: trace's byte order cannot be BT_CTF_BYTE_ORDER_NATIVE at this point; "
- "set it with bt_ctf_trace_set_native_byte_order(): "
- "addr=%p, name=\"%s\"",
- trace, bt_ctf_trace_get_name(trace));
- ret = -1;
- goto end;
- }
-
- g_string_append(context->string, "trace {\n");
- g_string_append(context->string, "\tmajor = 1;\n");
- g_string_append(context->string, "\tminor = 8;\n");
- assert(trace->native_byte_order == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN ||
- trace->native_byte_order == BT_CTF_BYTE_ORDER_BIG_ENDIAN ||
- trace->native_byte_order == BT_CTF_BYTE_ORDER_NETWORK);
-
- if (trace->uuid_set) {
- g_string_append_printf(context->string,
- "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
- }
-
- g_string_append_printf(context->string, "\tbyte_order = %s;\n",
- get_byte_order_string(trace->native_byte_order));
-
- if (trace->packet_header_type) {
- g_string_append(context->string, "\tpacket.header := ");
- context->current_indentation_level++;
- g_string_assign(context->field_name, "");
- BT_LOGD_STR("Serializing trace's packet header field type's metadata.");
- ret = bt_ctf_field_type_serialize(trace->packet_header_type,
- context);
- if (ret) {
- goto end;
- }
- context->current_indentation_level--;
- }
-
- g_string_append(context->string, ";\n};\n\n");
-end:
- return ret;
-}
-
-static
-void append_env_metadata(struct bt_ctf_trace *trace,
- struct metadata_context *context)
-{
- int64_t i;
- int64_t env_size;
-
- env_size = bt_ctf_attributes_get_count(trace->environment);
- if (env_size <= 0) {
- return;
- }
-
- g_string_append(context->string, "env {\n");
-
- for (i = 0; i < env_size; i++) {
- struct bt_value *env_field_value_obj = NULL;
- const char *entry_name;
-
- entry_name = bt_ctf_attributes_get_field_name(
- trace->environment, i);
- env_field_value_obj = bt_ctf_attributes_get_field_value(
- trace->environment, i);
-
- assert(entry_name);
- assert(env_field_value_obj);
-
- switch (bt_value_get_type(env_field_value_obj)) {
- case BT_VALUE_TYPE_INTEGER:
- {
- int ret;
- int64_t int_value;
-
- ret = bt_value_integer_get(env_field_value_obj,
- &int_value);
- assert(ret == 0);
- g_string_append_printf(context->string,
- "\t%s = %" PRId64 ";\n", entry_name,
- int_value);
- break;
- }
- case BT_VALUE_TYPE_STRING:
- {
- int ret;
- const char *str_value;
- char *escaped_str = NULL;
-
- ret = bt_value_string_get(env_field_value_obj,
- &str_value);
- assert(ret == 0);
- escaped_str = g_strescape(str_value, NULL);
- if (!escaped_str) {
- BT_LOGE("Cannot escape string: string=\"%s\"",
- str_value);
- goto loop_next;
- }
-
- g_string_append_printf(context->string,
- "\t%s = \"%s\";\n", entry_name, escaped_str);
- free(escaped_str);
- break;
- }
- default:
- goto loop_next;
- }
-
-loop_next:
- BT_PUT(env_field_value_obj);
- }
-
- g_string_append(context->string, "};\n\n");