You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The README state than an easy way to use the vtprotobuf generated code is to change the default grpc codec to use github.com/planetscale/vtprotobuf/codec/grpc.Codec
However the unmarshal operation of this custom codec has different semantics than the default one: it performs a merge rather than an override.
This is documented in the UnmarshalVT doc but it's easy to miss.
This can be an issue when using grpc streams, because some valid code with the default codec will change behavior:
func (Server) SomeStreamRPC(stream pb.Test_StreamServer) error {
msg:=new(pb.SomeMsg)
for {
// msg.ResetVT() <- This is required to keep the same behavior after changing the codec err:=stream.RecvMsg(msg)
iferr!=nil {
returnerr
}
// Do something with msg ...
}
}
I'd suggest that the codec is this repo calls msg.ResetVT() before UnmarhsalVT to keep the semantics of the default codec.
Advanced user can still pass their own codec that does not call ResetVT if they require it.
The text was updated successfully, but these errors were encountered:
Good catch. I think this is a sensible change for the default implementation, since it can be overriden by performance-conscious users. Would you mind opening a PR?
The README state than an easy way to use the vtprotobuf generated code is to change the default grpc codec to use
github.com/planetscale/vtprotobuf/codec/grpc.Codec
However the unmarshal operation of this custom codec has different semantics than the default one: it performs a merge rather than an override.
This is documented in the
UnmarshalVT
doc but it's easy to miss.This can be an issue when using grpc streams, because some valid code with the default codec will change behavior:
I'd suggest that the codec is this repo calls
msg.ResetVT()
beforeUnmarhsalVT
to keep the semantics of the default codec.Advanced user can still pass their own codec that does not call
ResetVT
if they require it.The text was updated successfully, but these errors were encountered: