Cgi类

微信NetSceneBase实现繁琐代码较多,注册反注册易错易漏,以及并不常用的一对多广播模式。我们用Pipeline实现一个Cgi<_Resp extends ResponseProtoBuf>类替代NetSceneBase

NetSceneGetChatRoomInfoDetail改造为例,新的实现如下

public class CgiGetChatroomInfoDetail extends Cgi<GetChatRoomInfoDetailResponse> {

    public CgiGetChatroomInfoDetail(String chatroomName) {
        super();

        CommReqResp.Builder builder = new CommReqResp.Builder();

        GetChatRoomInfoDetailRequest request = new GetChatRoomInfoDetailRequest();
        request.ChatRoomName = chatroomName;

        builder.setRequest(request);
        builder.setResponse(new GetChatRoomInfoDetailResponse());
        builder.setUri...;
        builder.setFuncId...;
        builder.setRequestCmdId...;
        builder.setResponseCmdId...;
        CommReqResp rr = builder.buildInstance();

        setReqResp(rr);  // 一定要set rr
    }

}

调用也很简单:

new CgiGetChatroomInfoDetail(roomId)
    .run()
    .lifeCycle(this)
    .$ui(new Functional<Void, Cgi.CgiBack<GetChatRoomInfoDetailResponse>>() {
        @Override
        public Void call(Cgi.CgiBack<GetChatRoomInfoDetailResponse> back) {
            if (errorProcess(back.errType, back.errCode, back.errMsg)) {
                return nil;
            }

            ...

            return nil;
        }
    });

对比NetSceneGetChatRoomInfoDetail实现请翻看NetSceneGetChatRoomInfoDetail.java

results matching ""

    No results matching ""