ProsecCoAP 🥂
 
Loading...
Searching...
No Matches
Coap::Utils Namespace Reference

Utilities. More...

Functions

template<typename T >
void toNetworkByteOrder (T value, uint8_t *result)
 Convert an integer-like value to network byte order (i.e. big-endian).
 
void toNetworkByteOrder (float value, uint8_t *result)
 Overload to convert a 32-bit float to network byte order.
 
void toNetworkByteOrder (double value, uint8_t *result)
 Overload to convert a 64-bit double to network byte order.
 
constexpr uint16_t read_uint16 (const uint8_t *bytes)
 Reads a 16-bit unsigned integer from a Big-Endian byte stream.
 
constexpr uint32_t read_uint32 (const uint8_t *bytes)
 Reads a 32-bit unsigned integer from a Big-Endian byte stream.
 
constexpr uint64_t read_uint64 (const uint8_t *bytes)
 Reads a 64-bit unsigned integer from a Big-Endian byte stream.
 
constexpr int16_t read_int16 (const uint8_t *bytes)
 Reads a 16-bit signed integer from a Big-Endian byte stream.
 
constexpr int32_t read_int32 (const uint8_t *bytes)
 Reads a 32-bit signed integer from a Big-Endian byte stream.
 
constexpr int64_t read_int64 (const uint8_t *bytes)
 Reads a 64-bit signed integer from a Big-Endian byte stream.
 
float read_float (const uint8_t *bytes)
 Reads a 32-bit float from a Big-Endian byte stream.
 
template<typename T = double>
read_double (const uint8_t *bytes)
 Reads a 64-bit double from a Big-Endian byte stream.
 

Detailed Description

Utilities.

This namespace contains public utility functions and classes.

Function Documentation

◆ read_double()

template<typename T = double>
T Coap::Utils::read_double ( const uint8_t * bytes)
inline

Reads a 64-bit double from a Big-Endian byte stream.

Note
Templated to defer the 64-bit architecture check until the function is actually called.

◆ read_float()

float Coap::Utils::read_float ( const uint8_t * bytes)
inline

Reads a 32-bit float from a Big-Endian byte stream.

◆ read_int16()

int16_t Coap::Utils::read_int16 ( const uint8_t * bytes)
inlineconstexpr

Reads a 16-bit signed integer from a Big-Endian byte stream.

◆ read_int32()

int32_t Coap::Utils::read_int32 ( const uint8_t * bytes)
inlineconstexpr

Reads a 32-bit signed integer from a Big-Endian byte stream.

◆ read_int64()

int64_t Coap::Utils::read_int64 ( const uint8_t * bytes)
inlineconstexpr

Reads a 64-bit signed integer from a Big-Endian byte stream.

◆ read_uint16()

uint16_t Coap::Utils::read_uint16 ( const uint8_t * bytes)
inlineconstexpr

Reads a 16-bit unsigned integer from a Big-Endian byte stream.

Basic usage:

uint8_t stream[2] = {0xAB, 0xCD};
uint16_t value = Coap::Utils::read_uint16(stream);
constexpr uint16_t read_uint16(const uint8_t *bytes)
Reads a 16-bit unsigned integer from a Big-Endian byte stream.
Definition Utils.h:93

Usage with larger buffers:

uint8_t stream[100] = {0}; // Large source data (must be populated).
uint16_t value = Coap::Utils::read_uint16(&stream[42]);

◆ read_uint32()

uint32_t Coap::Utils::read_uint32 ( const uint8_t * bytes)
inlineconstexpr

Reads a 32-bit unsigned integer from a Big-Endian byte stream.

◆ read_uint64()

uint64_t Coap::Utils::read_uint64 ( const uint8_t * bytes)
inlineconstexpr

Reads a 64-bit unsigned integer from a Big-Endian byte stream.

◆ toNetworkByteOrder() [1/3]

void Coap::Utils::toNetworkByteOrder ( double value,
uint8_t * result )
inline

Overload to convert a 64-bit double to network byte order.

Parameters
valueThe double value to convert.
[out]resultThe pointer to the byte buffer where the result will be stored (min 8 bytes).

◆ toNetworkByteOrder() [2/3]

void Coap::Utils::toNetworkByteOrder ( float value,
uint8_t * result )
inline

Overload to convert a 32-bit float to network byte order.

Parameters
valueThe float value to convert.
[out]resultThe pointer to the byte buffer where the result will be stored (min 4 bytes).

◆ toNetworkByteOrder() [3/3]

template<typename T >
void Coap::Utils::toNetworkByteOrder ( T value,
uint8_t * result )
inline

Convert an integer-like value to network byte order (i.e. big-endian).

Parameters
valueThe integer-like value to convert.
[out]resultThe pointer to the byte buffer where the result will be stored.

The destination buffer must have at least sizeof(T) bytes available.

Note
Both signed and unsigned integers are supported as long as the right-shift operator performs arithmetic right shift, so that the result remains negative.