src/cpp-common: add fixed-length integer reading functions
This patch adds `src/cpp-common/read-fixed-len-int.hpp` which offers
function templates to read fixed-length integers from a buffer.
The bt2_common::readFixedLenIntLe() (little endian) and
bt2_common::readFixedLenIntBe() (big endian) function templates accept
one template parameter which is the integral type of the integer to read
(and the return type of the function). For example,
bt2_common::readFixedLenIntLe<std::int32_t>() reads a 32-bit signed
little-endian integer and returns it.
The function templates use bt2_common::littleEndianToNative() and
bt2_common::bigEndianToNative() as needed.
You may combine this with `bt2_common::StdIntT` to have the length in
bits and the signedness as independent template parameters, for
example:
const auto val = readFixedLenIntBe<StdIntT<16, true>>(myBuf);
which is equivalent to:
const auto val = readFixedLenIntBe<std::int16_t>(myBuf);
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9c684bede60f7b6324a3140c5fd498c21ad513ab
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7939
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10840
Tested-by: jenkins <jenkins@lttng.org>
This page took 0.024326 seconds and 4 git commands to generate.