Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better representation of enums #197

Closed
vlisivka opened this issue Jun 18, 2019 · 1 comment
Closed

Better representation of enums #197

vlisivka opened this issue Jun 18, 2019 · 1 comment

Comments

@vlisivka
Copy link

I need to parse log of protobuf messages, generated by {:?}, back into protobuf objects, to replay messages. I forked RON deserializer, and made few changes to be able to deserialize {:?} representation. However, I cannot deserialize prost objects, because they use i32 instead of enum to represent enum, so information about actual type of field is lost. Unfortunately, this is limitation of Rust language itself. I hope, it will be fixed soon when RFC 2008 #[non_exhaustive] will be implemented and will work properly for #[repr(C)] enum's.

As workaround, I propose to use union(enum, i32) instead of plain i32, to save information about type. My proof of concept can be found here:
https://play.rust-lang.org/?gist=6131d0fcadd0bf2bba48a3efe26278f0

prost already generates is_valid() method for enum's, so it will not be hard to add generic union, use it instead of i32, and implement IsValidEnum trait for every protobuf enum.

@vlisivka
Copy link
Author

Closed in favor of #43, because #[non_exhaustive] tag is stabilized/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant