Skip to content
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

internal/proto: Fix encoding of zero embedded messages #672

Closed
wants to merge 2 commits into from

Conversation

cthulhu-rider
Copy link
Contributor

While an unspecified (nil) embedded field of `message` protobuf type is
encoded as nothing, the zero is still reflected in the message as an
encoded field number plus zero.

This fixes the test and makes correct assertion of zero message encoding.
The tests fails meaning there is a bug for now. The test is also made
independent with the nil one to make the not fail each other.

Signed-off-by: Leonard Lyubich <[email protected]>
Fixes the problem detected in d44ef3b
via `reflect` package as well as `neofs-api-go` module does.

Another way would be to check each field in the implementation of
`MarshalStable([]byte)` interface, but this would add a significant
amount of code. Benchmark showed almost no performance loss:
```
goos: linux
goarch: amd64
pkg: github.com/nspcc-dev/neofs-sdk-go/internal/proto
cpu: Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
                  │   old.txt    │            new.txt            │
                  │    sec/op    │   sec/op     vs base          │
MarshalEmbedded-8   26.00n ± 31%   27.59n ± 2%  ~ (p=0.393 n=10)

                  │  old.txt   │            new.txt             │
                  │    B/op    │    B/op     vs base            │
MarshalEmbedded-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

                  │  old.txt   │            new.txt             │
                  │ allocs/op  │ allocs/op   vs base            │
MarshalEmbedded-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal
```

Signed-off-by: Leonard Lyubich <[email protected]>
@cthulhu-rider cthulhu-rider added the bug Something isn't working label Dec 17, 2024
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.93%. Comparing base (591dd25) to head (6cbf49a).
Report is 28 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #672      +/-   ##
==========================================
+ Coverage   58.77%   60.93%   +2.15%     
==========================================
  Files         165      165              
  Lines       22751    22810      +59     
==========================================
+ Hits        13372    13899     +527     
+ Misses       8940     8544     -396     
+ Partials      439      367      -72     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cthulhu-rider cthulhu-rider marked this pull request as draft December 17, 2024 11:44
@cthulhu-rider cthulhu-rider marked this pull request as ready for review December 17, 2024 13:56
@cthulhu-rider
Copy link
Contributor Author

decided to checrry-pick into #667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant