Commit | Line | Data |
---|---|---|
6dc2ca62 MD |
1 | /* |
2 | * Common Trace Format | |
3 | * | |
4 | * Enumeration mapping strings (quarks) from/to integers. | |
5 | * | |
de0ba614 | 6 | * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
6dc2ca62 | 7 | * |
de0ba614 MD |
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. | |
12 | * | |
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. | |
17 | * | |
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 | |
6dc2ca62 MD |
21 | */ |
22 | ||
d79865b9 | 23 | #include <babeltrace/ctf/types.h> |
6dc2ca62 MD |
24 | #include <stdint.h> |
25 | #include <glib.h> | |
26 | ||
448d3cc7 MD |
27 | GQuark ctf_enum_read(const unsigned char *ptr, |
28 | const struct type_class_enum *src) | |
29 | { | |
30 | struct type_class_bitfield *bitfield_class = &src->p; | |
31 | struct type_class_integer *int_class = &bitfield_class->p; | |
32 | ||
33 | if (!int_class->signedness) { | |
34 | uint64_t v; | |
35 | ||
36 | v = ctf_bitfield_unsigned_read(src, | |
37 | bitfield_class->start_offset, | |
38 | int_class->len, | |
39 | int_class->byte_order); | |
40 | return enum_uint_to_quark(src, v); | |
41 | } else { | |
42 | int64_t v; | |
43 | ||
44 | v = fsrc->bitfield_signed_read(src, | |
45 | bitfield_class->start_offset, | |
46 | int_class->len, | |
47 | int_class->byte_order); | |
48 | return enum_int_to_quark(src, v); | |
49 | } | |
50 | } | |
51 | ||
52 | size_t ctf_enum_write(unsigned char *ptr, const struct type_class_enum *dest, | |
53 | GQuark q) | |
54 | { | |
55 | struct type_class_bitfield *bitfield_class = &dest->p; | |
56 | struct type_class_integer *int_class = &bitfield_class->p; | |
57 | ||
58 | if (!int_class->signedness) { | |
59 | uint64_t v; | |
60 | ||
61 | v = enum_quark_to_uint(dest, q); | |
62 | return ctf_bitfield_unsigned_write(src, | |
63 | bitfield_class->start_offset, | |
64 | int_class->len, | |
65 | int_class->byte_order, v); | |
66 | } else { | |
67 | int64_t v; | |
68 | ||
69 | v = enum_quark_to_int(dest, q); | |
70 | return ctf_bitfield_signed_write(src, | |
71 | bitfield_class->start_offset, | |
72 | int_class->len, | |
73 | int_class->byte_order, v); | |
74 | } | |
6dc2ca62 | 75 | } |