netty 에서 Protobuf 사용 하기

1293 단어 netty자바
private class ChildChannelHandler extends ChannelInitializer {
        @Override
        protected void initChannel(SocketChannel ch) {
            ch.pipeline().addLast("protobufFrameDecoder", new ProtobufVarint32FrameDecoder());

            ch.pipeline().addLast("protobuf decoder", new ProtobufDecoder(SubscribeReqPeoro.SubscribeReq.getDefaultInstance()));

            ch.pipeline().addLast("LengthFieldPrepender", new ProtobufVarint32LengthFieldPrepender());
            ch.pipeline().addLast("protobuf encoder", new ProtobufEncoder());

            ch.pipeline().addLast(new TimeServerHandler());
        }
    }
ChannelPipelineProtobufVarint32FrameDecoder 를 추가 합 니 다. 주로 세 미 패키지 처리 에 사 용 됩 니 다. 추가 ProtobufDecoder 디코더 입 니 다. 그 매개 변 수 는 com.google.protobuf.MessageLite 실제 적 으로 디 코딩 이 필요 한 목표 유형 이 무엇 인지 알려 주 는 것 입 니 다.ProtobufDecoder: ProtobufVarint32LengthFieldPrepender message 의 각 filed 를 규칙 에 따라 출력 할 뿐 ProtobufEncoder 이 없 기 때문에 socket 은 package (패키지) 를 판정 할 수 없습니다. 이 Encoder 의 역할 은 serializedSize 생 성 된 바이트 배열 앞에서 ProtobufEncoder 숫자 를 설정 하 는 것 입 니 다. varint32

좋은 웹페이지 즐겨찾기