]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: tools/cbor: rename cbor_encode_ctx struct members
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 29 Apr 2024 07:20:46 +0000 (09:20 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 29 Apr 2024 12:47:37 +0000 (14:47 +0200)
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.

include/haproxy/tools-t.h
src/log.c
src/tools.c

index b6d674d8b23c1e7f352287728bfa676ac36d5fbb..a63e0f6d20ecd1dca0f6918d9e8d550e152af2c8 100644 (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 */
index 2e8e1b28154c8327fd4e2dbe84d2b897e45c8ce2..68399a1e069c184f7069df11970786d9f470467d 100644 (file)
--- 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;
                }
        }
 }
index 19d48d62e4d6b38c5e853470fa0891f7f66b5cb1..61e0eaf6ff895cb48a9d29142a33750c3d0c18c7 100644 (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++;