-
Notifications
You must be signed in to change notification settings - Fork 75
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
External well-known structures support #80
External well-known structures support #80
Conversation
It's also worth noticing that |
Should we make a step back and discuss the overall approach for well known types? I'm not sure if I get idea right, but it seems like you want to add wkt support as "features". There is much simpler approach:
This approach doesn't require any changes in the existing code at all. |
@biosvs: thanks for the insight. I quite like this idea from an implementation point of view; my concern is that the developer experience is not ideal, as you'd have to manually add the import replacements to your I've just noticed that Vitess actually uses a couple WKTs, so I'm gonna attempt this approach to see how it works out in practice. |
Short update: turns out that Vitess uses its own custom types instead of Pb Well-known Types, so I don't have any input to offer here. I'd like to hear some other people's opinions before I close this PR for @biosvs's approach. |
👋 I'm back from vacations, it's nice seeing activity on this topic again because well known types are currently holding off vtprotobuf capabilities for messages that use a lot of them. I would love to see this support added! (Disclaimer: I haven't reviewed this specific PR thoroughly, just adding my thoughts on the general discussion.) Re: @biosvs' approach -- unless I'm mistaken, the developer experience impact would not be limited to import replacements in the // change the message timestamp to now
ts := time.Now()
someMessage.Timestamp = timestamppb.New(ts) It may be an acceptable tradeoff, I just want to make sure that we acknowledge what the developer experience will be. There are a couple other approaches mentioned in #54 that could avoid these import replacements. For instance, one approach would be to have public global helper function for WKT (example:
I'm curious to have your thoughts about all of this. On my side, I can find some time to try different approaches. |
@nockty yes, you're right. Here's an example of how it may look like: main...biosvs:vtprotobuf:add-wkt-types |
You also could use type aliases so that existing codebases wouldn't need to migrate to vtproto's implementations. Pseudocode for illustration: // vtproto/timestamppb/generated.go
type Timestamp timestamppb.Timestamp
func (t *Timestamp) MarshalVT() ...
func (t *Timestamp) UnmarshalVT() ...
// my-project-proto/generated.go
func (s *MyStruct) UnmarshalVT() {
if isWKTimestamp(m.field) {
m.field = timestamppb.Timestamp(vtproto_timestamppb.Timestamp(m.field).UnmarshalVT())
}
} |
@pomo-mondreganto generated messages have unexported fields like |
Merged an alternative implementation here: #99 Thank you for getting the ball rolling with this feature! |
I've added support for marshalling, unmarshalling and sizing of external well-known structures (currently tested with
google.protobuf.Duration
andgoogle.protobuf.Timestamp
, which we heavily use in production. My benchmarks show up to x3 speedup for marshalling structures with timestamp fields and up to x1.5 speedup for unmarshalling.Adding other well-known structures should not be a problem, too (just extend the switch-case
MapWellKnown(message *protogen.Message)
with the fully-qualified import path for the external structure).I believe we can even make the well known structures' set dynamic in the future, as Rust's prost does using the
extern_path
option.