457ea804e5133ca1e32488e857b2ad6b0369da9e
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
);
36 if (pos
->field_nr
++ != 0)
37 fprintf(pos
->fp
, ",");
38 fprintf(pos
->fp
, " ");
40 fprintf(pos
->fp
, "%s = ",
41 g_quark_to_string(definition
->name
));
44 && (integer_declaration
->encoding
== CTF_STRING_ASCII
45 || integer_declaration
->encoding
== CTF_STRING_UTF8
)) {
47 if (!integer_declaration
->signedness
) {
48 g_string_append_c(pos
->string
,
49 (int) integer_definition
->value
._unsigned
);
51 g_string_append_c(pos
->string
,
52 (int) integer_definition
->value
._signed
);
57 switch (integer_declaration
->base
) {
60 if (!integer_declaration
->signedness
) {
61 fprintf(pos
->fp
, "%" PRIu64
,
62 integer_definition
->value
._unsigned
);
64 fprintf(pos
->fp
, "%" PRId64
,
65 integer_definition
->value
._signed
);
73 if (!integer_declaration
->signedness
)
74 v
= integer_definition
->value
._unsigned
;
76 v
= (uint64_t) integer_definition
->value
._signed
;
78 fprintf(pos
->fp
, "0b");
79 v
= _bt_piecewise_lshift(v
, 64 - integer_declaration
->len
);
80 for (bitnr
= 0; bitnr
< integer_declaration
->len
; bitnr
++) {
81 fprintf(pos
->fp
, "%u", (v
& (1ULL << 63)) ? 1 : 0);
82 v
= _bt_piecewise_lshift(v
, 1);
90 if (!integer_declaration
->signedness
)
91 v
= integer_definition
->value
._unsigned
;
93 v
= (uint64_t) integer_definition
->value
._signed
;
95 fprintf(pos
->fp
, "0%" PRIo64
,
96 integer_definition
->value
._unsigned
);
103 if (!integer_declaration
->signedness
)
104 v
= integer_definition
->value
._unsigned
;
106 v
= (uint64_t) integer_definition
->value
._signed
;
108 fprintf(pos
->fp
, "0x%" PRIX64
,
109 integer_definition
->value
._unsigned
);
This page took 0.032836 seconds and 4 git commands to generate.