2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
7 #include <babeltrace2/babeltrace.h>
8 #include "common/macros.h"
9 #include "common/assert.h"
15 #include "ctf-meta-visitors.hpp"
17 static inline int set_text_array_sequence_field_class(struct ctf_field_class
*fc
)
27 case CTF_FIELD_CLASS_TYPE_STRUCT
:
29 struct ctf_field_class_struct
*struct_fc
= ctf_field_class_as_struct(fc
);
31 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
32 struct ctf_named_field_class
*named_fc
=
33 ctf_field_class_struct_borrow_member_by_index(struct_fc
, i
);
35 ret
= set_text_array_sequence_field_class(named_fc
->fc
);
43 case CTF_FIELD_CLASS_TYPE_VARIANT
:
45 struct ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
47 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
48 struct ctf_named_field_class
*named_fc
=
49 ctf_field_class_variant_borrow_option_by_index(var_fc
, i
);
51 ret
= set_text_array_sequence_field_class(named_fc
->fc
);
59 case CTF_FIELD_CLASS_TYPE_ARRAY
:
60 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
62 struct ctf_field_class_array_base
*array_fc
= ctf_field_class_as_array_base(fc
);
64 if (array_fc
->elem_fc
->type
== CTF_FIELD_CLASS_TYPE_INT
||
65 array_fc
->elem_fc
->type
== CTF_FIELD_CLASS_TYPE_ENUM
) {
66 struct ctf_field_class_int
*int_fc
= ctf_field_class_as_int(array_fc
->elem_fc
);
68 if (int_fc
->base
.base
.alignment
== 8 && int_fc
->base
.size
== 8 &&
69 int_fc
->encoding
== CTF_ENCODING_UTF8
) {
70 array_fc
->is_text
= true;
73 * Force integer element to be unsigned;
74 * this makes the decoder enter a single
75 * path when reading a text
76 * array/sequence and we can safely
77 * decode bytes as characters anyway.
79 int_fc
->is_signed
= false;
83 ret
= set_text_array_sequence_field_class(array_fc
->elem_fc
);
98 int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class
*ctf_tc
)
103 if (!ctf_tc
->is_translated
) {
104 ret
= set_text_array_sequence_field_class(ctf_tc
->packet_header_fc
);
110 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
111 ctf_stream_class
*sc
= (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
];
114 if (!sc
->is_translated
) {
115 ret
= set_text_array_sequence_field_class(sc
->packet_context_fc
);
120 ret
= set_text_array_sequence_field_class(sc
->event_header_fc
);
125 ret
= set_text_array_sequence_field_class(sc
->event_common_context_fc
);
131 for (j
= 0; j
< sc
->event_classes
->len
; j
++) {
132 struct ctf_event_class
*ec
= (ctf_event_class
*) sc
->event_classes
->pdata
[j
];
134 if (ec
->is_translated
) {
138 ret
= set_text_array_sequence_field_class(ec
->spec_context_fc
);
143 ret
= set_text_array_sequence_field_class(ec
->payload_fc
);