2 ms·
Well, isn't still type-safe then? If every field is optional, then a zero byte message is a totally valid message. The issue is that every field is optional, an
by 0x457 4y ago
Well, isn't still type-safe then? If every field is optional, then a zero byte message is a totally valid message. The issue is that every field is optional, and there are no required fields at all.
I'm very annoyed that all fields are optional. Which means I have to do additional validation on server side and in a language like rust it's double annoying because now you have `T` or `Option<T>` and it's confusing for some types:
- `string` will be rust's `String` except it is an empty string by default
- All "custom" types are `Option<T>` even if that makes no sense semantically
So now you have to check if a string is empty, which I guess is technically a string anyway. However, now you have no idea, it is an empty string as a value or lack of value? You end up wrapping `string` into a `StringValue` and now linter is complaining that you shouldn't use those.
Overall parser for protobuf messages got simpler, but now enforcing safety is on server's implementation.
- jeffbee 4y agoWell, I always try to keep in mind the distinction between protobuf the structured encoding and protobuf the code generator. You can use the former without the latter. Considering that the project doesn't even ship a codegen for Rust, you're already doing that. So if there's some more convenient API you'd like, you can just have it. You can also do this with protoc plugins and the official codegen, or you can hand-roll your own protocol parsers which isn't that crazy with such a simple format.