Nested Enum with protobuf and rust

89 views
Skip to first unread message

Chedy Souffargi

unread,
Apr 19, 2024, 8:10:25 PMApr 19
to Protocol Buffers
I am working on a Rust project, using Protocol Buffers, and dealing with nested enums. Here's what I have so far in Rust:

enum Vehicle { Car(CarType), Truck(TruckType), } enum CarType { Sedan, Coupe, Hatchback, } enum TruckType { Pickup, Semi, } fn create_vehicle_fleet() -> [Vehicle; 8] { [ Vehicle::Car(CarType::Sedan), Vehicle::Truck(TruckType::Pickup), Vehicle::Car(CarType::Coupe), Vehicle::Truck(TruckType::Semi), Vehicle::Car(CarType::Hatchback), Vehicle::Car(CarType::Sedan), Vehicle::Truck(TruckType::Pickup), Vehicle::Car(CarType::Coupe), ] }

I cannot find a proper way to represent the Vehicle enum in protobuf. Can anyone suggest a solution or provide guidance on how to handle this situation in Protocol Buffers?

Daz Wilkin

unread,
Apr 19, 2024, 8:50:46 PMApr 19
to Protocol Buffers
I took a stab at a reply to your question on Stack overflow:

Em Rauch

unread,
May 24, 2024, 9:39:30 AMMay 24
to Daz Wilkin, Protocol Buffers
The suggestion on stack overflow looks correct: Rust's language enums are "tagged unions", the Protobuf `oneof` feature also acts as a tagged union. Protobuf Enums are intended to be more semantically like C++ enums (which cannot hold values inside).

Can you clarify the followup comment "AAOS stands for Android Automotive OS. The IDL that generates publisher code, struggles with message types"? Any documentation links would be helpful for us to follow up on if there's some deliberate limitation or just an unfortunate technical state that might be worked around.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/9827eaf2-7b6f-474c-9cfa-f3fbca084ab8n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages