You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Protobuf经Dapr-Redis传输后全字段反序列化失败排查

Proto反序列化Any类型失败:仅全字段赋值时触发"invalid wire-format data"错误

将字节数据反序列化为any.Any类型时失败,报错信息:

proto: cannot parse invalid wire-format data

仅当消息所有字段均赋值时触发该问题,空消息或部分字段赋值的消息可正常反序列化,疑似存在消息大小限制。消息经Dapr适配器传输至Redis流,本地直接执行序列化/反序列化无异常,仅通过Dapr-Redis传输的消息出现该问题,非此链路传输的消息无此现象。


反序列化代码

import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/any"
)

func (h *EventHandler) instanceHandler(ctx context.Context, e *common.TopicEvent) (bool, error) {

    var anyMsg any.Any
    b := []byte(e.Data.(string))
    err := proto.Unmarshal(b, &anyMsg)
    if err != nil {
        h.logger.Error().
            Str("eventId", e.ID).
            Str("topic", e.Topic).
            Str("source", e.Source).
            Err(err).
            Msg("")

        return false, err
    }

}

Protobuf消息结构

message GetElementsPaginatedRequest {
  string eid = 1;
  string mediatorID = 2;
  string callerID = 3;
  string accountID = 4;
  string streamID = 5;
  int32 limit = 6;
  int32 page = 7;
  string order = 8;
  string clientID = 9;
}

发送前序列化代码

err := anyMsg.MarshalFrom(&epb)
if err != nil {
    return err
}

b, err := proto.Marshal(&anyMsg)
if err != nil {
    return err
}

排查线索

  • 移除任意字段(如accountID)后,反序列化可成功
  • 本地测试序列化与反序列化均正常,仅Dapr+Redis传输链路出现异常
  • 非Dapr-Redis传输的消息无此问题

内容的提问来源于stack exchange,提问作者sevvaio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 22:33:28