1 year ago
#385731
user2698342
gRPC "any" packing: No instance(s) of type variable(s) exist so that ShopData conforms to Message
I'm making a game with a custom server solution written in java that communicates with the game client using gRPC.
I'm attempting to pack a message (ShopData
) into an "any" object, but it's saying no instance(s) of type variable(s) exist so that ShopData conforms to Message
As you can see I have a GameNetworkEvent
message that contains a type flag and an "any" type payload.
I am building a ShopData
payload then am attempting to pack it into the "any" eventPayload
field. However the error seems to imply that ShopData
isn't a message? I don't get how that can be, since it's an auto-generated class from my protobuf message definition
Relevant protobuf definitions
message GameNetworkEvent {
enum Type {
START = 0;
SHOP = 1;
BRAWL = 2;
CHAT = 3;
};
Type eventType = 1;
google.protobuf.Any eventPayload = 2;
}
message ShopData {
int32 gold = 1;
repeated UnitData units = 2;
}
message UnitData {
string name = 1;
int32 attack = 2;
int32 health = 3;
int32 cost = 4;
bool isUpgraded = 5;
}
Message instantiation
FromBeyondProto.ShopData shop =
FromBeyondProto.ShopData.newBuilder()
.addAllUnits(generateRandomShop(10))
.setGold(10)
.build();
FromBeyondProto.GameNetworkEvent response =
FromBeyondProto.GameNetworkEvent.newBuilder()
.setEventType(FromBeyondProto.GameNetworkEvent.Type.SHOP)
.setEventPayload(Any.pack(shop))
.build();
java
protocol-buffers
grpc-java
0 Answers
Your Answer