muduo解包消息分发

1.dispatcher_.registerMessageCallback 这个会将回调函数存入ProtobufDispatcher的std::map中,其中T::descriptor()为key

2.client_.setMessageCallback(std::bind(&ProtobufCodec::onMessage, &codec_, _1, _2, _3)) 设置消息到来时的回调函数,回调

ProtobufCodec::onMessage

3.codec_(std::bind(&ProtobufDispatcher::onProtobufMessage, &dispatcher_, _1, _2, _3)) 创建ProtobufCodec类实例,并传入ProtobufCodec::onMessage触发时的回调函数onProtobufMessage(messageCallback_ = onProtobufMessage)

4.onProtobufMessage会找到当初注册时传入的函数对象(类CallbackT ),并将消息类型做向下转换,然后触发用户设置的回调函数

发布了47 篇原创文章 · 获赞 20 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/boiled_water123/article/details/104016062