Commit | Line | Data |
---|---|---|
fc93b2bd MD |
1 | /* |
2 | * BabelTrace - Integer Type Converter | |
3 | * | |
4 | * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2.1 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include <babeltrace/compiler.h> | |
22 | #include <stdint.h> | |
23 | ||
24 | size_t copy_integer(unsigned char *dest, const struct format *fdest, | |
25 | const unsigned char *src, const struct format *fsrc, | |
26 | const struct type_class *type_class) | |
27 | { | |
28 | struct type_class_integer *int_class = | |
29 | container_of(type_class, struct type_class_integer, p); | |
30 | ||
31 | if (!int_class->signedness) { | |
32 | uint64_t v; | |
33 | ||
34 | v = fsrc->uint_read(src, int_class->byte_order, int_class->len); | |
35 | return fdest->uint_write(dest, int_class->byte_order, | |
36 | int_class->len, v); | |
37 | } else { | |
38 | int64_t v; | |
39 | ||
40 | v = fsrc->int_read(src, int_class->byte_order, int_class->len); | |
41 | return fdest->int_write(dest, int_class->byte_order, | |
42 | int_class->len, v); | |
43 | } | |
44 | } |