netty 에서 Protobuf 사용 하기
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());
}
}
ChannelPipeline
에 ProtobufVarint32FrameDecoder
를 추가 합 니 다. 주로 세 미 패키지 처리 에 사 용 됩 니 다. 추가 ProtobufDecoder
디코더 입 니 다. 그 매개 변 수 는 com.google.protobuf.MessageLite
실제 적 으로 디 코딩 이 필요 한 목표 유형 이 무엇 인지 알려 주 는 것 입 니 다.ProtobufDecoder
: ProtobufVarint32LengthFieldPrepender
message 의 각 filed 를 규칙 에 따라 출력 할 뿐 ProtobufEncoder
이 없 기 때문에 socket 은 package (패키지) 를 판정 할 수 없습니다. 이 Encoder 의 역할 은 serializedSize
생 성 된 바이트 배열 앞에서 ProtobufEncoder
숫자 를 설정 하 는 것 입 니 다. varint32
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Netty Echo 클라이언트 작성 - (2)서버에 연결 각 메시지에 대해 서버에서 보내는 동일한 메시지를 기다리고 받습니다 연결 해제 서버와 같이 클라이언트는 데이터를 처리하는 데 사용되는 Channel InboundHandler를 가지고 있습니다.이 장면에...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.