memgraph/src/bolt/v1/states/message_parser.hpp

38 lines
772 B
C++
Raw Normal View History

2016-08-02 05:14:09 +08:00
#pragma once
#include "state.hpp"
#include "utils/crtp.hpp"
#include "bolt/v1/session.hpp"
namespace bolt
{
template <class Derived>
class MessageParser : public State, public Crtp<Derived>
{
public:
MessageParser(Logger&& logger)
: logger(std::forward<Logger>(logger)) {}
State* run(Session& session) override final
{
typename Derived::Message message;
logger.debug("Parsing message");
auto next = this->derived().parse(session, message);
// return next state if parsing was unsuccessful (i.e. error state)
if(next != &this->derived())
return next;
logger.debug("Executing state");
return this->derived().execute(session, message);
}
protected:
Logger logger;
};
}