tinyrpc/includes/net/tinypb/tinypb_dispatcher.hpp

29 lines
901 B
C++
Raw Permalink Normal View History

2025-01-21 16:35:26 +08:00
#pragma once
#include "abstract_dispatcher.hpp"
2025-02-04 16:09:27 +08:00
#include <memory>
2025-01-21 16:35:26 +08:00
#include <unordered_map>
#include <google/protobuf/message.h>
#include <google/protobuf/service.h>
#include <google/protobuf/descriptor.h>
namespace tinyrpc {
class TinypbDispatcher : public AbstractDispatcher {
using Service = google::protobuf::Service;
2025-01-22 17:58:45 +08:00
using Method = google::protobuf::MethodDescriptor;
using Message = google::protobuf::Message;
2025-01-21 16:35:26 +08:00
public:
TinypbDispatcher();
~TinypbDispatcher();
2025-02-04 16:09:27 +08:00
void dispatcher(ServerTcpConnection& conn, AbstractData& data, AbstractData& respond) override;
2025-01-21 16:35:26 +08:00
bool parseServiceFullName(const std::string& name, std::string& serviceName, std::string& methodName);
2025-02-04 16:09:27 +08:00
void registerService(std::shared_ptr<Service>& service);
2025-01-21 16:35:26 +08:00
private:
2025-02-04 16:09:27 +08:00
std::unordered_map<std::string, std::shared_ptr<Service>> m_service_map;
2025-01-21 16:35:26 +08:00
};
}