From: Aurelien DARRAGON Date: Mon, 29 Apr 2024 07:20:46 +0000 (+0200) Subject: CLEANUP: tools/cbor: rename cbor_encode_ctx struct members X-Git-Tag: v3.0-dev10~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0e2aea8224e42f8730a7786be7ce851abb54ab75;p=thirdparty%2Fhaproxy.git CLEANUP: tools/cbor: rename cbor_encode_ctx struct members Rename e_byte_fct to e_fct_byte and e_fct_byte_ctx to e_fct_ctx, and adjust some comments to make it clear that e_fct_ctx is here to provide additional user-ctx to the custom cbor encode function pointers. For now, only e_fct_byte function may be provided, but we could imagine having e_fct_int{16,32,64}() one day to speed up the encoding when we know we can encode multiple bytes at a time, but for now it's not worth the hassle. --- diff --git a/include/haproxy/tools-t.h b/include/haproxy/tools-t.h index b6d674d8b2..a63e0f6d20 100644 --- a/include/haproxy/tools-t.h +++ b/include/haproxy/tools-t.h @@ -174,11 +174,11 @@ struct cbor_encode_ctx { * The function needs to return the position of the last written byte * on success and NULL on failure. The function cannot write past */ - char *(*e_byte_fct)(struct cbor_encode_ctx *ctx, + char *(*e_fct_byte)(struct cbor_encode_ctx *ctx, char *start, char *stop, uint8_t byte); - /* to pass some context to the encode_byte fct */ - void *e_byte_fct_ctx; + /* to provide some user-context to the encode_fct_* funcs */ + void *e_fct_ctx; }; #endif /* _HAPROXY_TOOLS_T_H */ diff --git a/src/log.c b/src/log.c index 2e8e1b2815..68399a1e06 100644 --- a/src/log.c +++ b/src/log.c @@ -1774,7 +1774,7 @@ static char *_encode_byte_hex(char *start, char *stop, unsigned char byte) static char *_lf_cbor_encode_byte(struct cbor_encode_ctx *cbor_ctx, char *start, char *stop, unsigned char byte) { - struct lf_buildctx *ctx = cbor_ctx->e_byte_fct_ctx; + struct lf_buildctx *ctx = cbor_ctx->e_fct_ctx; if (ctx->options & LOG_OPT_BIN) { /* raw output */ @@ -1825,8 +1825,8 @@ static inline void lf_buildctx_prepare(struct lf_buildctx *ctx, if (ctx->options & LOG_OPT_ENCODE_CBOR) { /* prepare cbor-specific encode ctx */ - ctx->encode.cbor.e_byte_fct = _lf_cbor_encode_byte; - ctx->encode.cbor.e_byte_fct_ctx = ctx; + ctx->encode.cbor.e_fct_byte = _lf_cbor_encode_byte; + ctx->encode.cbor.e_fct_ctx = ctx; } } } diff --git a/src/tools.c b/src/tools.c index 19d48d62e4..61e0eaf6ff 100644 --- a/src/tools.c +++ b/src/tools.c @@ -2109,7 +2109,7 @@ char *cbor_encode_uint64_prefix(struct cbor_encode_ctx *ctx, } } - start = ctx->e_byte_fct(ctx, start, stop, prefix); + start = ctx->e_fct_byte(ctx, start, stop, prefix); if (start == NULL) return NULL; @@ -2117,7 +2117,7 @@ char *cbor_encode_uint64_prefix(struct cbor_encode_ctx *ctx, while (nb_bytes) { uint8_t cur_byte = (value >> ((nb_bytes - 1) * 8)) & 0xFFU; - start = ctx->e_byte_fct(ctx, start, stop, cur_byte); + start = ctx->e_fct_byte(ctx, start, stop, cur_byte); if (start == NULL) return NULL; @@ -2181,7 +2181,7 @@ char *cbor_encode_bytes_prefix(struct cbor_encode_ctx *ctx, /* write actual bytes if provided */ while (bytes && it < len) { - start = ctx->e_byte_fct(ctx, start, stop, bytes[it]); + start = ctx->e_fct_byte(ctx, start, stop, bytes[it]); if (start == NULL) return NULL; it++;