Appearance
namespace flake::utils
Functions Overview
| Name | |
|---|---|
| template <typename T > constexprconstuint8_t * | as_bytes(constT & value) Const byte-view of a trivially-copyable object. |
| template <typename T > constexpruint8_t * | as_writable_bytes(T & value) Mutable byte-view of a trivially-copyable object. |
| template <typename T > constexprconstchar * | as_chars(constT & value) Const char-view (POSIX socket / C string APIs). |
| template <typename T > constexprchar * | as_writable_chars(T & value) Mutable char-view (POSIX socket / C string APIs). |
| template <typename Dst ,typename Src > constexprconstDst * | bytes_as(constSrc * p) Reinterpret a byte buffer as a pointer-to-object view. |
| template <typename Dst ,typename Src > constexpr Dst * | bytes_as_mut(Src * p) Mutable variant of bytes_as. |
| template <typename T > constexprT | safe_or(T lhs, T rhs) Promotion-safe bitwise OR for unsigned integral types. |
| template <typename T > constexprT | safe_and(T lhs, T rhs) Promotion-safe bitwise AND for unsigned integral types. |
| template <typename T_dst ,typename T1 ,typename T2 > constexprT_dst | safe_add(T1 lhs, T2 rhs) Promotion-safe addition with explicit destination type. |
| template <typename T_dst ,typename T1 ,typename T2 > constexprT_dst | safe_sub(T1 lhs, T2 rhs) Promotion-safe subtraction with explicit destination type. |
| template <typename T > constexprT | safe_not(T x) Promotion-safe bitwise NOT for unsigned integral types. |
| template <typename T_dst ,typename T_src > void | memcpy(T_dst * dest, constT_src * src, std::size_t count) Element-wise, type-checked memcpy for trivial types. |
| std::size_t | strlen(constchar * str, std::size_t max_len) Bounded string length (does not read past max_len). |
| char * | charFromString(const std::string & str) Allocate a null-terminated C string from a std::string. |
| std::string | stringFromChar(constchar * str) Create a std::string from a null-terminated C string. |
| uint32_t | timestamp() Return a monotonic timestamp in milliseconds. |
| char * | copyStr(constchar * src) Duplicate a null-terminated C string into a pool-allocated buffer. |
| unsignedchar | crc8(unsignedconstchar * data, unsignedchar len) Compute an 8-bit CRC over a byte buffer. |
Function Details
function as_bytes
cpp
template <typename T >
constexprconstuint8_t * as_bytes(
constT & value
)Const byte-view of a trivially-copyable object.
function as_writable_bytes
cpp
template <typename T >
constexpruint8_t * as_writable_bytes(
T & value
)Mutable byte-view of a trivially-copyable object.
function as_chars
cpp
template <typename T >
constexprconstchar * as_chars(
constT & value
)Const char-view (POSIX socket / C string APIs).
function as_writable_chars
cpp
template <typename T >
constexprchar * as_writable_chars(
T & value
)Mutable char-view (POSIX socket / C string APIs).
function bytes_as
cpp
template <typename Dst ,
typename Src >
constexprconstDst * bytes_as(
constSrc * p
)Reinterpret a byte buffer as a pointer-to-object view.
Used on the deserialization side to read a POD value out of a byte stream, or to hand a typed buffer to a byte-oriented API. Src may be any trivially-copyable source pointer type (e.g. uint32_t* fed back to a uint8_t*-flavoured free).
function bytes_as_mut
cpp
template <typename Dst ,
typename Src >
constexpr Dst * bytes_as_mut(
Src * p
)Mutable variant of bytes_as.
function safe_or
cpp
template <typename T >
constexprT safe_or(
T lhs,
T rhs
)Promotion-safe bitwise OR for unsigned integral types.
Parameters:
- lhs Left-hand operand.
- rhs Right-hand operand.
Template Parameters:
- T Unsigned integral type.
Return: lhs | rhs cast back to T.
Both operands are widened to std::uintmax_t before the operation, avoiding implicit-promotion pitfalls.
function safe_and
cpp
template <typename T >
constexprT safe_and(
T lhs,
T rhs
)Promotion-safe bitwise AND for unsigned integral types.
Parameters:
- lhs Left-hand operand.
- rhs Right-hand operand.
Template Parameters:
- T Unsigned integral type.
Return: lhs & rhs cast back to T.
function safe_add
cpp
template <typename T_dst ,
typename T1 ,
typename T2 >
constexprT_dst safe_add(
T1 lhs,
T2 rhs
)Promotion-safe addition with explicit destination type.
Parameters:
- lhs Left-hand operand.
- rhs Right-hand operand.
Template Parameters:
- T_dst Destination type.
- T1 Type of the left-hand operand.
- T2 Type of the right-hand operand.
Return: lhs + rhs cast to T_dst.
All three types must share the same signedness.
function safe_sub
cpp
template <typename T_dst ,
typename T1 ,
typename T2 >
constexprT_dst safe_sub(
T1 lhs,
T2 rhs
)Promotion-safe subtraction with explicit destination type.
Parameters:
- lhs Left-hand operand.
- rhs Right-hand operand.
Template Parameters:
- T_dst Destination type.
- T1 Type of the left-hand operand.
- T2 Type of the right-hand operand.
Return: lhs - rhs cast to T_dst.
function safe_not
cpp
template <typename T >
constexprT safe_not(
T x
)Promotion-safe bitwise NOT for unsigned integral types.
Parameters:
- x Operand.
Template Parameters:
- T Unsigned integral type.
Return: ~x cast back to T.
function memcpy
cpp
template <typename T_dst ,
typename T_src >
void memcpy(
T_dst * dest,
constT_src * src,
std::size_t count
)Element-wise, type-checked memcpy for trivial types.
Parameters:
- dest Destination array.
- src Source array.
- count Number of elements to copy.
Template Parameters:
- T_dst Destination element type (must be trivial).
- T_src Source element type (must be trivially convertible to
T_dst).
Copies count elements from src to dest, performing a static_cast on each element. Both pointers are null-checked.
function strlen
cpp
inline std::size_t strlen(
constchar * str,
std::size_t max_len
)Bounded string length (does not read past max_len).
Parameters:
- str Null-terminated C string (may be
nullptr). - max_len Maximum number of characters to examine.
Return: Length of str, capped at max_len.
function charFromString
cpp
char * charFromString(
const std::string & str
)Allocate a null-terminated C string from a std::string.
Parameters:
- str Source string.
Return: Newly allocated null-terminated C string, or nullptr on pool/arena exhaustion. The caller must release the buffer with [flake::flakeFree](/embed/2.2.0/API/Namespaces/namespaceflake.md#function-flakefree), notdelete[] — the pointer does not originate from operator``new[].
The buffer is drawn from libflake's size-class byte pool (see flakeAlloc in lake_alloc.h); on exhaustion it spills into the arena overhang. Never allocates from the system heap.
function stringFromChar
cpp
std::string stringFromChar(
constchar * str
)Create a std::string from a null-terminated C string.
Parameters:
- str Source C string (may be
nullptr→ empty string).
Return: Corresponding std::string.
function timestamp
cpp
uint32_t timestamp()Return a monotonic timestamp in milliseconds.
Return: Current timestamp (platform-dependent epoch).
function copyStr
cpp
char * copyStr(
constchar * src
)Duplicate a null-terminated C string into a pool-allocated buffer.
Parameters:
- src Null-terminated source string.
Return: Newly allocated copy, or nullptr on pool/arena exhaustion. The caller must release the buffer with [flake::flakeFree](/embed/2.2.0/API/Namespaces/namespaceflake.md#function-flakefree), notdelete[] — the pointer does not originate from operator``new[].
The copy is drawn from libflake's size-class byte pool (see flakeAlloc in [flake_alloc.h](/embed/2.2.0/API/Files/flake__alloc_8h.md#file-flake-alloc.h)); on exhaustion it spills into the arena overhang. Never allocates from the system heap.
function crc8
cpp
unsignedchar crc8(
unsignedconstchar * data,
unsignedchar len
)Compute an 8-bit CRC over a byte buffer.
Parameters:
- data Input bytes.
- len Number of bytes.
Return: Computed CRC-8 value.