
php小编新一在这里为大家介绍一种问题:在Protobuf消息中,我们发现没有实现protoreflect.ProtoMessage接口的ProtoReflect方法,而该方法使用了指针接收器。这个问题可能会导致一些困惑和不便。在文章中,我们将深入探讨这个问题的原因和可能的解决方案,以帮助大家更好地理解和应对这个问题。让我们一起来了解吧!
我有一条 protobuf 消息导入 "google/protobuf/any.proto":
message mintrecord {
...
google.protobuf.any data = 11;
...
}我正在尝试使用anypb序列化data字段内的另一个protobuf:
data, err := anypb.new(protobuf.lootcrateprize{
items: &protobuf.inventory{items: items},
roll: fmt.sprintf("%f", roll),
})
if err != nil {
log.println("[lootbox] err: error marshalling lootcrate prize data into mintrec", err)
} else {
mintrecordproto.data = data
}编译后出现以下错误:
cannot use protobuf.lootcrateprize{…} (value of type protobuf.lootcrateprize) as type protoreflect.protomessage in argument to anypb.new:
protobuf.lootcrateprize does not implement protoreflect.protomessage (protoreflect method has pointer receiver)根据文档,我在这里没有做任何异常的事情。我该如何解决这个问题?
这是我尝试序列化并存储在 data 字段内的 protobuf:
lootcrate.proto:
syntax = "proto3";
package protobuf;
option go_package = "protobuf/";
import "protobuf/inventory.proto";
import "protobuf/flowerdbservice.proto";
message LootcratePrize {
Inventory items = 1;
repeated NFT flowers = 2;
string roll = 3;
}sarath sadasivan pillai 是正确的。
将您的代码更改为:
data, err := anypb.New(&protobuf.LootcratePrize{
Items: &protobuf.Inventory{Items: items},
Roll: fmt.Sprintf("%f", roll),
})以上就是Protobuf消息没有实现protoreflect.ProtoMessage(ProtoReflect方法有指针接收器)的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号