2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
9 #include "ctf-meta-visitors.hpp"
11 static inline int set_text_array_sequence_field_class(struct ctf_field_class
*fc
)
21 case CTF_FIELD_CLASS_TYPE_STRUCT
:
23 struct ctf_field_class_struct
*struct_fc
= ctf_field_class_as_struct(fc
);
25 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
26 struct ctf_named_field_class
*named_fc
=
27 ctf_field_class_struct_borrow_member_by_index(struct_fc
, i
);
29 ret
= set_text_array_sequence_field_class(named_fc
->fc
);
37 case CTF_FIELD_CLASS_TYPE_VARIANT
:
39 struct ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
41 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
42 struct ctf_named_field_class
*named_fc
=
43 ctf_field_class_variant_borrow_option_by_index(var_fc
, i
);
45 ret
= set_text_array_sequence_field_class(named_fc
->fc
);
53 case CTF_FIELD_CLASS_TYPE_ARRAY
:
54 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
56 struct ctf_field_class_array_base
*array_fc
= ctf_field_class_as_array_base(fc
);
58 if (array_fc
->elem_fc
->type
== CTF_FIELD_CLASS_TYPE_INT
||
59 array_fc
->elem_fc
->type
== CTF_FIELD_CLASS_TYPE_ENUM
) {
60 struct ctf_field_class_int
*int_fc
= ctf_field_class_as_int(array_fc
->elem_fc
);
62 if (int_fc
->base
.base
.alignment
== 8 && int_fc
->base
.size
== 8 &&
63 int_fc
->encoding
== CTF_ENCODING_UTF8
) {
64 array_fc
->is_text
= true;
67 * Force integer element to be unsigned;
68 * this makes the decoder enter a single
69 * path when reading a text
70 * array/sequence and we can safely
71 * decode bytes as characters anyway.
73 int_fc
->is_signed
= false;
77 ret
= set_text_array_sequence_field_class(array_fc
->elem_fc
);
92 int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class
*ctf_tc
)
97 if (!ctf_tc
->is_translated
) {
98 ret
= set_text_array_sequence_field_class(ctf_tc
->packet_header_fc
);
104 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
105 ctf_stream_class
*sc
= (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
];
108 if (!sc
->is_translated
) {
109 ret
= set_text_array_sequence_field_class(sc
->packet_context_fc
);
114 ret
= set_text_array_sequence_field_class(sc
->event_header_fc
);
119 ret
= set_text_array_sequence_field_class(sc
->event_common_context_fc
);
125 for (j
= 0; j
< sc
->event_classes
->len
; j
++) {
126 struct ctf_event_class
*ec
= (ctf_event_class
*) sc
->event_classes
->pdata
[j
];
128 if (ec
->is_translated
) {
132 ret
= set_text_array_sequence_field_class(ec
->spec_context_fc
);
137 ret
= set_text_array_sequence_field_class(ec
->payload_fc
);