惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
小众软件
小众软件
美团技术团队
Martin Fowler
Martin Fowler
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
J
Java Code Geeks
B
Blog
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
博客园 - Franky

博客园 - 三驾马车

Claude Code 官宣:可以在 IDEA 用了! idea gitee 更新已取消 解决方案 ByteBuffer和ByteBuf区别 Marshalling.getProvidedMarshallerFactory("serial") 参数有那些 protobuf 的 Varint 编码规范 netty initChannel ch.pipeline().addLast 先后顺序很重要 ChannelInboundHandlerAdapter 的channelRead和channelReadComplete的区别 Unpooled.buffer()和Unpooled.copiedBuffer区别 ServerBootstrap 和Bootstrap 区别 childhandler 和 handler 区别 ChannelInitializer<SocketChannel> 的作用详解 ChannelHandlerAdapter 和 ChannelInboundHandlerAdapter 的区别 SimpleChannelInboundHandler 中的 messageReceived 和 channelRead0 ChannelHandlerAdapter 与 ChannelInboundHandler 的区别 Application run failed .ParserException: while parsing a block mapping in 'reader' openssl genrsa 自签名ssl证书 上传本地项目到新建git项目 save download pdf
ProtobufVarint32FrameDecoder和ProtobufDecoder区别
三驾马车 · 2025-05-21 · via 博客园 - 三驾马车

1. ProtobufVarint32FrameDecoder 的输出是 去除了 Varint32 长度头的纯 protobuf 消息体,确保:

  1. 消息完整性(无粘包/半包问题)。

  2. 直接适配 ProtobufDecoder 的输入要求。

2. ProtobufDecoder 用于处理 Protocol Buffers (protobuf) 二进制数据的解码器,其 处理后的结果是将字节流(ByteBuf)转换为具体的 Java 对象(即 protobuf 生成的 Message 子类)

  1. 接收前驱解码器的输出

    • 前驱通常是 ProtobufVarint32FrameDecoder,负责提供完整的消息体(不含长度前缀)。

  2. 解析二进制数据

    • 根据 protoc 生成的 Java 类(如 MyMessage),将 ByteBuf 反序列化为对象。

  3. 传递对象给下一个处理器

                 输出解码后的对象,供后续 ChannelHandler(如业务处理器)使用。

ProtobufDecoder 的输出是 完全解析后的 protobuf Java 对象,其核心作用包括:

  1. 二进制 → 对象转换:将网络字节流反序列化为内存中的结构化数据。

  2. 与业务逻辑衔接:直接提供可操作的对象,避免手动解析。