memgraph/include/communication/bolt/v1/states/message_parser.hpp

34 lines
794 B
C++
Raw Normal View History

2016-08-02 05:14:09 +08:00
#pragma once
#include "communication/bolt/v1/session.hpp"
#include "communication/bolt/v1/states/state.hpp"
#include "utils/crtp.hpp"
2016-08-02 05:14:09 +08:00
namespace bolt
{
template <class Derived>
class MessageParser : public State, public Crtp<Derived>
{
public:
MessageParser(Logger &&logger) : logger(std::forward<Logger>(logger)) {}
2016-08-02 05:14:09 +08:00
State *run(Session &session) override final
2016-08-02 05:14:09 +08:00
{
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;
2016-08-02 05:14:09 +08:00
logger.debug("Executing state");
return this->derived().execute(session, message);
}
protected:
Logger logger;
};
}