Move to babeltrace namespace
[babeltrace.git] / include / babeltrace / ctf / types-bitfield.h
1 #ifndef _BABELTRACE_CTF_TYPES_BITFIELD_H
2 #define _BABELTRACE_CTF_TYPES_BITFIELD_H
3
4 /*
5 * Common Trace Format
6 *
7 * Bitfields read/write functions.
8 *
9 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #include <ctf/bitfield.h>
27 #include <endian.h>
28
29 static inline
30 uint64_t ctf_bitfield_unsigned_read(const unsigned char *ptr,
31 unsigned long start, unsigned long len,
32 int byte_order)
33 {
34 uint64_t v;
35
36 if (byte_order == LITTLE_ENDIAN)
37 ctf_bitfield_read_le(ptr, start, len, &v);
38 else
39 ctf_bitfield_read_be(ptr, start, len, &v);
40 return v;
41 }
42
43 static inline
44 int64_t ctf_bitfield_signed_read(const unsigned char *ptr,
45 unsigned long start, unsigned long len,
46 int byte_order)
47 {
48 int64_t v;
49
50 if (byte_order == LITTLE_ENDIAN)
51 ctf_bitfield_read_le(ptr, start, len, &v);
52 else
53 ctf_bitfield_read_be(ptr, start, len, &v);
54 return v;
55 }
56
57 static inline
58 size_t ctf_bitfield_unsigned_write(unsigned char *ptr,
59 unsigned long start, unsigned long len,
60 int byte_order, uint64_t v)
61 {
62 if (!ptr)
63 goto end;
64 if (byte_order == LITTLE_ENDIAN)
65 ctf_bitfield_write_le(ptr, start, len, v);
66 else
67 ctf_bitfield_write_be(ptr, start, len, v);
68 end:
69 return len;
70 }
71
72 static inline
73 size_t ctf_bitfield_signed_write(unsigned char *ptr,
74 unsigned long start, unsigned long len,
75 int byte_order, int64_t v)
76 {
77 if (!ptr)
78 goto end;
79 if (byte_order == LITTLE_ENDIAN)
80 ctf_bitfield_write_le(ptr, start, len, v);
81 else
82 ctf_bitfield_write_be(ptr, start, len, v);
83 end:
84 return len;
85 }
86
87 #endif /* _BABELTRACE_CTF_TYPES_BITFIELD_H */
This page took 0.044036 seconds and 4 git commands to generate.