protogen: Do not panic in StableSize() #51
2 changed files with 20 additions and 0 deletions
|
@ -65,6 +65,10 @@ func (f *Filter) StableMarshal(buf []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filter) StableSize() (size int) {
|
func (f *Filter) StableSize() (size int) {
|
||||||
|
if f == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
size += protoutil.StringSize(nameFilterField, f.name)
|
size += protoutil.StringSize(nameFilterField, f.name)
|
||||||
size += protoutil.StringSize(keyFilterField, f.key)
|
size += protoutil.StringSize(keyFilterField, f.key)
|
||||||
size += protoutil.EnumSize(opFilterField, int32(f.op))
|
size += protoutil.EnumSize(opFilterField, int32(f.op))
|
||||||
|
@ -101,6 +105,10 @@ func (s *Selector) StableMarshal(buf []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Selector) StableSize() (size int) {
|
func (s *Selector) StableSize() (size int) {
|
||||||
|
if s == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
size += protoutil.StringSize(nameSelectorField, s.name)
|
size += protoutil.StringSize(nameSelectorField, s.name)
|
||||||
size += protoutil.UInt32Size(countSelectorField, s.count)
|
size += protoutil.UInt32Size(countSelectorField, s.count)
|
||||||
size += protoutil.EnumSize(countSelectorField, int32(s.clause))
|
size += protoutil.EnumSize(countSelectorField, int32(s.clause))
|
||||||
|
@ -132,6 +140,10 @@ func (r *Replica) StableMarshal(buf []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Replica) StableSize() (size int) {
|
func (r *Replica) StableSize() (size int) {
|
||||||
|
if r == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
size += protoutil.UInt32Size(countReplicaField, r.count)
|
size += protoutil.UInt32Size(countReplicaField, r.count)
|
||||||
size += protoutil.StringSize(selectorReplicaField, r.selector)
|
size += protoutil.StringSize(selectorReplicaField, r.selector)
|
||||||
|
|
||||||
|
@ -173,6 +185,10 @@ func (p *PlacementPolicy) StableMarshal(buf []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PlacementPolicy) StableSize() (size int) {
|
func (p *PlacementPolicy) StableSize() (size int) {
|
||||||
|
if p == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
for i := range p.replicas {
|
for i := range p.replicas {
|
||||||
size += protoutil.NestedStructureSize(replicasPolicyField, &p.replicas[i])
|
size += protoutil.NestedStructureSize(replicasPolicyField, &p.replicas[i])
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,10 @@ func (x *Detail) StableMarshal(buf []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Detail) StableSize() (size int) {
|
func (x *Detail) StableSize() (size int) {
|
||||||
|
if x == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
size += protoutil.UInt32Size(detailIDFNum, x.id)
|
size += protoutil.UInt32Size(detailIDFNum, x.id)
|
||||||
size += protoutil.BytesSize(detailValueFNum, x.val)
|
size += protoutil.BytesSize(detailValueFNum, x.val)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue