25template <
typename u
int_t>
27readUint(
void const*
const buffer,
size_t const length) {
28 constexpr size_t size(
sizeof(uint_t));
31 << size <<
"-byte integer, but got " << length <<
" byte"
32 << (length == 1 ?
"" :
"s") <<
" instead");
35 uint8_t
const*
const byte_buffer(
static_cast<uint8_t const*
>(buffer));
38 for (
size_t i = 0; i < size; ++i) {
39 result |= (
static_cast<uint_t
>(byte_buffer[i])) << (8 * (size - (i + 1)));
54template <
typename u
int_t>
56writeUint(uint_t
const value,
void*
const buffer,
size_t const length) {
57 constexpr size_t size(
sizeof(uint_t));
60 << size <<
"-byte integer, but got " << length <<
" byte"
61 << (length == 1 ?
"" :
"s") <<
" instead");
64 uint8_t* byte_buffer(
static_cast<uint8_t*
>(buffer));
66 for (
size_t i = 0; i < size; ++i) {
67 uint8_t
const shift_by(8 * (size - (i + 1)));
68 byte_buffer[i] = uint8_t((value & (uint_t(0xff) << shift_by)) >> shift_by);
71 return (byte_buffer + size);
76readUint16(
void const*
const buffer,
size_t const length) {
77 return (readUint<uint16_t>(buffer, length));
82readUint32(
void const*
const buffer,
size_t const length) {
83 return (readUint<uint32_t>(buffer, length));
88readUint64(
void const*
const buffer,
size_t const length) {
89 return (readUint<uint64_t>(buffer, length));
94writeUint16(uint16_t
const value,
void*
const buffer,
size_t const length) {
95 return (
writeUint(value, buffer, length));
100writeUint32(uint32_t
const value,
void*
const buffer,
size_t const length) {
101 return (
writeUint(value, buffer, length));
106writeUint64(uint64_t
const value,
void*
const buffer,
size_t const length) {
107 return (
writeUint(value, buffer, length));
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
uint_t readUint(void const *const buffer, size_t const length)
Read an unsigned integer from given buffer.
uint8_t * writeUint32(uint32_t const value, void *const buffer, size_t const length)
uint32_t wrapper over writeUint.
uint8_t * writeUint(uint_t const value, void *const buffer, size_t const length)
Write the given unsigned integer to the given buffer.
uint16_t readUint16(void const *const buffer, size_t const length)
uint16_t wrapper over readUint.
uint8_t * writeUint16(uint16_t const value, void *const buffer, size_t const length)
uint16_t wrapper over writeUint.
uint8_t * writeUint64(uint64_t const value, void *const buffer, size_t const length)
uint64_t wrapper over writeUint.
uint64_t readUint64(void const *const buffer, size_t const length)
uint16_t wrapper over readUint.
uint32_t readUint32(void const *const buffer, size_t const length)
uint32_t wrapper over readUint.
Defines the logger used by the top-level component of kea-lfc.