Bitfields: allow per-word read on native endianness
[babeltrace.git] / include / ctf / ctf-types-bitfield.h
index 4657a28fa7d4bbf035d26d4458e92d29503c535c..a6764bf5bdb72ab1f94dd5d9f050870dbfa1c8ce 100644 (file)
 #include <ctf/bitfield.h>
 #include <endian.h>
 
-/*
- * ctf_bitfield_unsigned_read and ctf_bitfield_signed_read are defined by
- * bitfield.h.
- *
- * The write primitives below are provided as wrappers over
- * ctf_bitfield_write_le and ctf_bitfield_write_be to specify per-byte write of
- * signed/unsigned integers through a standard API.
- */
+static inline
+uint64_t ctf_bitfield_unsigned_read(const uint8_t *ptr,
+                                   unsigned long start, unsigned long len,
+                                   int byte_order)
+{
+       uint64_t v;
+
+       if (byte_order == LITTLE_ENDIAN)
+               ctf_bitfield_read_le(ptr, start, len, &v);
+       else
+               ctf_bitfield_read_be(ptr, start, len, &v);
+       return v;
+}
+
+static inline
+int64_t ctf_bitfield_signed_read(const uint8_t *ptr,
+                                unsigned long start, unsigned long len,
+                                int byte_order)
+{
+       int64_t v;
+
+       if (byte_order == LITTLE_ENDIAN)
+               ctf_bitfield_read_le(ptr, start, len, &v);
+       else
+               ctf_bitfield_read_be(ptr, start, len, &v);
+       return v;
+}
 
 static inline
 size_t ctf_bitfield_unsigned_write(uint8_t *ptr,
This page took 0.022755 seconds and 4 git commands to generate.