#pragma once #include #include #include #include class Reader; using GenericRequestJsonHandler = std::function(Reader&)>; using GenericResponseJsonHandler = std::function(Reader&)>; using GenericNotificationJsonHandler = std::function(Reader&)>; class MessageJsonHandler { public: std::map method2request; std::map method2response; std::map method2notification; GenericRequestJsonHandler const* GetRequestJsonHandler(char const* methodInfo) const { auto const findIt = method2request.find(methodInfo); return findIt == method2request.end() ? nullptr : &findIt->second; } void SetRequestJsonHandler(std::string const& methodInfo, GenericRequestJsonHandler handler) { method2request[methodInfo] = handler; } GenericResponseJsonHandler const* GetResponseJsonHandler(char const* methodInfo) const { auto const findIt = method2response.find(methodInfo); return findIt == method2response.end() ? nullptr : &findIt->second; } void SetResponseJsonHandler(std::string const& methodInfo, GenericResponseJsonHandler handler) { method2response[methodInfo] = handler; } GenericNotificationJsonHandler const* GetNotificationJsonHandler(char const* methodInfo) const { auto const findIt = method2notification.find(methodInfo); return findIt == method2notification.end() ? nullptr : &findIt->second; } void SetNotificationJsonHandler(std::string const& methodInfo, GenericNotificationJsonHandler handler) { method2notification[methodInfo] = handler; } std::unique_ptr parseResponseMessage(std::string const&, Reader&); std::unique_ptr parseRequstMessage(std::string const&, Reader&); bool resovleResponseMessage(Reader&, std::pair>& result); std::unique_ptr parseNotificationMessage(std::string const&, Reader&); };