Common Trace Format - initial commit
[babeltrace.git] / include / ctf / ctf-types-bitfield.h
1 #ifndef _CTF_TYPES_BITFIELD_H
2 #define _CTF_TYPES_BITFIELD_H
3
4 /*
5 * Common Trace Format
6 *
7 * Bitfields read/write functions.
8 *
9 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * Dual LGPL v2.1/GPL v2 license.
12 */
13
14 #include <ctf/bitfield.h>
15 #include <endian.h>
16
17 /*
18 * ctf_bitfield_unsigned_read and ctf_bitfield_signed_read are defined by
19 * bitfield.h.
20 *
21 * The write primitives below are provided as wrappers over
22 * ctf_bitfield_write_le and ctf_bitfield_write_be to specify per-byte write of
23 * signed/unsigned integers through a standard API.
24 */
25
26 static inline
27 size_t ctf_bitfield_unsigned_write(uint8_t *ptr,
28 unsigned long start, unsigned long len,
29 int byte_order, uint64_t v)
30 {
31 if (!ptr)
32 goto end;
33 if (byte_order == LITTLE_ENDIAN)
34 ctf_bitfield_write_le(ptr, start, len, v);
35 else
36 ctf_bitfield_write_be(ptr, start, len, v);
37 end:
38 return len;
39 }
40
41 static inline
42 size_t ctf_bitfield_signed_write(uint8_t *ptr,
43 unsigned long start, unsigned long len,
44 int byte_order, int64_t v)
45 {
46 if (!ptr)
47 goto end;
48 if (byte_order == LITTLE_ENDIAN)
49 ctf_bitfield_write_le(ptr, start, len, v);
50 else
51 ctf_bitfield_write_be(ptr, start, len, v);
52 end:
53 return len;
54 }
55
56 #endif /* _CTF_TYPES_BITFIELD_H */
This page took 0.030631 seconds and 5 git commands to generate.