|
Anjay Lite
|
Public utility helpers used throughout Anjay Lite. More...
#include <anj/init.h>#include <stddef.h>#include <stdint.h>#include <stdlib.h>#include <anj/defs.h>Go to the source code of this file.
Macros | |
| #define | ANJ_ID_INVALID UINT16_MAX |
| #define | ANJ_CONTAINER_OF(ptr, type, member) ((type *) (void *) ((char *) (intptr_t) (ptr) -offsetof(type, member))) |
| #define | ANJ_MIN(a, b) ((a) < (b) ? (a) : (b)) |
| #define | ANJ_MAX(a, b) ((a) < (b) ? (b) : (a)) |
| #define | ANJ_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) |
| #define | ANJ_QUOTE(Value) # Value |
| #define | ANJ_QUOTE_MACRO(Value) ANJ_QUOTE(Value) |
| #define | ANJ_ASSERT(cond, msg) assert((cond) && (bool) "" msg) |
| #define | ANJ_UNREACHABLE(msg) ANJ_ASSERT(0, msg) |
| #define | ANJ_CONCAT(...) |
| #define | ANJ_STATIC_ASSERT(condition, message) |
| #define | ANJ_MAKE_RESOURCE_INSTANCE_PATH(Oid, Iid, Rid, Riid) _ANJ_MAKE_URI_PATH(Oid, Iid, Rid, Riid, 4) |
| #define | ANJ_MAKE_RESOURCE_PATH(Oid, Iid, Rid) _ANJ_MAKE_URI_PATH(Oid, Iid, Rid, ANJ_ID_INVALID, 3) |
| #define | ANJ_MAKE_INSTANCE_PATH(Oid, Iid) _ANJ_MAKE_URI_PATH(Oid, Iid, ANJ_ID_INVALID, ANJ_ID_INVALID, 2) |
| #define | ANJ_MAKE_OBJECT_PATH(Oid) |
| #define | ANJ_MAKE_ROOT_PATH() |
Functions | |
| static bool | anj_uri_path_equal (const anj_uri_path_t *left, const anj_uri_path_t *right) |
| static size_t | anj_uri_path_length (const anj_uri_path_t *path) |
| static bool | anj_uri_path_has (const anj_uri_path_t *path, anj_id_type_t id_type) |
| static bool | anj_uri_path_is (const anj_uri_path_t *path, anj_id_type_t id_type) |
| static bool | anj_uri_path_outside_base (const anj_uri_path_t *path, const anj_uri_path_t *base) |
| bool | anj_uri_path_increasing (const anj_uri_path_t *previous_path, const anj_uri_path_t *current_path) |
| uint16_t | anj_determine_block_buffer_size (size_t buff_size) |
| size_t | anj_uint16_to_string_value (char *out_buff, uint16_t value) |
| size_t | anj_uint32_to_string_value (char *out_buff, uint32_t value) |
| size_t | anj_uint64_to_string_value (char *out_buff, uint64_t value) |
| size_t | anj_int64_to_string_value (char *out_buff, int64_t value) |
| size_t | anj_double_to_string_value (char *out_buff, double value) |
| int | anj_string_to_uint32_value (uint32_t *out_val, const char *buff, size_t buff_len) |
| int | anj_string_to_uint64_value (uint64_t *out_val, const char *buff, size_t buff_len) |
| int | anj_string_to_int64_value (int64_t *out_val, const char *buff, size_t buff_len) |
| int | anj_string_to_objlnk_value (anj_objlnk_value_t *out, const char *objlnk) |
| int | anj_string_to_double_value (double *out_val, const char *buff, size_t buff_len) |
Public utility helpers used throughout Anjay Lite.
This header provides small generic macros, helpers for working with LwM2M paths, and number/string conversion routines used by the library. It is safe to include from application code.
| #define ANJ_ARRAY_SIZE | ( | arr | ) | (sizeof(arr) / sizeof(arr[0])) |
Number of elements in a C array.
| #define ANJ_ASSERT | ( | cond, | |
| msg | |||
| ) | assert((cond) && (bool) "" msg) |
Assertion helper with a fixed string literal message.
| #define ANJ_CONCAT | ( | ... | ) |
Concatenates tokens after performing macro-argument expansion. Useful when building identifiers from macro parameters.
| #define ANJ_CONTAINER_OF | ( | ptr, | |
| type, | |||
| member | |||
| ) | ((type *) (void *) ((char *) (intptr_t) (ptr) -offsetof(type, member))) |
Returns a pointer to the structure that contains member at address ptr.
| ptr | Pointer to a structure member. |
| type | Type of the outer structure. |
| member | Member name inside type. |
| #define ANJ_ID_INVALID UINT16_MAX |
Special “invalid” value used by LwM2M for all identifier kinds: Object IDs, Object Instance IDs, Resource IDs, Resource Instance IDs and Short Server IDs.
| #define ANJ_MAKE_INSTANCE_PATH | ( | Oid, | |
| Iid | |||
| ) | _ANJ_MAKE_URI_PATH(Oid, Iid, ANJ_ID_INVALID, ANJ_ID_INVALID, 2) |
Constructs an anj_uri_path_t compound literal representing an Object Instance path: /Oid/Iid.
| #define ANJ_MAKE_OBJECT_PATH | ( | Oid | ) |
Constructs an anj_uri_path_t compound literal representing an Object path: /Oid.
| #define ANJ_MAKE_RESOURCE_INSTANCE_PATH | ( | Oid, | |
| Iid, | |||
| Rid, | |||
| Riid | |||
| ) | _ANJ_MAKE_URI_PATH(Oid, Iid, Rid, Riid, 4) |
Constructs an anj_uri_path_t compound literal representing a Resource Instance path: /Oid/Iid/Rid/Riid.
| #define ANJ_MAKE_RESOURCE_PATH | ( | Oid, | |
| Iid, | |||
| Rid | |||
| ) | _ANJ_MAKE_URI_PATH(Oid, Iid, Rid, ANJ_ID_INVALID, 3) |
Constructs an anj_uri_path_t compound literal representing a Resource path: /Oid/Iid/Rid.
| #define ANJ_MAKE_ROOT_PATH | ( | ) |
Constructs an anj_uri_path_t compound literal representing the root path.
| #define ANJ_MAX | ( | a, | |
| b | |||
| ) | ((a) < (b) ? (b) : (a)) |
Maximum of two values.
| #define ANJ_MIN | ( | a, | |
| b | |||
| ) | ((a) < (b) ? (a) : (b)) |
Minimum of two values.
| #define ANJ_QUOTE | ( | Value | ) | # Value |
Turns a token into a string literal without expanding it.
| #define ANJ_QUOTE_MACRO | ( | Value | ) | ANJ_QUOTE(Value) |
Turns a token into a string literal after performing macro expansion.
| #define ANJ_STATIC_ASSERT | ( | condition, | |
| message | |||
| ) |
C99-compatible replacement for static_assert.
Produces a compile-time error if condition is false.
| condition | Boolean expression evaluated at compile time. |
| message | Identifier used in the generated struct name. |
| #define ANJ_UNREACHABLE | ( | msg | ) | ANJ_ASSERT(0, msg) |
Marks code that should be unreachable in a correct program flow. Triggers an assertion failure in debug builds.
| uint16_t anj_determine_block_buffer_size | ( | size_t | buff_size | ) |
Determine a Block-Wise transfer buffer size that satisfies RFC 7959 constraints (power of two in the range 16-1024), not exceeding buff_size.
If buff_size is smaller than 16, returns 0.
| buff_size | Available buffer size in bytes. |
| size_t anj_double_to_string_value | ( | char * | out_buff, |
| double | value | ||
| ) |
Convert a double to a string (without a terminating NUL).
This function is used to encode LwM2M attribute values whose textual format is defined as 1*DIGIT ["." 1*DIGIT]. For very large/small magnitudes (>|UINT64_MAX|, <1e-10) an exponential notation may be used. NaN and infinities are emitted as "nan" and "inf".
If ANJ_WITH_CUSTOM_CONVERSION_FUNCTIONS is enabled, a lightweight formatter is used (may incur rounding error at extreme magnitudes).
The buffer must be at least ANJ_DOUBLE_STR_MAX_LEN bytes long.
| size_t anj_int64_to_string_value | ( | char * | out_buff, |
| int64_t | value | ||
| ) |
Convert an int64_t to a decimal string (without a terminating nullchar). The buffer must be at least ANJ_I64_STR_MAX_LEN bytes long.
| int anj_string_to_double_value | ( | double * | out_val, |
| const char * | buff, | ||
| size_t | buff_len | ||
| ) |
Parse a decimal string into double (no inf / nan support, consistent with LwM2M attribute representation).
buff_len (e.g., using strlen() if the content is null-terminated).| int anj_string_to_int64_value | ( | int64_t * | out_val, |
| const char * | buff, | ||
| size_t | buff_len | ||
| ) |
Parse a decimal string into int64_t (optional leading sign allowed).
buff_len (e.g., using strlen() if the content is null-terminated).INT64_MIN..INT64_MAX).| [out] | out_val | Parsed value. |
| buff | Input buffer. | |
| buff_len | Input length. |
| int anj_string_to_objlnk_value | ( | anj_objlnk_value_t * | out, |
| const char * | objlnk | ||
| ) |
Parse an Objlnk string (e.g., "3:0") into anj_objlnk_value_t.
| [out] | out | Output structure. |
| objlnk | null-terminated input string. |
| int anj_string_to_uint32_value | ( | uint32_t * | out_val, |
| const char * | buff, | ||
| size_t | buff_len | ||
| ) |
Parse a decimal string into uint32_t.
buff_len (e.g., using strlen() if the content is null-terminated).| [out] | out_val | Parsed value. |
| buff | Input buffer. | |
| buff_len | Input length. |
| int anj_string_to_uint64_value | ( | uint64_t * | out_val, |
| const char * | buff, | ||
| size_t | buff_len | ||
| ) |
Parse a decimal string into uint64_t.
buff_len (e.g., using strlen() if the content is null-terminated).| [out] | out_val | Parsed value. |
| buff | Input buffer. | |
| buff_len | Input length. |
| size_t anj_uint16_to_string_value | ( | char * | out_buff, |
| uint16_t | value | ||
| ) |
Convert a uint16_t to a decimal string (without a terminating nullchar). The buffer must be at least ANJ_U16_STR_MAX_LEN bytes long.
| size_t anj_uint32_to_string_value | ( | char * | out_buff, |
| uint32_t | value | ||
| ) |
Convert a uint32_t to a decimal string (without a terminating nullchar). The buffer must be at least ANJ_U32_STR_MAX_LEN bytes long.
| size_t anj_uint64_to_string_value | ( | char * | out_buff, |
| uint64_t | value | ||
| ) |
Convert a uint64_t to a decimal string (without a terminating nullchar). The buffer must be at least ANJ_U64_STR_MAX_LEN bytes long.
|
inlinestatic |
Compares two LwM2M paths for equality (same length and same components).
|
inlinestatic |
Checks whether path contains the component identified by id_type. For example, /Oid/Iid “has” ANJ_ID_OID and ANJ_ID_IID.
| bool anj_uri_path_increasing | ( | const anj_uri_path_t * | previous_path, |
| const anj_uri_path_t * | current_path | ||
| ) |
Checks that current_path is lexicographically greater than previous_path.
|
inlinestatic |
Checks whether path is exactly of the level identified by id_type. For example, /Oid/Iid “is” ANJ_ID_IID.
|
inlinestatic |
Returns the number of components in path.
|
inlinestatic |
Checks whether path lies outside of the subtree rooted at base. Returns true if path is shorter than base or diverges at any component.