1337eca3ab13df44bb89e7ee5903d381dd743a88
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
));
43 if (integer_declaration
->encoding
== CTF_STRING_ASCII
44 || integer_declaration
->encoding
== CTF_STRING_UTF8
) {
46 if (!integer_declaration
->signedness
) {
47 g_string_append_c(pos
->string
,
48 (int) integer_definition
->value
._unsigned
);
50 g_string_append_c(pos
->string
,
51 (int) integer_definition
->value
._signed
);
56 switch (integer_declaration
->base
) {
59 if (!integer_declaration
->signedness
) {
60 fprintf(pos
->fp
, "%" PRIu64
,
61 integer_definition
->value
._unsigned
);
63 fprintf(pos
->fp
, "%" PRId64
,
64 integer_definition
->value
._signed
);
72 if (!integer_declaration
->signedness
)
73 v
= integer_definition
->value
._unsigned
;
75 v
= (uint64_t) integer_definition
->value
._signed
;
77 fprintf(pos
->fp
, "0b");
78 v
= _bt_piecewise_lshift(v
, 64 - integer_declaration
->len
);
79 for (bitnr
= 0; bitnr
< integer_declaration
->len
; bitnr
++) {
80 fprintf(pos
->fp
, "%u", (v
& (1ULL << 63)) ? 1 : 0);
81 v
= _bt_piecewise_lshift(v
, 1);
89 if (!integer_declaration
->signedness
)
90 v
= integer_definition
->value
._unsigned
;
92 v
= (uint64_t) integer_definition
->value
._signed
;
94 fprintf(pos
->fp
, "0%" PRIo64
,
95 integer_definition
->value
._unsigned
);
102 if (!integer_declaration
->signedness
)
103 v
= integer_definition
->value
._unsigned
;
105 v
= (uint64_t) integer_definition
->value
._signed
;
107 fprintf(pos
->fp
, "0x%" PRIX64
,
108 integer_definition
->value
._unsigned
);
This page took 0.031689 seconds and 4 git commands to generate.