-
Notifications
You must be signed in to change notification settings - Fork 78
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
Call Reset before UnmarshallVT to keep the default grpc semantic #131
base: main
Are you sure you want to change the base?
Conversation
You should do the same trick as the code does to detect the |
In addition to @bhollis's comment I'd suggest to extract |
@@ -25,6 +31,12 @@ func (Codec) Unmarshal(data []byte, v interface{}) error { | |||
if !ok { | |||
return fmt.Errorf("failed to unmarshal, message is %T (missing vtprotobuf helpers)", v) | |||
} | |||
//All types that implement github.com/golang/protobuf/proto.Message have a Reset method | |||
vv, ok := v.(reseter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vv, ok := v.(reseter) | |
vv, ok := v.(interface { ResetVT() }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't require the message to implement ResetVT()
because this method isn't generated by default (it requires the pool
option)
Doing so would break the codec for user who just use the marshal
and umarshal
features
But I can follow this style and do
vv, ok := v.(reseter) | |
vv, ok := v.(interface{ Reset() }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right :) IMO the resetvt func should be turned into a plug-in that's activated automatically with pool plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you mean that ResetVT()
should be generated automatically when the unmarshal plugin is enabled ?
Fixes #128
Contrary to what was discussed in the issue, I was not able to call
ResetVT()
beforeUnmarshallVT()
because the reset method isn't always generated (it's only generated when the pool option is enabled)Perhaps the
ResetVT()
method should also be generated when the unmarshal feature is enabled ?