Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit e5e25dd

Browse files
author
hamidr
committed
Add more accessible methods to parsers
1 parent 0259466 commit e5e25dd

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

includes/async_redis/parser/base_resp_parser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ namespace async_redis {
3030
virtual int parse_append(const char*, ssize_t, bool&) = 0;
3131
virtual std::string to_string() const = 0;
3232
virtual void map(const caller_t &fn);
33+
bool is_array() const;
34+
bool is_number() const;
35+
bool is_string() const;
36+
bool is_enum() const;
37+
bool is_error() const;
3338

3439
void print();
3540
};

src/parser/base_resp_parser.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ base_resp_parser::append_chunk(base_resp_parser::parser& data, const char* chunk
5151
return data->parse_append(chunk, length, is_finished);
5252
}
5353

54+
bool
55+
base_resp_parser::is_array() const
56+
{
57+
this->type() == RespType::Arr;
58+
}
59+
60+
bool
61+
base_resp_parser::is_number() const
62+
{
63+
this->type() == RespType::Num;
64+
}
65+
66+
bool
67+
base_resp_parser::is_error() const
68+
{
69+
this->type() == RespType::Err;
70+
}
71+
72+
bool
73+
base_resp_parser::is_string() const
74+
{
75+
this->type() == RespType::BulkStr;
76+
}
77+
78+
bool
79+
base_resp_parser::is_enum() const
80+
{
81+
this->type() == RespType::Str;
82+
}
83+
5484
void
5585
base_resp_parser::print()
5686
{

0 commit comments

Comments
 (0)