4 * Integers read/write functions.
6 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <ctf/ctf-types.h>
28 uint64_t ctf_uint_read(struct stream_pos
*pos
,
29 const struct type_class_integer
*int_class
)
31 int rbo
= (int_class
->byte_order
!= BYTE_ORDER
); /* reverse byte order */
33 align_pos(pos
, int_class
->p
.alignment
);
34 assert(!(pos
->offset
% CHAR_BIT
));
35 switch (int_class
->len
) {
40 v
= *(const uint8_t *)pos
->base
;
41 move_pos(pos
, int_class
->len
);
48 v
= *(const uint16_t *)pos
->base
;
49 move_pos(pos
, int_class
->len
);
50 return rbo
? GUINT16_SWAP_LE_BE(v
) : v
;
56 v
= *(const uint32_t *)pos
->base
;
57 move_pos(pos
, int_class
->len
);
58 return rbo
? GUINT32_SWAP_LE_BE(v
) : v
;
64 v
= *(const uint64_t *)pos
->base
;
65 move_pos(pos
, int_class
->len
);
66 return rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
73 int64_t ctf_int_read(struct stream_pos
*pos
,
74 const struct type_class_integer
*int_class
)
76 int rbo
= (int_class
->byte_order
!= BYTE_ORDER
); /* reverse byte order */
78 align_pos(pos
, int_class
->p
.alignment
);
79 assert(!(pos
->offset
% CHAR_BIT
));
80 switch (int_class
->len
) {
85 v
= *(const int8_t *)pos
->base
;
86 move_pos(pos
, int_class
->len
);
93 v
= *(const int16_t *)pos
->base
;
94 move_pos(pos
, int_class
->len
);
95 return rbo
? GUINT16_SWAP_LE_BE(v
) : v
;
101 v
= *(const int32_t *)pos
->base
;
102 move_pos(pos
, int_class
->len
);
103 return rbo
? GUINT32_SWAP_LE_BE(v
) : v
;
109 v
= *(const int64_t *)pos
->base
;
110 move_pos(pos
, int_class
->len
);
111 return rbo
? GUINT64_SWAP_LE_BE(v
) : v
;
118 void ctf_uint_write(struct stream_pos
*pos
,
119 const struct type_class_integer
*int_class
,
122 int rbo
= (int_class
->byte_order
!= BYTE_ORDER
); /* reverse byte order */
124 align_pos(pos
, int_class
->p
.alignment
);
125 assert(!(pos
->offset
% CHAR_BIT
));
129 switch (int_class
->len
) {
130 case 8: *(uint8_t *) get_pos_addr(pos
) = (uint8_t) v
;
133 *(uint16_t *) get_pos_addr(pos
) = rbo
?
134 GUINT16_SWAP_LE_BE((uint16_t) v
) :
138 *(uint32_t *) get_pos_addr(pos
) = rbo
?
139 GUINT32_SWAP_LE_BE((uint32_t) v
) :
143 *(uint64_t *) get_pos_addr(pos
) = rbo
?
144 GUINT64_SWAP_LE_BE(v
) : v
;
150 move_pos(pos
, int_class
->len
);
153 void ctf_int_write(struct stream_pos
*pos
,
154 const struct type_class_integer
*int_class
,
157 int rbo
= (int_class
->byte_order
!= BYTE_ORDER
); /* reverse byte order */
159 align_pos(pos
, int_class
->p
.alignment
);
160 assert(!(pos
->offset
% CHAR_BIT
));
164 switch (int_class
->len
) {
165 case 8: *(int8_t *) get_pos_addr(pos
) = (int8_t) v
;
168 *(int16_t *) get_pos_addr(pos
) = rbo
?
169 GUINT16_SWAP_LE_BE((int16_t) v
) :
173 *(int32_t *) get_pos_addr(pos
) = rbo
?
174 GUINT32_SWAP_LE_BE((int32_t) v
) :
178 *(int64_t *) get_pos_addr(pos
) = rbo
?
179 GUINT64_SWAP_LE_BE(v
) : v
;
185 move_pos(pos
, int_class
->len
);
This page took 0.033877 seconds and 4 git commands to generate.