Repository: valkey-io/valkey
File: src/networking.c (C)

Code before:
} clientFilter;

/* Types of payloads in reply buffers (c->buf and c->reply)
 * Unencoded buffers contain plain replies only
 * Encoded buffers contain headers followed by either plain replies or
 * by bulk string references */
typedef enum {
    PLAIN_REPLY = 0, /* plain reply */
    BULK_STR_REF     /* bulk string references */
} payloadType;

typedef struct PayloadHeaderFlags {
    uint8_t track_bytes : 1; /* 1 if net bytes tracking was enabled when reply was added */
    uint8_t reserved : 7;
} PayloadHeaderFlags;

/* Encoded reply buffers consist from chunks
 * Each chunk contains header followed by payload
 * The packed attribute is specified because buffer is accessed at arbitrary offsets,
 * so no benefit in data structure padding and applying packed saves the space in the buffer  */
typedef struct __attribute__((__packed__)) payloadHeader {
    size_t payload_len;   /* payload length in a reply buffer */
    size_t reply_len;     /* actual reply length for non-plain payloads */
    uint8_t payload_type; /* one of payloadType */
    int16_t slot;         /* to report network-bytes-out for BULK_STR_REF chunks */
    PayloadHeaderFlags flags;
} payloadHeader;

/* To avoid copy of whole string in reply buffer
 * we store pointers to object and string itself */
typedef struct __attribute__((__packed__)) bulkStrRef {
    robj *obj; /* pointer to object used for reference count management */
    sds str;   /* pointer to string to optimize memory access by I/O thread */
} bulkStrRef;

static void setProtocolError(const char *errstr, client *c);
static void pauseClientsByClient(mstime_t end, int isPauseClientAll);
int postponeClientRead(client *c);
char *getClientSockname(client *c);
static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter);
static int clientMatchesFilter(client *client, clientFilter *client_filter);
static int validateClientFlagFilter(sds flag_filter);
static int validateClientCapaFilter(sds capa);
static sds getAllFilteredClientsInfoString(clientFilter *client_filter, int hide_user_data);
static int clientMatchesFlagFilter(client *c, sds flag_filter);
static int clientMatchesIpFilter(client *c, sds ip);
static int clientMatchesCapaFilter(client *c, sds capa_filter);
static void freeClientFilter(clientFilter *filter);
static bool consumeCommandQueue(client *c);
static int parseMultibulk(client *c,
                          int *argc,

Review comment (suggestion):
It appears to me that we can pack this more and save one byte. `payload_type` actually just needs one bit.

```suggestion
    int16_t slot;             /* to report network-bytes-out for BULK_STR_REF chunks */
    uint8_t payload_type : 1; /* one of payloadType */
    uint8_t track_bytes : 1;
    uint8_t reserved : 6;
```

Code after:
} clientFilter;

/* Types of payloads in reply buffers (c->buf and c->reply)
 * Unencoded buffers contain plain replies only
 * Encoded buffers contain headers followed by either plain replies or
 * by bulk string references */
typedef enum {
    PLAIN_REPLY = 0, /* plain reply */
    BULK_STR_REF     /* bulk string references */
} payloadType;

/* Encoded reply buffers consist from chunks
 * Each chunk contains header followed by payload
 * The packed attribute is specified because buffer is accessed at arbitrary offsets,
 * so no benefit in data structure padding and applying packed saves the space in the buffer  */
typedef struct __attribute__((__packed__)) payloadHeader {
    size_t payload_len;       /* payload length in a reply buffer */
    size_t reply_len;         /* actual reply length for non-plain payloads */
    int16_t slot;             /* to report network-bytes-out for BULK_STR_REF chunks */
    uint8_t payload_type : 1; /* one of payloadType */
    uint8_t track_bytes : 1;  /* 1 if net bytes tracking was enabled when reply was added */
    uint8_t reserved : 6;
} payloadHeader;

/* To avoid copy of whole string in reply buffer
 * we store pointers to object and string itself */
typedef struct __attribute__((__packed__)) bulkStrRef {
    robj *obj; /* pointer to object used for reference count management */
    sds str;   /* pointer to string to optimize memory access by I/O thread */
} bulkStrRef;

static void setProtocolError(const char *errstr, client *c);
static void pauseClientsByClient(mstime_t end, int isPauseClientAll);
int postponeClientRead(client *c);
char *getClientSockname(client *c);
static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter);
static int clientMatchesFilter(client *client, clientFilter *client_filter);
static int validateClientFlagFilter(sds flag_filter);
static int validateClientCapaFilter(sds capa);
static sds getAllFilteredClientsInfoString(clientFilter *client_filter, int hide_user_data);
static int clientMatchesFlagFilter(client *c, sds flag_filter);
static int clientMatchesIpFilter(client *c, sds ip);
static int clientMatchesCapaFilter(client *c, sds capa_filter);
static void freeClientFilter(clientFilter *filter);
static bool consumeCommandQueue(client *c);
static int parseMultibulk(client *c,
                          int *argc,
                          robj ***argv,
                          int *argv_len,
                          size_t *argv_len_sum,
                          unsigned long long *net_input_bytes_curr_cmd);