Bitfields: allow per-word read on native endianness
[babeltrace.git] / include / ctf / ctf-types-bitfield.h
CommitLineData
6dc2ca62
MD
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
08228826
MD
17static inline
18uint64_t ctf_bitfield_unsigned_read(const uint8_t *ptr,
19 unsigned long start, unsigned long len,
20 int byte_order)
21{
22 uint64_t v;
23
24 if (byte_order == LITTLE_ENDIAN)
25 ctf_bitfield_read_le(ptr, start, len, &v);
26 else
27 ctf_bitfield_read_be(ptr, start, len, &v);
28 return v;
29}
30
31static inline
32int64_t ctf_bitfield_signed_read(const uint8_t *ptr,
33 unsigned long start, unsigned long len,
34 int byte_order)
35{
36 int64_t v;
37
38 if (byte_order == LITTLE_ENDIAN)
39 ctf_bitfield_read_le(ptr, start, len, &v);
40 else
41 ctf_bitfield_read_be(ptr, start, len, &v);
42 return v;
43}
6dc2ca62
MD
44
45static inline
46size_t ctf_bitfield_unsigned_write(uint8_t *ptr,
47 unsigned long start, unsigned long len,
48 int byte_order, uint64_t v)
49{
50 if (!ptr)
51 goto end;
52 if (byte_order == LITTLE_ENDIAN)
53 ctf_bitfield_write_le(ptr, start, len, v);
54 else
55 ctf_bitfield_write_be(ptr, start, len, v);
56end:
57 return len;
58}
59
60static inline
61size_t ctf_bitfield_signed_write(uint8_t *ptr,
62 unsigned long start, unsigned long len,
63 int byte_order, int64_t v)
64{
65 if (!ptr)
66 goto end;
67 if (byte_order == LITTLE_ENDIAN)
68 ctf_bitfield_write_le(ptr, start, len, v);
69 else
70 ctf_bitfield_write_be(ptr, start, len, v);
71end:
72 return len;
73}
74
75#endif /* _CTF_TYPES_BITFIELD_H */
This page took 0.02517 seconds and 4 git commands to generate.