[#51] *: Do not panic in StableSize()
All checks were successful
Tests and linters / Lint (pull_request) Successful in 2m0s
Tests and linters / Tests (1.19) (pull_request) Successful in 3m27s
Tests and linters / Tests with -race (pull_request) Successful in 1m44s
Tests and linters / Tests (1.20) (pull_request) Successful in 3m29s

After #49 it can be called on nil structures.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-08-02 10:55:05 +03:00
parent 3072090c77
commit 964c3edb3f
2 changed files with 20 additions and 0 deletions

View file

@ -65,6 +65,10 @@ func (f *Filter) StableMarshal(buf []byte) []byte {
}
func (f *Filter) StableSize() (size int) {
if f == nil {
return 0
}
size += protoutil.StringSize(nameFilterField, f.name)
size += protoutil.StringSize(keyFilterField, f.key)
size += protoutil.EnumSize(opFilterField, int32(f.op))
@ -101,6 +105,10 @@ func (s *Selector) StableMarshal(buf []byte) []byte {
}
func (s *Selector) StableSize() (size int) {
if s == nil {
return 0
}
size += protoutil.StringSize(nameSelectorField, s.name)
size += protoutil.UInt32Size(countSelectorField, s.count)
size += protoutil.EnumSize(countSelectorField, int32(s.clause))
@ -132,6 +140,10 @@ func (r *Replica) StableMarshal(buf []byte) []byte {
}
func (r *Replica) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.UInt32Size(countReplicaField, r.count)
size += protoutil.StringSize(selectorReplicaField, r.selector)
@ -173,6 +185,10 @@ func (p *PlacementPolicy) StableMarshal(buf []byte) []byte {
}
func (p *PlacementPolicy) StableSize() (size int) {
if p == nil {
return 0
}
for i := range p.replicas {
size += protoutil.NestedStructureSize(replicasPolicyField, &p.replicas[i])
}

View file

@ -30,6 +30,10 @@ func (x *Detail) StableMarshal(buf []byte) []byte {
}
func (x *Detail) StableSize() (size int) {
if x == nil {
return 0
}
size += protoutil.UInt32Size(detailIDFNum, x.id)
size += protoutil.BytesSize(detailValueFNum, x.val)