Moving from Protocol Buffer v2 to v3 - challenges

40 views
Skip to first unread message

Renegade

unread,
Mar 19, 2025, 11:42:50 AMMar 19
to nanopb
Hi all.

I am moving an application to call a protobuff version 3 endpoint which has recently upgraded from v2.

In the past I had the following as an example:

proto:
message AppRequest {
required uint32 seq = 1;
required uint64 playerId = 2;
required int32 playerToken = 3;
optional uint32 entityId = 4;
optional AppEmpty getInfo = 8;
optional AppEmpty getTime = 9;
optional AppEmpty getMap = 10;
optional AppEmpty getTeamInfo = 11;
optional AppEmpty getTeamChat = 12;
optional AppSendMessage sendTeamMessage = 13;
optional AppEmpty getEntityInfo = 14;
optional AppSetEntityValue setEntityValue = 15;
optional AppEmpty checkSubscription = 16;
optional AppFlag setSubscription = 17;
optional AppEmpty getMapMarkers = 18;
optional AppPromoteToLeader promoteToLeader = 20;
optional AppEmpty getClanInfo = 21;
optional AppSendMessage setClanMotd = 22;
optional AppEmpty getClanChat = 23;
optional AppSendMessage sendClanMessage = 24;
optional AppGetNexusAuth getNexusAuth = 25;
optional AppCameraSubscribe cameraSubscribe = 30;
optional AppEmpty cameraUnsubscribe = 31;
optional AppCameraInput cameraInput = 32;
}

I would code a call using a line like:

appRequest.has_getInfo = true;
Amongst others.

Now I moved the proto to v3 it looks like:

protov3:
message AppRequest {
  uint32 seq = 1;
  uint64 playerId = 2;
  int32 playerToken = 3;
 
  oneof action {
    AppEmpty getInfo = 8;
    AppEmpty getTime = 9;
    AppEmpty getMap = 10;
    AppEmpty getTeamInfo = 11;
    AppEmpty getTeamChat = 12;
    AppSendMessage sendTeamMessage = 13;
    AppEmpty getEntityInfo = 14;
    AppSetEntityValue setEntityValue = 15;
    AppEmpty checkSubscription = 16;
    AppFlag setSubscription = 17;
    AppEmpty getMapMarkers = 18;
    AppPromoteToLeader promoteToLeader = 20;
    AppEmpty getClanInfo = 21;
    AppSendMessage setClanMotd = 22;
    AppEmpty getClanChat = 23;
    AppSendMessage sendClanMessage = 24;
    AppGetNexusAuth getNexusAuth = 25;
    AppCameraSubscribe cameraSubscribe = 30;
    AppEmpty cameraUnsubscribe = 31;
    AppCameraInput cameraInput = 32;
  }
}

And I am trying to determine how to code the request type, so it sets it as getInfo.

I note I now have :

appRequest.action
which is a union, but I don't know how to code or assign that action to one of the 'oneof' actions.

Can somebody please help!

Petteri Aimonen

unread,
Mar 19, 2025, 2:33:23 PMMar 19
to nan...@googlegroups.com
Hi,

With oneof, the generated struct will have a field `which_action`.
You should set it to a value such as AppRequest_getInfo_tag.
This replaces the previous has_ field, otherwise it works the same.

--
Petteri

On Wed, Mar 19, 2025 at 08:42:50AM -0700, Renegade wrote:
> Hi all.
>
> I am moving an application to call a protobuff version 3 endpoint which has
> recently upgraded from v2.
>
> In the past I had the following as an example:
>
> *proto:*
> *protov3:*
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nanopb+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/nanopb/92eea118-9ff9-4929-bc1e-4ebf61de3a4en%40googlegroups.com.
> --
> You received this message because you are subscribed to the Google
> Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [1]nanopb+un...@googlegroups.com.
> To view this discussion visit
> [2]https://groups.google.com/d/msgid/nanopb/92eea118-9ff9-4929-bc1e-4eb
> f61de3a4en%40googlegroups.com.
>
> References
>
> 1. mailto:nanopb+un...@googlegroups.com
> 2. https://groups.google.com/d/msgid/nanopb/92eea118-9ff9-4929...@googlegroups.com?utm_medium=email&utm_source=footer


Renegade

unread,
Mar 19, 2025, 7:46:35 PMMar 19
to nanopb
Hello Petteri,

Excellent this has worked! Thank you very much!
Reply all
Reply to author
Forward
0 new messages