automerge/automerge-c/test/str_utils.c
Jason Kankiewicz 6de9ff620d Moved hex_to_bytes() so that it could be shared
by the unit test suites for `AMactorId` and `AMdoc` functions.
2022-06-14 00:52:06 -07:00

15 lines
386 B
C

#include <stdio.h>
#include <stdint.h>
/* local */
#include "str_utils.h"
void hex_to_bytes(char const* hex_str, uint8_t* src, size_t const count) {
unsigned int byte;
char const* next = hex_str;
for (size_t index = 0; *next && index != count; next += 2, ++index) {
if (sscanf(next, "%02x", &byte) == 1) {
src[index] = (uint8_t)byte;
}
}
}