Skip to content

Commit

Permalink
Add more accessible methods to parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidr committed Jan 11, 2017
1 parent 0259466 commit e5e25dd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions includes/async_redis/parser/base_resp_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ namespace async_redis {
virtual int parse_append(const char*, ssize_t, bool&) = 0;
virtual std::string to_string() const = 0;
virtual void map(const caller_t &fn);
bool is_array() const;
bool is_number() const;
bool is_string() const;
bool is_enum() const;
bool is_error() const;

void print();
};
Expand Down
30 changes: 30 additions & 0 deletions src/parser/base_resp_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ base_resp_parser::append_chunk(base_resp_parser::parser& data, const char* chunk
return data->parse_append(chunk, length, is_finished);
}

bool
base_resp_parser::is_array() const
{
this->type() == RespType::Arr;
}

bool
base_resp_parser::is_number() const
{
this->type() == RespType::Num;
}

bool
base_resp_parser::is_error() const
{
this->type() == RespType::Err;
}

bool
base_resp_parser::is_string() const
{
this->type() == RespType::BulkStr;
}

bool
base_resp_parser::is_enum() const
{
this->type() == RespType::Str;
}

void
base_resp_parser::print()
{
Expand Down

0 comments on commit e5e25dd

Please sign in to comment.