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.
This commit is contained in:
Aurelien DARRAGON 2024-04-29 09:20:46 +02:00
parent 20bc42e697
commit 0e2aea8224
3 changed files with 9 additions and 9 deletions

View File

@ -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 <stop>
*/
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 */

View File

@ -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;
}
}
}

View File

@ -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++;