Skip to content

Commit 231a073

Browse files
committed
Update Year in License
1 parent 7e5f656 commit 231a073

File tree

3 files changed

+79
-18
lines changed

3 files changed

+79
-18
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2024 Boaz Segev
3+
Copyright (c) 2019-2025 Boaz Segev
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

fio-stl.h

+77-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* *****************************************************************************
2-
Copyright: Boaz Segev, 2019-2024
2+
Copyright: Boaz Segev, 2019-2025
33
License: ISC / MIT (choose your license)
44

55
Feel free to copy, use and enjoy according to the license provided.
@@ -40669,9 +40669,9 @@ RESP Parser Settings
4066940669

4067040670
/* RESP's parser type - do not access directly. */
4067140671
typedef struct {
40672-
void *(*get_null)(void);
40673-
void *(*get_true)(void);
40674-
void *(*get_false)(void);
40672+
void *set_null;
40673+
void *set_true;
40674+
void *set_false;
4067540675
void *(*get_number)(int64_t i);
4067640676
void *(*get_float)(double f);
4067740677
void *(*get_bignum)(char *str, size_t len);
@@ -40684,6 +40684,10 @@ typedef struct {
4068440684
void *(*map_push)(void *map, void *key, void *value);
4068540685
/* returns non-zero on error. */
4068640686
int (*done)(void *udata, void *response);
40687+
/** Called on error response, NOT on protocol error. */
40688+
int (*error)(void *udata, void *response);
40689+
/** Called after either response callbacks or protocol error. */
40690+
void (*free_response)(void *obj);
4068740691
} fio_resp3_settings_s;
4068840692

4068940693
/* *****************************************************************************
@@ -40692,22 +40696,27 @@ RESP Parser API
4069240696

4069340697
/* RESP's parser type - do not access directly. */
4069440698
typedef struct fio_resp3_s {
40699+
/** callback settings. */
40700+
fio_resp3_settings_s settings;
4069540701
struct {
40696-
/** callback settings. */
40697-
fio_resp3_settings_s *settings;
4069840702
/** current parsing function. */
4069940703
size_t (*parse)(struct fio_resp3_s *, uint8_t *, size_t);
4070040704
/** Stack's depth */
4070140705
uint16_t depth;
40702-
struct {
40703-
void *data;
40704-
uint32_t expected;
40705-
uint8_t typ;
40706-
} stack[FIO_RESP3_MAX_NESTING];
4070740706
} private_data;
40707+
struct {
40708+
void *data;
40709+
uint32_t expected;
40710+
uint8_t typ;
40711+
} private_stack[FIO_RESP3_MAX_NESTING];
4070840712
void *udata;
4070940713
} fio_resp3_s;
4071040714

40715+
#define FIO_RESP3_INIT(...) \
40716+
(fio_resp3_s) { \
40717+
.settings = {__VA_ARGS__}, .private_data = {0}, .udata = NULL \
40718+
}
40719+
4071140720
/** Returns an initialized parser. */
4071240721
FIO_IFUNC fio_resp3_s fio_resp3_init(fio_resp3_settings_s *settings,
4071340722
void *udata);
@@ -40719,18 +40728,69 @@ FIO_IFUNC void fio_resp3_init2(fio_resp3_s *dest,
4071940728
/** Parse `data`, returning the abount of bytes consumed. */
4072040729
FIO_IFUNC size_t fio_resp3_parse(fio_resp3_s *parser);
4072140730

40731+
/* *****************************************************************************
40732+
Validating RESP3 Settings.
40733+
***************************************************************************** */
40734+
40735+
/* clang-format off */
40736+
static void *fio___resp3_get_number(int64_t i) { (void)i; }
40737+
static void *fio___resp3_get_float(double f) { (void)f; }
40738+
static void *fio___resp3_get_bignum(char *str, size_t len) { (void)str, (void)len; }
40739+
static void *fio___resp3_get_string(char *str, size_t len) { (void)str, (void)len; }
40740+
static void *fio___resp3_str_start(size_t soft_expected) { (void)soft_expected; }
40741+
static void *fio___resp3_str(void *d, char *s, size_t l) { (void)d, (void)s, (void)l; }
40742+
static void *fio___resp3_arr_start(size_t soft_expected) { (void)soft_expected; }
40743+
static void *fio___resp3_arr_push(void *a, void *v) { (void)a, (void)v; }
40744+
static void *fio___resp3_map_start(size_t soft_expected) { (void)soft_expected; }
40745+
static void *fio___resp3_map(void *m, void *k, void *v) { (void)m, (void)k, (void)v; }
40746+
static int fio___resp3_done(void *u, void *r) { (void)u, (void)r; }
40747+
static int fio___resp3_err(void *u, void *r) { (void)u, (void)r; }
40748+
static void fio___resp3_free(void *r) { (void)r; }
40749+
/* clang-format on */
40750+
40751+
static void fio___resp3_validate_settings(fio_resp3_settings_s *settings) {
40752+
static const fio_resp3_settings_s defaults = {
40753+
.set_null = NULL,
40754+
.set_true = (void *)1,
40755+
.set_false = NULL,
40756+
.get_number = fio___resp3_get_number,
40757+
.get_float = fio___resp3_get_float,
40758+
.get_bignum = fio___resp3_get_bignum,
40759+
.get_string = fio___resp3_get_string,
40760+
.string_start = fio___resp3_str_start,
40761+
.string_write = fio___resp3_str,
40762+
.array_start = fio___resp3_arr_start,
40763+
.array_push = fio___resp3_arr_push,
40764+
.map_start = fio___resp3_map_start,
40765+
.map_push = fio___resp3_map,
40766+
.done = fio___resp3_done,
40767+
.error = fio___resp3_err,
40768+
.free_response = fio___resp3_free,
40769+
};
40770+
union {
40771+
uintptr_t *ptr;
40772+
fio_resp3_settings_s *s;
40773+
} src, dest;
40774+
src.s = (fio_resp3_settings_s *)&defaults;
40775+
dest.s = settings;
40776+
for (int i = 0; i < sizeof(fio_resp3_settings_s) / sizeof(uintptr_t); ++i)
40777+
if (!dest.ptr[i])
40778+
dest.ptr[i] = src.ptr[i];
40779+
}
40780+
4072240781
/* *****************************************************************************
4072340782
RESP Implementation - inline functions.
4072440783
***************************************************************************** */
4072540784

40726-
SFUNC size_t fio___resp3_parse_start(fio_resp3_s *parser,
40727-
uint8_t *buf,
40728-
size_t len);
40785+
FIO_SFUNC size_t fio___resp3_parse_start(fio_resp3_s *parser,
40786+
uint8_t *buf,
40787+
size_t len);
4072940788
/** Returns an initialized parser. */
4073040789
FIO_IFUNC fio_resp3_s fio_resp3_init(fio_resp3_settings_s *settings,
4073140790
void *udata) {
4073240791
fio_resp3_s r;
40733-
r.private_data.settings = settings;
40792+
fio___resp3_validate_settings(settings);
40793+
r.settings = *settings;
4073440794
r.private_data.parse = fio___resp3_parse_start;
4073540795
r.private_data.depth = 0;
4073640796
r.udata = udata;
@@ -40741,7 +40801,8 @@ FIO_IFUNC fio_resp3_s fio_resp3_init(fio_resp3_settings_s *settings,
4074140801
FIO_IFUNC void fio_resp3_init2(fio_resp3_s *dest,
4074240802
fio_resp3_settings_s *settings,
4074340803
void *udata) {
40744-
dest->private_data.settings = settings;
40804+
fio___resp3_validate_settings(settings);
40805+
dest->settings = *settings;
4074540806
dest->private_data.parse = fio___resp3_parse_start;
4074640807
dest->private_data.depth = 0;
4074740808
dest->udata = udata;

fio-stl/000 copyright.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* *****************************************************************************
2-
Copyright: Boaz Segev, 2019-2024
2+
Copyright: Boaz Segev, 2019-2025
33
License: ISC / MIT (choose your license)
44
55
Feel free to copy, use and enjoy according to the license provided.

0 commit comments

Comments
 (0)