1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* Copyright (c) 2021-Present, Redis Ltd.
* All rights reserved.
*
* Licensed under your choice of (a) the Redis Source Available License 2.0
* (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the
* GNU Affero General Public License v3 (AGPLv3).
*/
#ifndef SRC_RESP_PARSER_H_
#define SRC_RESP_PARSER_H_
#include <stddef.h>
typedef struct ReplyParser ReplyParser;
typedef struct ReplyParserCallbacks {
/* Called when the parser reaches an empty mbulk ('*-1') */
void (*null_array_callback)(void *ctx, const char *proto, size_t proto_len);
/* Called when the parser reaches an empty bulk ('$-1') (bulk len is -1) */
void (*null_bulk_string_callback)(void *ctx, const char *proto, size_t proto_len);
/* Called when the parser reaches a bulk ('$'), which is passed as 'str' along with its length 'len' */
void (*bulk_string_callback)(void *ctx, const char *str, size_t len, const char *proto, size_t proto_len);
/* Called when the parser reaches an error ('-'), which is passed as 'str' along with its length 'len' */
void (*error_callback)(void *ctx, const char *str, size_t len, const char *proto, size_t proto_len);
/* Called when the parser reaches a simple string ('+'), which is passed as 'str' along with its length 'len' */
void (*simple_str_callback)(void *ctx, const char *str, size_t len, const char *proto, size_t proto_len);
/* Called when the parser reaches a long long value (':'), which is passed as an argument 'val' */
void (*long_callback)(void *ctx, long long val, const char *proto, size_t proto_len);
/* Called when the parser reaches an array ('*'). The array length is passed as an argument 'len' */
void (*array_callback)(struct ReplyParser *parser, void *ctx, size_t len, const char *proto);
/* Called when the parser reaches a set ('~'). The set length is passed as an argument 'len' */
void (*set_callback)(struct ReplyParser *parser, void *ctx, size_t len, const char *proto);
/* Called when the parser reaches a map ('%'). The map length is passed as an argument 'len' */
void (*map_callback)(struct ReplyParser *parser, void *ctx, size_t len, const char *proto);
/* Called when the parser reaches a bool ('#'), which is passed as an argument 'val' */
void (*bool_callback)(void *ctx, int val, const char *proto, size_t proto_len);
/* Called when the parser reaches a double (','), which is passed as an argument 'val' */
void (*double_callback)(void *ctx, double val, const char *proto, size_t proto_len);
/* Called when the parser reaches a big number ('('), which is passed as 'str' along with its length 'len' */
void (*big_number_callback)(void *ctx, const char *str, size_t len, const char *proto, size_t proto_len);
/* Called when the parser reaches a string ('='), which is passed as 'str' along with its 'format' and length 'len' */
void (*verbatim_string_callback)(void *ctx, const char *format, const char *str, size_t len, const char *proto, size_t proto_len);
/* Called when the parser reaches an attribute ('|'). The attribute length is passed as an argument 'len' */
void (*attribute_callback)(struct ReplyParser *parser, void *ctx, size_t len, const char *proto);
/* Called when the parser reaches a null ('_') */
void (*null_callback)(void *ctx, const char *proto, size_t proto_len);
void (*error)(void *ctx);
} ReplyParserCallbacks;
struct ReplyParser {
/* The current location in the reply buffer, needs to be set to the beginning of the reply */
const char *curr_location;
ReplyParserCallbacks callbacks;
};
int parseReply(ReplyParser *parser, void *p_ctx);
#endif /* SRC_RESP_PARSER_H_ */
|