libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Functions
hexcode.h File Reference
#include <stdlib.h>
#include "core.h"
#include "types.h"
Include dependency graph for hexcode.h:

Go to the source code of this file.

Functions

void hex_enc (const void *in_raw, size_t len, void *out_enc, size_t out_cap)
 
bool_t hex_dec (const void *in_enc, size_t len, void *out_raw, size_t out_cap)
 

Function Documentation

◆ hex_dec()

bool_t hex_dec ( const void *  in_enc,
size_t  len,
void *  out_raw,
size_t  out_cap 
)

Decodes a string of hex characters into a binary output buffer.

Parameters
in_encInput string of hex characters. This must NOT contain any whitespace. It must be strictly ONLY the hex characters. The input doesn't need to be NUL-terminated (length is provided explicitly in the len parameter).
lenNumber of characters in the in_enc buffer (excluding any terminating NUL bytes). This must be a multiple of 2.
out_rawOutput binary buffer, which will be filled with the decoded data.
out_capOutput buffer length in bytes. This must be at least half of len.
Returns
B_TRUE if decoding succeeded, B_FALSE otherwise. Decoding failure can occur if the input doesn't contain an even number of characters, the output buffer is too small to contain the entire decoded input, or if an invalid (non-hex) character is encountered in the input buffer.

Definition at line 84 of file hexcode.c.

◆ hex_enc()

void hex_enc ( const void *  in_raw,
size_t  len,
void *  out_enc,
size_t  out_cap 
)

Encodes binary data into a string of hex digits.

Parameters
in_rawInput binary data buffer to be encoded.
lenInput binary buffer length in bytes.
out_encOutput buffer to hold the string of encoded hex characters. The output is guaranteed to always be zero-terminated (provided the buffer can hold at least 1 byte).
out_capOutput buffer capacity. To properly encode all input into the output, the output buffer must be able to hold at least twice len bytes plus 1 (for the terminating NUL byte).

Definition at line 38 of file hexcode.c.