|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Base-16 conversion between raw bytes and their ASCII digits. More...
#include <stdint.h>Go to the source code of this file.
Functions | |
| char | pc_hex_digit (uint8_t nibble, bool upper=false) |
Low nibble of nibble as a hex character, uppercase when upper. | |
| int8_t | pc_hex_val (char c) |
Hex character c as 0..15, or -1 when c is not a hex digit of either case. | |
| uint8_t | pc_hex_u32 (uint32_t v, char *out) |
Write v into out as lowercase hex digits, most significant first, and return the digit count (1..8; zero renders as a single "0"). | |
| void | pc_hex_encode (const uint8_t *in, uint32_t n, char *out, bool upper=false) |
Write n bytes of in into out as 2 * n hex characters plus a NUL. | |
| int32_t | pc_hex_decode (const char *in, uint32_t hexlen, uint8_t *out, uint32_t out_cap) |
Read exactly hexlen hex characters from in into out as hexlen / 2 bytes. | |
Base-16 conversion between raw bytes and their ASCII digits.
Four operations cover every hex site in the library: one nibble out, one digit in, a machine word out, and a byte run in either direction. Each writes into a caller-owned buffer, takes no heap and no <stdlib.h>, and is inline so an unused one costs nothing.
The decoders report failure through a negative return rather than a sentinel digit, so a malformed byte can never be mistaken for a valid zero.
Definition in file hex.h.
|
inline |
|
inline |
Hex character c as 0..15, or -1 when c is not a hex digit of either case.
Definition at line 36 of file hex.h.
Referenced by pc_hex_decode(), and pc_prov_form_field().
|
inline |
Write v into out as lowercase hex digits, most significant first, and return the digit count (1..8; zero renders as a single "0").
No 0x prefix, no NUL, and no leading zeros, which is the form the HTTP/1.1 chunked size line takes. The width is counted before any digit is written so each digit lands at its final index, which is why no reversal buffer is needed. out needs room for 8 characters.
|
inline |
|
inline |
Read exactly hexlen hex characters from in into out as hexlen / 2 bytes.
hexlen is odd, the result exceeds out_cap, or any character is not a hex digit. Nothing is written on the odd-length or capacity rejections; a bad digit stops the run where it is found. Definition at line 100 of file hex.h.
References pc_hex_val().