#ifndef INCLUDE_BUFFER_UTILS_H
#define INCLUDE_BUFFER_UTILS_H
#include <stdint.h>
#include <stddef.h>
static inline void write_le2(uint8_t *const buffer, const size_t offset, const uint16_t value)
{
buffer[offset + 0U] = value & 0xffU;
buffer[offset + 1U] = (value >> 8U) & 0xffU;
}
static inline void write_le4(uint8_t *const buffer, const size_t offset, const uint32_t value)
{
buffer[offset + 0U] = value & 0xffU;
buffer[offset + 1U] = (value >> 8U) & 0xffU;
buffer[offset + 2U] = (value >> 16U) & 0xffU;
buffer[offset + 3U] = (value >> 24U) & 0xffU;
}
static inline uint16_t read_le2(const uint8_t *const buffer, const size_t offset)
{
return buffer[offset + 0U] | ((uint16_t)buffer[offset + 1U] << 8U);
}
static inline uint32_t read_le4(const uint8_t *const buffer, const size_t offset)
{
return buffer[offset + 0U] | ((uint32_t)buffer[offset + 1U] << 8U) | ((uint32_t)buffer[offset + 2U] << 16U) |
((uint32_t)buffer[offset + 3U] << 24U);
}
static inline uint32_t read_be4(const uint8_t *const buffer, const size_t offset)
{
return ((uint32_t)buffer[offset + 0U] << 24U) | ((uint32_t)buffer[offset + 1U] << 16U) |
((uint32_t)buffer[offset + 2U] << 8U) | buffer[offset + 3U];
}
#endif