4 * Integers read/write functions.
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/ctf-text/types.h>
23 #include <babeltrace/bitfield.h>
25 int ctf_text_integer_write(struct stream_pos
*ppos
, struct definition
*definition
)
27 struct definition_integer
*integer_definition
=
28 container_of(definition
, struct definition_integer
, p
);
29 const struct declaration_integer
*integer_declaration
=
30 integer_definition
->declaration
;
31 struct ctf_text_stream_pos
*pos
= ctf_text_pos(ppos
);
33 if (!print_field(definition
))
39 if (pos
->field_nr
++ != 0)
40 fprintf(pos
->fp
, ",");
41 fprintf(pos
->fp
, " ");
43 fprintf(pos
->fp
, "%s = ",
44 g_quark_to_string(definition
->name
));
47 && (integer_declaration
->encoding
== CTF_STRING_ASCII
48 || integer_declaration
->encoding
== CTF_STRING_UTF8
)) {
50 if (!integer_declaration
->signedness
) {
51 g_string_append_c(pos
->string
,
52 (int) integer_definition
->value
._unsigned
);
54 g_string_append_c(pos
->string
,
55 (int) integer_definition
->value
._signed
);
60 switch (integer_declaration
->base
) {
63 if (!integer_declaration
->signedness
) {
64 fprintf(pos
->fp
, "%" PRIu64
,
65 integer_definition
->value
._unsigned
);
67 fprintf(pos
->fp
, "%" PRId64
,
68 integer_definition
->value
._signed
);
76 if (!integer_declaration
->signedness
)
77 v
= integer_definition
->value
._unsigned
;
79 v
= (uint64_t) integer_definition
->value
._signed
;
81 fprintf(pos
->fp
, "0b");
82 v
= _bt_piecewise_lshift(v
, 64 - integer_declaration
->len
);
83 for (bitnr
= 0; bitnr
< integer_declaration
->len
; bitnr
++) {
84 fprintf(pos
->fp
, "%u", (v
& (1ULL << 63)) ? 1 : 0);
85 v
= _bt_piecewise_lshift(v
, 1);
93 if (!integer_declaration
->signedness
)
94 v
= integer_definition
->value
._unsigned
;
96 v
= (uint64_t) integer_definition
->value
._signed
;
98 fprintf(pos
->fp
, "0%" PRIo64
,
99 integer_definition
->value
._unsigned
);
106 if (!integer_declaration
->signedness
)
107 v
= integer_definition
->value
._unsigned
;
109 v
= (uint64_t) integer_definition
->value
._signed
;
111 fprintf(pos
->fp
, "0x%" PRIX64
,
112 integer_definition
->value
._unsigned
);
This page took 0.04691 seconds and 4 git commands to generate.