Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/proto: Fix encoding of zero embedded messages
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]>
- Loading branch information