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