-
Notifications
You must be signed in to change notification settings - Fork 808
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
Allow marshaler to omit nullable optional values #142
Comments
I suspect your patch will break some use cases. |
Oh, sorry, missed that proto3 feature. This is actually perfect, thanks! |
So I think there is still a bug here, let me demonstrate a use case. Here's the minimal proto:
When I run func (m *Test) MarshalTo(data []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.Data != nil {
data[i] = 0xa
i++
i = encodeVarintTest(data, i, uint64(len(*m.Data)))
i += copy(data[i:], *m.Data)
}
if m.XXX_unrecognized != nil {
i += copy(data[i:], m.XXX_unrecognized)
}
return i, nil
} When I repeat the same process but with func (m *Test) MarshalTo(data []byte) (int, error) {
var i int
_ = i
var l int
_ = l
data[i] = 0xa
i++
i = encodeVarintTest(data, i, uint64(len(m.Data)))
i += copy(data[i:], m.Data)
return i, nil
} In my opinion the output should be the same, no matter if I chose standard of faster mode. In this particular case, I also cannot just switch to proto3 as this is a third-party protocol. Ideas? |
gogofast_out / gofast_out has no side effects. gogofaster_out makes most fields nullable=false. In the docs of gogoprotobuf
|
Assuming I have a simple struct:
Which then results in:
As you can see, all attributes are optional and non-nullable. If I then marshal the struct, I get something like:
This is obviously quite a waste and not in line with how Go works. I understand that protobuf generated by Go messages must be interoperable but it would be nice to have the option to omit zero values. I have applied a manual patch below for now, but is this a feature you would generally consider?
Here's the output with the patch:
Here's the patched code:
The text was updated successfully, but these errors were encountered: