Search code examples
c++metadatagrpcrpc

Showing metadata on response side with GRPC on BloomRPC


My goal is sending source part from request to response side. In bloomRPC, with these codes, I can send name and uuid to response side, but I cannot send metadata. Is there a similar code that I can go for metadata in here? If you need editor and response in bloomRPC, I can send that too.

//main.cpp:
class RouteGuideImpl final: public project::EventServer::Service{
    public:
        grpc::Status PubEvent(grpc::ServerContext *context, const events::PubEventRequest *request, events::PubEventResponse *response){
        std::cout<<"Welcome"<<std::endl;
        for(int i=0;i<request->eventsize();i++){
            auto value= response->add.subs();
            value->set_name(request->events(i).source().name());
            value->set_uuid(request->events(i).source().uuid());
        }
        return grpc::Status::OK;
    }
};
//.proto file:
message Source{
    string name = 1;
    string uuid = 2;
    map<string,string> metadata = 3;
}

Solution

  • Well, metadata is a google map object. So I did this and it worked:

    for(const auto& elements_source_metadata : request->events(i).source().metadata()){
    x->mutable_metadata()->insert({elements_source_metadata.first,
                                   elements_source_metadata.second});