+static inline void write_u32le(uint8_t *p, uint32_t x)
+{
+ p[0] = x & 0xff; x >>= 8;
+ p[1] = x & 0xff; x >>= 8;
+ p[2] = x & 0xff; x >>= 8;
+ p[3] = x & 0xff; x >>= 8;
+}
+#define WL32(p, x) write_u32le((uint8_t *)(p), (uint32_t)(x))
+
+/**
+ * Write a 40 bits unsigned integer to memory stored as little endian.
+ * @param p a pointer to the output memory
+ * @param x the input unsigned integer
+ */
+static inline void write_u40le(uint8_t *p, uint64_t x)
+{
+ p[0] = x & 0xff; x >>= 8;
+ p[1] = x & 0xff; x >>= 8;
+ p[2] = x & 0xff; x >>= 8;
+ p[3] = x & 0xff; x >>= 8;
+ p[4] = x & 0xff; x >>= 8;
+}
+#define WL40(p, x) write_u40le((uint8_t *)(p), (uint64_t)(x))
+
+/**
+ * Write a 48 bits unsigned integer to memory stored as little endian.
+ * @param p a pointer to the output memory
+ * @param x the input unsigned integer
+ */
+static inline void write_u48le(uint8_t *p, uint64_t x)
+{
+ p[0] = x & 0xff; x >>= 8;
+ p[1] = x & 0xff; x >>= 8;
+ p[2] = x & 0xff; x >>= 8;
+ p[3] = x & 0xff; x >>= 8;
+ p[4] = x & 0xff; x >>= 8;
+ p[5] = x & 0xff; x >>= 8;
+}
+#define WL48(p, x) write_u48le((uint8_t *)(p), (uint64_t)(x))
+
+/**
+ * Write a 64 bits unsigned integer to memory stored as big endian.
+ * @param p a pointer to the output memory
+ * @param x the input unsigned integer
+ */
+static inline void write_u64be(uint8_t *p, uint64_t x)
+{
+ p[7] = x & 0xff; x >>= 8;
+ p[6] = x & 0xff; x >>= 8;
+ p[5] = x & 0xff; x >>= 8;
+ p[4] = x & 0xff; x >>= 8;
+ p[3] = x & 0xff; x >>= 8;
+ p[2] = x & 0xff; x >>= 8;
+ p[1] = x & 0xff; x >>= 8;
+ p[0] = x & 0xff; x >>= 8;
+}
+
+/**
+ * Write a 64 bits unsigned integer to memory stored as little endian.
+ * @param p a pointer to the output memory
+ * @param x the input unsigned integer
+ */
+static inline void write_u64le(uint8_t *p, uint64_t x)
+{
+ p[0] = x & 0xff; x >>= 8;
+ p[1] = x & 0xff; x >>= 8;
+ p[2] = x & 0xff; x >>= 8;
+ p[3] = x & 0xff; x >>= 8;
+ p[4] = x & 0xff; x >>= 8;
+ p[5] = x & 0xff; x >>= 8;
+ p[6] = x & 0xff; x >>= 8;
+ p[7] = x & 0xff; x >>= 8;
+}
+#define WL64(p, x) write_u64le((uint8_t *)(p), (uint64_t)(x))
+
+/**
+ * Write a 32 bits float to memory stored as big endian.
+ * @param p a pointer to the output memory
+ * @param x the input float
+ */
+static inline void write_fltbe(uint8_t *p, float x)
+{
+ union { uint32_t u; float f; } u;
+ u.f = x;
+ write_u32be(p, u.u);
+}
+#define WBFL(p, x) write_fltbe((uint8_t *)(p), (x))
+
+/**
+ * Write a 32 bits float to memory stored as little endian.
+ * @param p a pointer to the output memory
+ * @param x the input float
+ */
+static inline void write_fltle(uint8_t *p, float x)
+{
+ union { uint32_t u; float f; } u;
+ u.f = x;
+ write_u32le(p, u.u);
+}
+#define WLFL(p, x) write_fltle((uint8_t *)(p), float (x))
+
+/**
+ * Write a 64 bits float to memory stored as little endian.
+ * @param p a pointer to the output memory
+ * @param x the input floating point value
+ */
+static inline void write_dblle(uint8_t *p, double x)
+{
+ union { uint64_t u; double f; } u;
+ u.f = x;
+ write_u64le(p, u.u);
+}
+#define WLDB(p, x) write_dblle((uint8_t *)(p), float (x))
+
+/* Endianess conversion helpers with read/write position increment. */
+
+/**
+ * Read unsigned 8bit integer from raw memory, increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint8_t read_u8_inc(const uint8_t **p)
+{
+ uint8_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_u8(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read unsigned 8bit integer, check length, increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in, out] l Remaining input payload length.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint8_t read_u8_inc_len(const uint8_t **p, size_t *l)
+{
+ uint8_t v;
+
+ if (!p || !*p)
+ return 0;
+ if (l && *l < sizeof(v)) {
+ *l = 0;
+ return 0;
+ }
+ v = read_u8(*p);
+ *p += sizeof(v);
+ if (l)
+ *l -= sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read signed 8bit integer from raw memory, increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, signed.
+ */
+static inline int8_t read_i8_inc(const uint8_t **p)
+{
+ int8_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_i8(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read unsigned 16bit integer from raw memory (big endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint16_t read_u16be_inc(const uint8_t **p)
+{
+ uint16_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_u16be(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read unsigned 16bit integer from raw memory (little endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint16_t read_u16le_inc(const uint8_t **p)
+{
+ uint16_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_u16le(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read unsigned 16bit integer (LE format), check length, increment position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in, out] l Remaining input payload length.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint16_t read_u16le_inc_len(const uint8_t **p, size_t *l)
+{
+ uint16_t v;
+
+ if (!p || !*p)
+ return 0;
+ if (l && *l < sizeof(v)) {
+ *l = 0;
+ return 0;
+ }
+ v = read_u16le(*p);
+ *p += sizeof(v);
+ if (l)
+ *l -= sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read signed 16bit integer from raw memory (big endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, signed.
+ */
+static inline int16_t read_i16be_inc(const uint8_t **p)
+{
+ int16_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_i16be(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read signed 16bit integer from raw memory (little endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, signed.
+ */
+static inline int16_t read_i16le_inc(const uint8_t **p)
+{
+ int16_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_i16le(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read unsigned 24bit integer from raw memory (little endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint32_t read_u24le_inc(const uint8_t **p)
+{
+ uint32_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_u24le(*p);
+ *p += 3 * sizeof(uint8_t);
+
+ return v;
+}
+
+/**
+ * Read unsigned 32bit integer from raw memory (big endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint32_t read_u32be_inc(const uint8_t **p)
+{
+ uint32_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_u32be(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read unsigned 32bit integer from raw memory (little endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint32_t read_u32le_inc(const uint8_t **p)
+{
+ uint32_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_u32le(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read signed 32bit integer from raw memory (big endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, signed.
+ */
+static inline int32_t read_i32be_inc(const uint8_t **p)
+{
+ int32_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_i32be(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read signed 32bit integer from raw memory (little endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, signed.
+ */
+static inline int32_t read_i32le_inc(const uint8_t **p)
+{
+ int32_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_i32le(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read unsigned 64bit integer from raw memory (big endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint64_t read_u64be_inc(const uint8_t **p)
+{
+ uint64_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_u64be(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read unsigned 64bit integer from raw memory (little endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved integer value, unsigned.
+ */
+static inline uint64_t read_u64le_inc(const uint8_t **p)
+{
+ uint64_t v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_u64le(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read 32bit float from raw memory (big endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved float value.
+ */
+static inline float read_fltbe_inc(const uint8_t **p)
+{
+ float v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_fltbe(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read 32bit float from raw memory (little endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved float value.
+ */
+static inline float read_fltle_inc(const uint8_t **p)
+{
+ float v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_fltle(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read 64bit float from raw memory (big endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved float value.
+ */
+static inline double read_dblbe_inc(const uint8_t **p)
+{
+ double v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_dblbe(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Read 64bit float from raw memory (little endian format), increment read position.
+ * @param[in, out] p Pointer into byte stream.
+ * @return Retrieved float value.
+ */
+static inline double read_dblle_inc(const uint8_t **p)
+{
+ double v;
+
+ if (!p || !*p)
+ return 0;
+ v = read_dblle(*p);
+ *p += sizeof(v);
+
+ return v;
+}
+
+/**
+ * Write unsigned 8bit integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u8_inc(uint8_t **p, uint8_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u8(*p, x);
+ *p += sizeof(x);
+}
+
+/**
+ * Write unsigned 16bit big endian integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u16be_inc(uint8_t **p, uint16_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u16be(*p, x);
+ *p += sizeof(x);
+}
+
+/**
+ * Write unsigned 16bit little endian integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u16le_inc(uint8_t **p, uint16_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u16le(*p, x);
+ *p += sizeof(x);
+}
+
+/**
+ * Write unsigned 24bit liggle endian integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u24le_inc(uint8_t **p, uint32_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u24le(*p, x);
+ *p += 3 * sizeof(uint8_t);
+}
+
+/**
+ * Write unsigned 32bit big endian integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u32be_inc(uint8_t **p, uint32_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u32be(*p, x);
+ *p += sizeof(x);
+}
+
+/**
+ * Write unsigned 32bit little endian integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u32le_inc(uint8_t **p, uint32_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u32le(*p, x);
+ *p += sizeof(x);
+}
+
+/**
+ * Write unsigned 40bit little endian integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u40le_inc(uint8_t **p, uint64_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u40le(*p, x);
+ *p += 5 * sizeof(uint8_t);
+}
+
+/**
+ * Write unsigned 48bit little endian integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u48le_inc(uint8_t **p, uint64_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u48le(*p, x);
+ *p += 48 / 8 * sizeof(uint8_t);
+}
+
+/**
+ * Write unsigned 64bit little endian integer to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_u64le_inc(uint8_t **p, uint64_t x)
+{
+ if (!p || !*p)
+ return;
+ write_u64le(*p, x);
+ *p += sizeof(x);
+}
+
+/**
+ * Write single precision little endian float to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_fltle_inc(uint8_t **p, float x)
+{
+ if (!p || !*p)
+ return;
+ write_fltle(*p, x);
+ *p += sizeof(x);
+}
+
+/**
+ * Write double precision little endian float to raw memory, increment write position.
+ * @param[in, out] p Pointer into byte stream.
+ * @param[in] x Value to write.
+ */
+static inline void write_dblle_inc(uint8_t **p, double x)
+{
+ if (!p || !*p)
+ return;
+ write_dblle(*p, x);
+ *p += sizeof(x);
+}