util/proto: do not return error from primitive marshalers

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-12 15:20:19 +03:00 committed by LeL
parent 732dd51b1b
commit 84d981e88e
14 changed files with 202 additions and 932 deletions

View file

@ -24,22 +24,10 @@ func (d *Decimal) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, d.StableSize()) buf = make([]byte, d.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val) offset += protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val)
if err != nil { protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec)
return nil, err
}
offset += n
_, err = protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }

View file

@ -114,19 +114,8 @@ func (r *Record) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = protoutil.EnumMarshal(recordOperationField, buf[offset:], int32(r.op)) offset += protoutil.EnumMarshal(recordOperationField, buf[offset:], int32(r.op))
if err != nil { offset += protoutil.EnumMarshal(recordActionField, buf[offset:], int32(r.action))
return nil, err
}
offset += n
n, err = protoutil.EnumMarshal(recordActionField, buf[offset:], int32(r.action))
if err != nil {
return nil, err
}
offset += n
for i := range r.filters { for i := range r.filters {
n, err = protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i]) n, err = protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i])
@ -184,36 +173,12 @@ func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, f.StableSize()) buf = make([]byte, f.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.EnumMarshal(filterHeaderTypeField, buf[offset:], int32(f.hdrType)) offset += protoutil.EnumMarshal(filterHeaderTypeField, buf[offset:], int32(f.hdrType))
if err != nil { offset += protoutil.EnumMarshal(filterMatchTypeField, buf[offset:], int32(f.matchType))
return nil, err offset += protoutil.StringMarshal(filterNameField, buf[offset:], f.key)
} protoutil.StringMarshal(filterValueField, buf[offset:], f.value)
offset += n
n, err = protoutil.EnumMarshal(filterMatchTypeField, buf[offset:], int32(f.matchType))
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.StringMarshal(filterNameField, buf[offset:], f.key)
if err != nil {
return nil, err
}
offset += n
_, err = protoutil.StringMarshal(filterValueField, buf[offset:], f.value)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -247,22 +212,10 @@ func (t *Target) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, t.StableSize()) buf = make([]byte, t.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.EnumMarshal(targetTypeField, buf[offset:], int32(t.role)) offset += protoutil.EnumMarshal(targetTypeField, buf[offset:], int32(t.role))
if err != nil { protoutil.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys)
return nil, err
}
offset += n
_, err = protoutil.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -292,29 +245,11 @@ func (l *TokenLifetime) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, l.StableSize()) buf = make([]byte, l.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp) offset += protoutil.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp)
if err != nil { offset += protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
return nil, err protoutil.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
}
offset += n
n, err = protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
if err != nil {
return nil, err
}
offset += n
_, err = protoutil.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }

View file

@ -48,12 +48,7 @@ func (a *DataAuditResult) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch) offset += proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid) n, err = proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid)
if err != nil { if err != nil {
@ -62,33 +57,10 @@ func (a *DataAuditResult) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey) offset += proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey)
if err != nil { offset += proto.BoolMarshal(completeFNum, buf[offset:], a.complete)
return nil, err offset += proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests)
} offset += proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries)
offset += n
n, err = proto.BoolMarshal(completeFNum, buf[offset:], a.complete)
if err != nil {
return nil, err
}
offset += n
n, err = proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests)
if err != nil {
return nil, err
}
offset += n
n, err = proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries)
if err != nil {
return nil, err
}
offset += n
n, err = refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG) n, err = refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG)
if err != nil { if err != nil {
@ -104,38 +76,11 @@ func (a *DataAuditResult) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.UInt32Marshal(hitFNum, buf[offset:], a.hit) offset += proto.UInt32Marshal(hitFNum, buf[offset:], a.hit)
if err != nil { offset += proto.UInt32Marshal(missFNum, buf[offset:], a.miss)
return nil, err offset += proto.UInt32Marshal(failFNum, buf[offset:], a.fail)
} offset += proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes)
proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes)
offset += n
n, err = proto.UInt32Marshal(missFNum, buf[offset:], a.miss)
if err != nil {
return nil, err
}
offset += n
n, err = proto.UInt32Marshal(failFNum, buf[offset:], a.fail)
if err != nil {
return nil, err
}
offset += n
n, err = proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes)
if err != nil {
return nil, err
}
offset += n
_, err = proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }

View file

@ -60,22 +60,10 @@ func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, a.StableSize()) buf = make([]byte, a.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key) offset += protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key)
if err != nil { protoutil.StringMarshal(attributeValueField, buf[offset:], a.val)
return nil, err
}
offset += n
_, err = protoutil.StringMarshal(attributeValueField, buf[offset:], a.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -123,19 +111,8 @@ func (c *Container) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce) offset += protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce)
if err != nil { offset += protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL)
return nil, err
}
offset += n
n, err = protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL)
if err != nil {
return nil, err
}
offset += n
for i := range c.attr { for i := range c.attr {
n, err = protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i]) n, err = protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i])
@ -612,12 +589,7 @@ func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch) offset += protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch)
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid) n, err = protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid)
if err != nil { if err != nil {
@ -626,10 +598,7 @@ func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf[offset:], a.usedSpace) protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf[offset:], a.usedSpace)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }

View file

@ -55,33 +55,10 @@ func (f *Filter) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = protoutil.StringMarshal(nameFilterField, buf[offset:], f.name) offset += protoutil.StringMarshal(nameFilterField, buf[offset:], f.name)
if err != nil { offset += protoutil.StringMarshal(keyFilterField, buf[offset:], f.key)
return nil, err offset += protoutil.EnumMarshal(opFilterField, buf[offset:], int32(f.op))
} offset += protoutil.StringMarshal(valueFilterField, buf[offset:], f.value)
offset += n
n, err = protoutil.StringMarshal(keyFilterField, buf[offset:], f.key)
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.EnumMarshal(opFilterField, buf[offset:], int32(f.op))
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.StringMarshal(valueFilterField, buf[offset:], f.value)
if err != nil {
return nil, err
}
offset += n
for i := range f.filters { for i := range f.filters {
n, err = protoutil.NestedStructureMarshal(filtersFilterField, buf[offset:], &f.filters[i]) n, err = protoutil.NestedStructureMarshal(filtersFilterField, buf[offset:], &f.filters[i])
@ -120,43 +97,13 @@ func (s *Selector) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, s.StableSize()) buf = make([]byte, s.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.StringMarshal(nameSelectorField, buf[offset:], s.name) offset += protoutil.StringMarshal(nameSelectorField, buf[offset:], s.name)
if err != nil { offset += protoutil.UInt32Marshal(countSelectorField, buf[offset:], s.count)
return nil, err offset += protoutil.EnumMarshal(clauseSelectorField, buf[offset:], int32(s.clause))
} offset += protoutil.StringMarshal(attributeSelectorField, buf[offset:], s.attribute)
protoutil.StringMarshal(filterSelectorField, buf[offset:], s.filter)
offset += n
n, err = protoutil.UInt32Marshal(countSelectorField, buf[offset:], s.count)
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.EnumMarshal(clauseSelectorField, buf[offset:], int32(s.clause))
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.StringMarshal(attributeSelectorField, buf[offset:], s.attribute)
if err != nil {
return nil, err
}
offset += n
_, err = protoutil.StringMarshal(filterSelectorField, buf[offset:], s.filter)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -184,22 +131,10 @@ func (r *Replica) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count) offset += protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count)
if err != nil { protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector)
return nil, err
}
offset += n
_, err = protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -238,12 +173,7 @@ func (p *PlacementPolicy) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
} }
n, err = protoutil.UInt32Marshal(backupPolicyField, buf[offset:], p.backupFactor) offset += protoutil.UInt32Marshal(backupPolicyField, buf[offset:], p.backupFactor)
if err != nil {
return nil, err
}
offset += n
for i := range p.selectors { for i := range p.selectors {
n, err = protoutil.NestedStructureMarshal(selectorsPolicyField, buf[offset:], &p.selectors[i]) n, err = protoutil.NestedStructureMarshal(selectorsPolicyField, buf[offset:], &p.selectors[i])
@ -304,32 +234,13 @@ func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, a.StableSize()) buf = make([]byte, a.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.StringMarshal(keyAttributeField, buf[offset:], a.key) offset += protoutil.StringMarshal(keyAttributeField, buf[offset:], a.key)
if err != nil { offset += protoutil.StringMarshal(valueAttributeField, buf[offset:], a.value)
return nil, err
}
offset += n
n, err = protoutil.StringMarshal(valueAttributeField, buf[offset:], a.value)
if err != nil {
return nil, err
}
offset += n
for i := range a.parents { for i := range a.parents {
n, err = protoutil.StringMarshal(parentsAttributeField, buf[offset:], a.parents[i]) offset += protoutil.StringMarshal(parentsAttributeField, buf[offset:], a.parents[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf, nil
@ -368,19 +279,8 @@ func (ni *NodeInfo) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = protoutil.BytesMarshal(keyNodeInfoField, buf[offset:], ni.publicKey) offset += protoutil.BytesMarshal(keyNodeInfoField, buf[offset:], ni.publicKey)
if err != nil { offset += protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses)
return nil, err
}
offset += n
n, err = protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses)
if err != nil {
return nil, err
}
offset += n
for i := range ni.attributes { for i := range ni.attributes {
n, err = protoutil.NestedStructureMarshal(attributesNodeInfoField, buf[offset:], &ni.attributes[i]) n, err = protoutil.NestedStructureMarshal(attributesNodeInfoField, buf[offset:], &ni.attributes[i])
@ -391,10 +291,7 @@ func (ni *NodeInfo) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
} }
_, err = protoutil.EnumMarshal(stateNodeInfoField, buf[offset:], int32(ni.state)) protoutil.EnumMarshal(stateNodeInfoField, buf[offset:], int32(ni.state))
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -491,22 +388,10 @@ func (x *NetworkParameter) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k) offset += protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k)
if err != nil { protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v)
return nil, err
}
offset += n
_, err = protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -583,30 +468,13 @@ func (i *NetworkInfo) StableMarshal(buf []byte) ([]byte, error) {
} }
var ( var (
offset, n int offset int
err error err error
) )
n, err = protoutil.UInt64Marshal(netInfoCurEpochFNum, buf[offset:], i.curEpoch) offset += protoutil.UInt64Marshal(netInfoCurEpochFNum, buf[offset:], i.curEpoch)
if err != nil { offset += protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum)
return nil, err offset += protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock)
}
offset += n
n, err = protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum)
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock)
if err != nil {
return nil, err
}
offset += n
_, err = protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg) _, err = protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg)
if err != nil { if err != nil {

View file

@ -133,12 +133,7 @@ func (h *ShortHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.UInt64Marshal(shortHdrEpochField, buf[offset:], h.creatEpoch) offset += proto.UInt64Marshal(shortHdrEpochField, buf[offset:], h.creatEpoch)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(shortHdrOwnerField, buf[offset:], h.ownerID) n, err = proto.NestedStructureMarshal(shortHdrOwnerField, buf[offset:], h.ownerID)
if err != nil { if err != nil {
@ -147,19 +142,8 @@ func (h *ShortHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.EnumMarshal(shortHdrObjectTypeField, buf[offset:], int32(h.typ)) offset += proto.EnumMarshal(shortHdrObjectTypeField, buf[offset:], int32(h.typ))
if err != nil { offset += proto.UInt64Marshal(shortHdrPayloadLength, buf[offset:], h.payloadLen)
return nil, err
}
offset += n
n, err = proto.UInt64Marshal(shortHdrPayloadLength, buf[offset:], h.payloadLen)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(shortHdrHashField, buf[offset:], h.payloadHash) n, err = proto.NestedStructureMarshal(shortHdrHashField, buf[offset:], h.payloadHash)
if err != nil { if err != nil {
@ -205,22 +189,10 @@ func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, a.StableSize()) buf = make([]byte, a.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.StringMarshal(attributeKeyField, buf[offset:], a.key) offset += proto.StringMarshal(attributeKeyField, buf[offset:], a.key)
if err != nil { proto.StringMarshal(attributeValueField, buf[offset:], a.val)
return nil, err
}
offset += n
_, err = proto.StringMarshal(attributeValueField, buf[offset:], a.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -289,10 +261,7 @@ func (h *SplitHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID) proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -351,19 +320,8 @@ func (h *Header) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.UInt64Marshal(hdrEpochField, buf[offset:], h.creatEpoch) offset += proto.UInt64Marshal(hdrEpochField, buf[offset:], h.creatEpoch)
if err != nil { offset += proto.UInt64Marshal(hdrPayloadLengthField, buf[offset:], h.payloadLen)
return nil, err
}
offset += n
n, err = proto.UInt64Marshal(hdrPayloadLengthField, buf[offset:], h.payloadLen)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(hdrPayloadHashField, buf[offset:], h.payloadHash) n, err = proto.NestedStructureMarshal(hdrPayloadHashField, buf[offset:], h.payloadHash)
if err != nil { if err != nil {
@ -372,12 +330,7 @@ func (h *Header) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.EnumMarshal(hdrObjectTypeField, buf[offset:], int32(h.typ)) offset += proto.EnumMarshal(hdrObjectTypeField, buf[offset:], int32(h.typ))
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(hdrHomomorphicHashField, buf[offset:], h.homoHash) n, err = proto.NestedStructureMarshal(hdrHomomorphicHashField, buf[offset:], h.homoHash)
if err != nil { if err != nil {
@ -515,10 +468,7 @@ func (o *Object) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = proto.BytesMarshal(objPayloadField, buf[offset:], o.payload) proto.BytesMarshal(objPayloadField, buf[offset:], o.payload)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -554,12 +504,7 @@ func (s *SplitInfo) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = proto.BytesMarshal(splitInfoSplitIDField, buf[offset:], s.splitID) offset += proto.BytesMarshal(splitInfoSplitIDField, buf[offset:], s.splitID)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(splitInfoLastPartField, buf[offset:], s.lastPart) n, err = proto.NestedStructureMarshal(splitInfoLastPartField, buf[offset:], s.lastPart)
if err != nil { if err != nil {
@ -613,10 +558,7 @@ func (r *GetRequestBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = proto.BoolMarshal(getReqBodyRawFlagField, buf[offset:], r.raw) proto.BoolMarshal(getReqBodyRawFlagField, buf[offset:], r.raw)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -706,10 +648,7 @@ func (r *GetResponseBody) StableMarshal(buf []byte) ([]byte, error) {
} }
case *GetObjectPartChunk: case *GetObjectPartChunk:
if v != nil { if v != nil {
_, err := proto.BytesMarshal(getRespBodyChunkField, buf, v.chunk) proto.BytesMarshal(getRespBodyChunkField, buf, v.chunk)
if err != nil {
return nil, err
}
} }
case *SplitInfo: case *SplitInfo:
_, err := proto.NestedStructureMarshal(getRespBodySplitInfoField, buf, v) _, err := proto.NestedStructureMarshal(getRespBodySplitInfoField, buf, v)
@ -784,10 +723,7 @@ func (r *PutObjectPartInit) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = proto.UInt32Marshal(putReqInitCopiesNumField, buf[offset:], r.copyNum) proto.UInt32Marshal(putReqInitCopiesNumField, buf[offset:], r.copyNum)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -827,10 +763,7 @@ func (r *PutRequestBody) StableMarshal(buf []byte) ([]byte, error) {
} }
case *PutObjectPartChunk: case *PutObjectPartChunk:
if v != nil { if v != nil {
_, err := proto.BytesMarshal(putReqBodyChunkField, buf, v.chunk) proto.BytesMarshal(putReqBodyChunkField, buf, v.chunk)
if err != nil {
return nil, err
}
} }
default: default:
panic("unknown one of object put request body type") panic("unknown one of object put request body type")
@ -977,17 +910,8 @@ func (r *HeadRequestBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.BoolMarshal(headReqBodyMainFlagField, buf[offset:], r.mainOnly) offset += proto.BoolMarshal(headReqBodyMainFlagField, buf[offset:], r.mainOnly)
if err != nil { proto.BoolMarshal(headReqBodyRawFlagField, buf[offset:], r.raw)
return nil, err
}
offset += n
_, err = proto.BoolMarshal(headReqBodyRawFlagField, buf[offset:], r.raw)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -1086,29 +1010,11 @@ func (f *SearchFilter) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, f.StableSize()) buf = make([]byte, f.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.EnumMarshal(searchFilterMatchField, buf[offset:], int32(f.matchType)) offset += proto.EnumMarshal(searchFilterMatchField, buf[offset:], int32(f.matchType))
if err != nil { offset += proto.StringMarshal(searchFilterNameField, buf[offset:], f.key)
return nil, err proto.StringMarshal(searchFilterValueField, buf[offset:], f.val)
}
offset += n
n, err = proto.StringMarshal(searchFilterNameField, buf[offset:], f.key)
if err != nil {
return nil, err
}
offset += n
_, err = proto.StringMarshal(searchFilterValueField, buf[offset:], f.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -1150,12 +1056,7 @@ func (r *SearchRequestBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.UInt32Marshal(searchReqBodyVersionField, buf[offset:], r.version) offset += proto.UInt32Marshal(searchReqBodyVersionField, buf[offset:], r.version)
if err != nil {
return nil, err
}
offset += n
for i := range r.filters { for i := range r.filters {
n, err = proto.NestedStructureMarshal(searchReqBodyFiltersField, buf[offset:], &r.filters[i]) n, err = proto.NestedStructureMarshal(searchReqBodyFiltersField, buf[offset:], &r.filters[i])
@ -1233,22 +1134,10 @@ func (r *Range) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.UInt64Marshal(rangeOffsetField, buf[offset:], r.off) offset += proto.UInt64Marshal(rangeOffsetField, buf[offset:], r.off)
if err != nil { proto.UInt64Marshal(rangeLengthField, buf[offset:], r.len)
return nil, err
}
offset += n
_, err = proto.UInt64Marshal(rangeLengthField, buf[offset:], r.len)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -1296,10 +1185,7 @@ func (r *GetRangeRequestBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = proto.BoolMarshal(getRangeReqBodyRawField, buf[offset:], r.raw) proto.BoolMarshal(getRangeReqBodyRawField, buf[offset:], r.raw)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -1333,10 +1219,7 @@ func (r *GetRangeResponseBody) StableMarshal(buf []byte) ([]byte, error) {
case nil: case nil:
case *GetRangePartChunk: case *GetRangePartChunk:
if v != nil { if v != nil {
_, err := proto.BytesMarshal(getRangeRespChunkField, buf, v.chunk) proto.BytesMarshal(getRangeRespChunkField, buf, v.chunk)
if err != nil {
return nil, err
}
} }
case *SplitInfo: case *SplitInfo:
if v != nil { if v != nil {
@ -1408,17 +1291,8 @@ func (r *GetRangeHashRequestBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
} }
n, err = proto.BytesMarshal(getRangeHashReqBodySaltField, buf[offset:], r.salt) offset += proto.BytesMarshal(getRangeHashReqBodySaltField, buf[offset:], r.salt)
if err != nil { proto.EnumMarshal(getRangeHashReqBodyTypeField, buf[offset:], int32(r.typ))
return nil, err
}
offset += n
_, err = proto.EnumMarshal(getRangeHashReqBodyTypeField, buf[offset:], int32(r.typ))
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -1453,22 +1327,10 @@ func (r *GetRangeHashResponseBody) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.EnumMarshal(getRangeHashRespBodyTypeField, buf, int32(r.typ)) offset += proto.EnumMarshal(getRangeHashRespBodyTypeField, buf, int32(r.typ))
if err != nil { proto.RepeatedBytesMarshal(getRangeHashRespBodyHashListField, buf[offset:], r.hashList)
return nil, err
}
offset += n
_, err = proto.RepeatedBytesMarshal(getRangeHashRespBodyHashListField, buf[offset:], r.hashList)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }

View file

@ -36,10 +36,7 @@ func (o *OwnerID) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, o.StableSize()) buf = make([]byte, o.StableSize())
} }
_, err := proto.BytesMarshal(ownerIDValField, buf, o.val) proto.BytesMarshal(ownerIDValField, buf, o.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -65,10 +62,7 @@ func (c *ContainerID) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, c.StableSize()) buf = make([]byte, c.StableSize())
} }
_, err := proto.BytesMarshal(containerIDValField, buf, c.val) proto.BytesMarshal(containerIDValField, buf, c.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -94,10 +88,7 @@ func (o *ObjectID) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, o.StableSize()) buf = make([]byte, o.StableSize())
} }
_, err := proto.BytesMarshal(objectIDValField, buf, o.val) proto.BytesMarshal(objectIDValField, buf, o.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -195,22 +186,10 @@ func (c *Checksum) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, c.StableSize()) buf = make([]byte, c.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ)) offset += proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ))
if err != nil { proto.BytesMarshal(checksumValueField, buf[offset:], c.sum)
return nil, err
}
offset += n
_, err = proto.BytesMarshal(checksumValueField, buf[offset:], c.sum)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -239,29 +218,11 @@ func (s *Signature) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, s.StableSize()) buf = make([]byte, s.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.BytesMarshal(signatureKeyField, buf[offset:], s.key) offset += proto.BytesMarshal(signatureKeyField, buf[offset:], s.key)
if err != nil { offset += proto.BytesMarshal(signatureValueField, buf[offset:], s.sign)
return nil, err proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme))
}
offset += n
n, err = proto.BytesMarshal(signatureValueField, buf[offset:], s.sign)
if err != nil {
return nil, err
}
offset += n
_, err = proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme))
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -291,22 +252,10 @@ func (v *Version) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, v.StableSize()) buf = make([]byte, v.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.UInt32Marshal(versionMajorField, buf[offset:], v.major) offset += proto.UInt32Marshal(versionMajorField, buf[offset:], v.major)
if err != nil { proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor)
return nil, err
}
offset += n
_, err = proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }

View file

@ -20,10 +20,7 @@ func (x *PeerID) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
_, err := protoutil.BytesMarshal(peerIDPubKeyFNum, buf, x.publicKey) protoutil.BytesMarshal(peerIDPubKeyFNum, buf, x.publicKey)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -65,10 +62,7 @@ func (x *Trust) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = protoutil.Float64Marshal(trustValueFNum, buf[offset:], x.val) protoutil.Float64Marshal(trustValueFNum, buf[offset:], x.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -230,12 +224,7 @@ func (x *AnnounceLocalTrustRequestBody) StableMarshal(buf []byte) ([]byte, error
err error err error
) )
n, err = protoutil.UInt64Marshal(announceLocalTrustBodyEpochFNum, buf[offset:], x.epoch) offset += protoutil.UInt64Marshal(announceLocalTrustBodyEpochFNum, buf[offset:], x.epoch)
if err != nil {
return nil, err
}
offset += n
for i := range x.trusts { for i := range x.trusts {
n, err = protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], &x.trusts[i]) n, err = protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], &x.trusts[i])
@ -292,23 +281,12 @@ func (x *AnnounceIntermediateResultRequestBody) StableMarshal(buf []byte) ([]byt
} }
var ( var (
offset, n int offset int
err error err error
) )
n, err = protoutil.UInt64Marshal(announceInterResBodyEpochFNum, buf, x.epoch) offset += protoutil.UInt64Marshal(announceInterResBodyEpochFNum, buf, x.epoch)
if err != nil { offset += protoutil.UInt32Marshal(announceInterResBodyIterFNum, buf[offset:], x.iter)
return nil, err
}
offset += n
n, err = protoutil.UInt32Marshal(announceInterResBodyIterFNum, buf[offset:], x.iter)
if err != nil {
return nil, err
}
offset += n
_, err = protoutil.NestedStructureMarshal(announceInterResBodyTrustFNum, buf[offset:], x.trust) _, err = protoutil.NestedStructureMarshal(announceInterResBodyTrustFNum, buf[offset:], x.trust)
if err != nil { if err != nil {

View file

@ -82,10 +82,7 @@ func (c *CreateRequestBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = proto.UInt64Marshal(createReqBodyExpirationField, buf[offset:], c.expiration) proto.UInt64Marshal(createReqBodyExpirationField, buf[offset:], c.expiration)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -114,22 +111,10 @@ func (c *CreateResponseBody) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, c.StableSize()) buf = make([]byte, c.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.BytesMarshal(createRespBodyIDField, buf[offset:], c.id) offset += proto.BytesMarshal(createRespBodyIDField, buf[offset:], c.id)
if err != nil { proto.BytesMarshal(createRespBodyKeyField, buf[offset:], c.sessionKey)
return nil, err
}
offset += n
_, err = proto.BytesMarshal(createRespBodyKeyField, buf[offset:], c.sessionKey)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -158,22 +143,10 @@ func (x *XHeader) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.StringMarshal(xheaderKeyField, buf[offset:], x.key) offset += proto.StringMarshal(xheaderKeyField, buf[offset:], x.key)
if err != nil { proto.StringMarshal(xheaderValueField, buf[offset:], x.val)
return nil, err
}
offset += n
_, err = proto.StringMarshal(xheaderValueField, buf[offset:], x.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -207,29 +180,11 @@ func (l *TokenLifetime) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, l.StableSize()) buf = make([]byte, l.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp) offset += proto.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp)
if err != nil { offset += proto.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
return nil, err proto.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
}
offset += n
n, err = proto.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
if err != nil {
return nil, err
}
offset += n
_, err = proto.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -264,22 +219,10 @@ func (c *ObjectSessionContext) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, c.StableSize()) buf = make([]byte, c.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.EnumMarshal(objectCtxVerbField, buf[offset:], int32(c.verb)) offset += proto.EnumMarshal(objectCtxVerbField, buf[offset:], int32(c.verb))
if err != nil { proto.NestedStructureMarshal(objectCtxAddressField, buf[offset:], c.addr)
return nil, err
}
offset += n
_, err = proto.NestedStructureMarshal(objectCtxAddressField, buf[offset:], c.addr)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -320,29 +263,11 @@ func (x *ContainerSessionContext) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.EnumMarshal(cnrCtxVerbFNum, buf[offset:], int32(ContainerSessionVerbToGRPCField(x.verb))) offset += proto.EnumMarshal(cnrCtxVerbFNum, buf[offset:], int32(ContainerSessionVerbToGRPCField(x.verb)))
if err != nil { offset += proto.BoolMarshal(cnrCtxWildcardFNum, buf[offset:], x.wildcard)
return nil, err proto.NestedStructureMarshal(cnrCtxCidFNum, buf[offset:], x.cid)
}
offset += n
n, err = proto.BoolMarshal(cnrCtxWildcardFNum, buf[offset:], x.wildcard)
if err != nil {
return nil, err
}
offset += n
_, err = proto.NestedStructureMarshal(cnrCtxCidFNum, buf[offset:], x.cid)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -377,12 +302,7 @@ func (t *TokenBody) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = proto.BytesMarshal(sessionTokenBodyIDField, buf[offset:], t.id) offset += proto.BytesMarshal(sessionTokenBodyIDField, buf[offset:], t.id)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf[offset:], t.ownerID) n, err = proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf[offset:], t.ownerID)
if err != nil { if err != nil {
@ -398,12 +318,7 @@ func (t *TokenBody) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.BytesMarshal(sessionTokenBodyKeyField, buf[offset:], t.sessionKey) offset += proto.BytesMarshal(sessionTokenBodyKeyField, buf[offset:], t.sessionKey)
if err != nil {
return nil, err
}
offset += n
if t.ctx != nil { if t.ctx != nil {
switch v := t.ctx.(type) { switch v := t.ctx.(type) {
@ -528,19 +443,8 @@ func (r *RequestMetaHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.UInt64Marshal(reqMetaHeaderEpochField, buf[offset:], r.epoch) offset += proto.UInt64Marshal(reqMetaHeaderEpochField, buf[offset:], r.epoch)
if err != nil { offset += proto.UInt32Marshal(reqMetaHeaderTTLField, buf[offset:], r.ttl)
return nil, err
}
offset += n
n, err = proto.UInt32Marshal(reqMetaHeaderTTLField, buf[offset:], r.ttl)
if err != nil {
return nil, err
}
offset += n
for i := range r.xHeaders { for i := range r.xHeaders {
n, err = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i]) n, err = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i])
@ -572,10 +476,7 @@ func (r *RequestMetaHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
_, err = proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf[offset:], r.netMagic) proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf[offset:], r.netMagic)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -699,19 +600,8 @@ func (r *ResponseMetaHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.UInt64Marshal(respMetaHeaderEpochField, buf[offset:], r.epoch) offset += proto.UInt64Marshal(respMetaHeaderEpochField, buf[offset:], r.epoch)
if err != nil { offset += proto.UInt32Marshal(respMetaHeaderTTLField, buf[offset:], r.ttl)
return nil, err
}
offset += n
n, err = proto.UInt32Marshal(respMetaHeaderTTLField, buf[offset:], r.ttl)
if err != nil {
return nil, err
}
offset += n
for i := range r.xHeaders { for i := range r.xHeaders {
n, err = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i]) n, err = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i])

View file

@ -21,22 +21,10 @@ func (x *Detail) StableMarshal(buf []byte) ([]byte, error) {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.UInt32Marshal(detailIDFNum, buf[offset:], x.id) offset += protoutil.UInt32Marshal(detailIDFNum, buf[offset:], x.id)
if err != nil { offset += protoutil.BytesMarshal(detailValueFNum, buf[offset:], x.val)
return nil, err
}
offset += n
_, err = protoutil.BytesMarshal(detailValueFNum, buf[offset:], x.val)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -73,20 +61,16 @@ func (x *Status) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = protoutil.UInt32Marshal(statusCodeFNum, buf[offset:], CodeToGRPC(x.code)) offset += protoutil.UInt32Marshal(statusCodeFNum, buf[offset:], CodeToGRPC(x.code))
if err != nil { if err != nil {
return nil, err return nil, err
} }
offset += n offset += protoutil.StringMarshal(statusMsgFNum, buf[offset:], x.msg)
n, err = protoutil.StringMarshal(statusMsgFNum, buf[offset:], x.msg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
offset += n
for i := range x.details { for i := range x.details {
n, err = protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i]) n, err = protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i])
if err != nil { if err != nil {

View file

@ -30,12 +30,7 @@ func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = proto.UInt64Marshal(sizeField, buf[offset:], s.size) offset += proto.UInt64Marshal(sizeField, buf[offset:], s.size)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(hashField, buf[offset:], s.hash) n, err = proto.NestedStructureMarshal(hashField, buf[offset:], s.hash)
if err != nil { if err != nil {
@ -44,12 +39,7 @@ func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.UInt64Marshal(expirationField, buf[offset:], s.exp) offset += proto.UInt64Marshal(expirationField, buf[offset:], s.exp)
if err != nil {
return nil, err
}
offset += n
_, err = refs.ObjectIDNestedListMarshal(objectIDsField, buf[offset:], s.members) _, err = refs.ObjectIDNestedListMarshal(objectIDsField, buf[offset:], s.members)
if err != nil { if err != nil {

View file

@ -28,19 +28,8 @@ func (s *Tombstone) StableMarshal(buf []byte) ([]byte, error) {
err error err error
) )
n, err = proto.UInt64Marshal(expFNum, buf[offset:], s.exp) offset += proto.UInt64Marshal(expFNum, buf[offset:], s.exp)
if err != nil { offset += proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID)
return nil, err
}
offset += n
n, err = proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID)
if err != nil {
return nil, err
}
offset += n
for i := range s.members { for i := range s.members {
n, err = proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i]) n, err = proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i])

View file

@ -20,9 +20,9 @@ type (
} }
) )
func BytesMarshal(field int, buf, v []byte) (int, error) { func BytesMarshal(field int, buf, v []byte) int {
if len(v) == 0 { if len(v) == 0 {
return 0, nil return 0
} }
prefix := field<<3 | 0x2 prefix := field<<3 | 0x2
@ -33,7 +33,7 @@ func BytesMarshal(field int, buf, v []byte) (int, error) {
i += binary.PutUvarint(buf[i:], uint64(len(v))) i += binary.PutUvarint(buf[i:], uint64(len(v)))
i += copy(buf[i:], v) i += copy(buf[i:], v)
return i, nil return i
} }
func BytesSize(field int, v []byte) int { func BytesSize(field int, v []byte) int {
@ -47,7 +47,7 @@ func BytesSize(field int, v []byte) int {
return VarUIntSize(uint64(prefix)) + VarUIntSize(uint64(ln)) + ln return VarUIntSize(uint64(prefix)) + VarUIntSize(uint64(ln)) + ln
} }
func StringMarshal(field int, buf []byte, v string) (int, error) { func StringMarshal(field int, buf []byte, v string) int {
return BytesMarshal(field, buf, []byte(v)) return BytesMarshal(field, buf, []byte(v))
} }
@ -55,9 +55,9 @@ func StringSize(field int, v string) int {
return BytesSize(field, []byte(v)) return BytesSize(field, []byte(v))
} }
func BoolMarshal(field int, buf []byte, v bool) (int, error) { func BoolMarshal(field int, buf []byte, v bool) int {
if !v { if !v {
return 0, nil return 0
} }
prefix := field << 3 prefix := field << 3
@ -67,7 +67,7 @@ func BoolMarshal(field int, buf []byte, v bool) (int, error) {
i := binary.PutUvarint(buf, uint64(prefix)) i := binary.PutUvarint(buf, uint64(prefix))
buf[i] = 0x1 buf[i] = 0x1
return i + 1, nil return i + 1
} }
func BoolSize(field int, v bool) int { func BoolSize(field int, v bool) int {
@ -80,9 +80,9 @@ func BoolSize(field int, v bool) int {
return VarUIntSize(uint64(prefix)) + 1 // bool is always 1 byte long return VarUIntSize(uint64(prefix)) + 1 // bool is always 1 byte long
} }
func UInt64Marshal(field int, buf []byte, v uint64) (int, error) { func UInt64Marshal(field int, buf []byte, v uint64) int {
if v == 0 { if v == 0 {
return 0, nil return 0
} }
prefix := field << 3 prefix := field << 3
@ -92,7 +92,7 @@ func UInt64Marshal(field int, buf []byte, v uint64) (int, error) {
i := binary.PutUvarint(buf, uint64(prefix)) i := binary.PutUvarint(buf, uint64(prefix))
i += binary.PutUvarint(buf[i:], v) i += binary.PutUvarint(buf[i:], v)
return i, nil return i
} }
func UInt64Size(field int, v uint64) int { func UInt64Size(field int, v uint64) int {
@ -105,7 +105,7 @@ func UInt64Size(field int, v uint64) int {
return VarUIntSize(uint64(prefix)) + VarUIntSize(v) return VarUIntSize(uint64(prefix)) + VarUIntSize(v)
} }
func Int64Marshal(field int, buf []byte, v int64) (int, error) { func Int64Marshal(field int, buf []byte, v int64) int {
return UInt64Marshal(field, buf, uint64(v)) return UInt64Marshal(field, buf, uint64(v))
} }
@ -113,7 +113,7 @@ func Int64Size(field int, v int64) int {
return UInt64Size(field, uint64(v)) return UInt64Size(field, uint64(v))
} }
func UInt32Marshal(field int, buf []byte, v uint32) (int, error) { func UInt32Marshal(field int, buf []byte, v uint32) int {
return UInt64Marshal(field, buf, uint64(v)) return UInt64Marshal(field, buf, uint64(v))
} }
@ -121,7 +121,7 @@ func UInt32Size(field int, v uint32) int {
return UInt64Size(field, uint64(v)) return UInt64Size(field, uint64(v))
} }
func Int32Marshal(field int, buf []byte, v int32) (int, error) { func Int32Marshal(field int, buf []byte, v int32) int {
return UInt64Marshal(field, buf, uint64(v)) return UInt64Marshal(field, buf, uint64(v))
} }
@ -129,7 +129,7 @@ func Int32Size(field int, v int32) int {
return UInt64Size(field, uint64(v)) return UInt64Size(field, uint64(v))
} }
func EnumMarshal(field int, buf []byte, v int32) (int, error) { func EnumMarshal(field int, buf []byte, v int32) int {
return UInt64Marshal(field, buf, uint64(v)) return UInt64Marshal(field, buf, uint64(v))
} }
@ -137,19 +137,14 @@ func EnumSize(field int, v int32) int {
return UInt64Size(field, uint64(v)) return UInt64Size(field, uint64(v))
} }
func RepeatedBytesMarshal(field int, buf []byte, v [][]byte) (int, error) { func RepeatedBytesMarshal(field int, buf []byte, v [][]byte) int {
var offset int var offset int
for i := range v { for i := range v {
off, err := BytesMarshal(field, buf[offset:], v[i]) offset += BytesMarshal(field, buf[offset:], v[i])
if err != nil {
return 0, err
}
offset += off
} }
return offset, nil return offset
} }
func RepeatedBytesSize(field int, v [][]byte) (size int) { func RepeatedBytesSize(field int, v [][]byte) (size int) {
@ -160,19 +155,14 @@ func RepeatedBytesSize(field int, v [][]byte) (size int) {
return size return size
} }
func RepeatedStringMarshal(field int, buf []byte, v []string) (int, error) { func RepeatedStringMarshal(field int, buf []byte, v []string) int {
var offset int var offset int
for i := range v { for i := range v {
off, err := StringMarshal(field, buf[offset:], v[i]) offset += StringMarshal(field, buf[offset:], v[i])
if err != nil {
return 0, err
}
offset += off
} }
return offset, nil return offset
} }
func RepeatedStringSize(field int, v []string) (size int) { func RepeatedStringSize(field int, v []string) (size int) {
@ -183,9 +173,9 @@ func RepeatedStringSize(field int, v []string) (size int) {
return size return size
} }
func RepeatedUInt64Marshal(field int, buf []byte, v []uint64) (int, error) { func RepeatedUInt64Marshal(field int, buf []byte, v []uint64) int {
if len(v) == 0 { if len(v) == 0 {
return 0, nil return 0
} }
prefix := field<<3 | 0x02 prefix := field<<3 | 0x02
@ -197,7 +187,7 @@ func RepeatedUInt64Marshal(field int, buf []byte, v []uint64) (int, error) {
offset += binary.PutUvarint(buf[offset:], v[i]) offset += binary.PutUvarint(buf[offset:], v[i])
} }
return offset, nil return offset
} }
func RepeatedUInt64Size(field int, v []uint64) (size, arraySize int) { func RepeatedUInt64Size(field int, v []uint64) (size, arraySize int) {
@ -218,9 +208,9 @@ func RepeatedUInt64Size(field int, v []uint64) (size, arraySize int) {
return size, arraySize return size, arraySize
} }
func RepeatedInt64Marshal(field int, buf []byte, v []int64) (int, error) { func RepeatedInt64Marshal(field int, buf []byte, v []int64) int {
if len(v) == 0 { if len(v) == 0 {
return 0, nil return 0
} }
convert := make([]uint64, len(v)) convert := make([]uint64, len(v))
@ -244,9 +234,9 @@ func RepeatedInt64Size(field int, v []int64) (size, arraySize int) {
return RepeatedUInt64Size(field, convert) return RepeatedUInt64Size(field, convert)
} }
func RepeatedUInt32Marshal(field int, buf []byte, v []uint32) (int, error) { func RepeatedUInt32Marshal(field int, buf []byte, v []uint32) int {
if len(v) == 0 { if len(v) == 0 {
return 0, nil return 0
} }
convert := make([]uint64, len(v)) convert := make([]uint64, len(v))
@ -270,9 +260,9 @@ func RepeatedUInt32Size(field int, v []uint32) (size, arraySize int) {
return RepeatedUInt64Size(field, convert) return RepeatedUInt64Size(field, convert)
} }
func RepeatedInt32Marshal(field int, buf []byte, v []int32) (int, error) { func RepeatedInt32Marshal(field int, buf []byte, v []int32) int {
if len(v) == 0 { if len(v) == 0 {
return 0, nil return 0
} }
convert := make([]uint64, len(v)) convert := make([]uint64, len(v))
@ -337,9 +327,9 @@ func NestedStructureSize(field int64, v stableMarshaller) (size int) {
return size return size
} }
func Fixed64Marshal(field int, buf []byte, v uint64) (int, error) { func Fixed64Marshal(field int, buf []byte, v uint64) int {
if v == 0 { if v == 0 {
return 0, nil return 0
} }
prefix := field<<3 | 1 prefix := field<<3 | 1
@ -349,7 +339,7 @@ func Fixed64Marshal(field int, buf []byte, v uint64) (int, error) {
i := binary.PutUvarint(buf, uint64(prefix)) i := binary.PutUvarint(buf, uint64(prefix))
binary.LittleEndian.PutUint64(buf[i:], v) binary.LittleEndian.PutUint64(buf[i:], v)
return i + 8, nil return i + 8
} }
func Fixed64Size(fNum int, v uint64) int { func Fixed64Size(fNum int, v uint64) int {
@ -362,9 +352,9 @@ func Fixed64Size(fNum int, v uint64) int {
return VarUIntSize(uint64(prefix)) + 8 return VarUIntSize(uint64(prefix)) + 8
} }
func Float64Marshal(field int, buf []byte, v float64) (int, error) { func Float64Marshal(field int, buf []byte, v float64) int {
if v == 0 { if v == 0 {
return 0, nil return 0
} }
prefix := field<<3 | 1 prefix := field<<3 | 1
@ -372,7 +362,7 @@ func Float64Marshal(field int, buf []byte, v float64) (int, error) {
i := binary.PutUvarint(buf, uint64(prefix)) i := binary.PutUvarint(buf, uint64(prefix))
binary.LittleEndian.PutUint64(buf[i:], math.Float64bits(v)) binary.LittleEndian.PutUint64(buf[i:], math.Float64bits(v))
return i + 8, nil return i + 8
} }
func Float64Size(fNum int, v float64) int { func Float64Size(fNum int, v float64) int {

View file

@ -1,7 +1,6 @@
package proto_test package proto_test
import ( import (
"fmt"
"math" "math"
"testing" "testing"
@ -59,91 +58,55 @@ func (s *stablePrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte, e
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err := proto.BytesMarshal(fieldNum, buf, s.FieldA) i += proto.BytesMarshal(fieldNum, buf, s.FieldA)
if err != nil {
return nil, fmt.Errorf("can't marshal field a: %w", err)
}
i += offset
fieldNum = 2 fieldNum = 2
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.StringMarshal(fieldNum, buf, s.FieldB) i += proto.StringMarshal(fieldNum, buf, s.FieldB)
if err != nil {
return nil, fmt.Errorf("can't marshal field b: %w", err)
}
i += offset
fieldNum = 200 fieldNum = 200
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.BoolMarshal(fieldNum, buf, s.FieldC) i += proto.BoolMarshal(fieldNum, buf, s.FieldC)
if err != nil {
return nil, fmt.Errorf("can't marshal field c: %w", err)
}
i += offset
fieldNum = 201 fieldNum = 201
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.Int32Marshal(fieldNum, buf, s.FieldD) i += proto.Int32Marshal(fieldNum, buf, s.FieldD)
if err != nil {
return nil, fmt.Errorf("can't marshal field d: %w", err)
}
i += offset
fieldNum = 202 fieldNum = 202
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.UInt32Marshal(fieldNum, buf, s.FieldE) i += proto.UInt32Marshal(fieldNum, buf, s.FieldE)
if err != nil {
return nil, fmt.Errorf("can't marshal field e: %w", err)
}
i += offset
fieldNum = 203 fieldNum = 203
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.Int64Marshal(fieldNum, buf, s.FieldF) i += proto.Int64Marshal(fieldNum, buf, s.FieldF)
if err != nil {
return nil, fmt.Errorf("can't marshal field f: %w", err)
}
i += offset
fieldNum = 204 fieldNum = 204
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.UInt64Marshal(fieldNum, buf, s.FieldG) i += proto.UInt64Marshal(fieldNum, buf, s.FieldG)
if err != nil {
return nil, fmt.Errorf("can't marshal field g: %w", err)
}
i += offset
fieldNum = 205 fieldNum = 205
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.Fixed64Marshal(fieldNum, buf, s.FieldI) i += proto.Fixed64Marshal(fieldNum, buf, s.FieldI)
if err != nil {
return nil, fmt.Errorf("can't marshal field I: %w", err)
}
i += offset
fieldNum = 206 fieldNum = 206
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.Float64Marshal(fieldNum, buf, s.FieldJ) i += proto.Float64Marshal(fieldNum, buf, s.FieldJ)
if err != nil {
return nil, fmt.Errorf("can't marshal field J: %w", err)
}
i += offset
fieldNum = 207 fieldNum = 207
if wrongField { if wrongField {
@ -158,11 +121,7 @@ func (s *stablePrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte, e
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.EnumMarshal(fieldNum, buf, int32(s.FieldH)) i += proto.EnumMarshal(fieldNum, buf, int32(s.FieldH))
if err != nil {
return nil, fmt.Errorf("can't marshal field h: %w", err)
}
i += offset
return buf, nil return buf, nil
} }
@ -190,69 +149,43 @@ func (s *stableRepPrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte
buf = make([]byte, s.stableSize()) buf = make([]byte, s.stableSize())
} }
var ( var i, fieldNum int
i, offset, fieldNum int
)
fieldNum = 1 fieldNum = 1
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err := proto.RepeatedBytesMarshal(fieldNum, buf, s.FieldA) i += proto.RepeatedBytesMarshal(fieldNum, buf, s.FieldA)
if err != nil {
return nil, fmt.Errorf("can't marshal field a: %w", err)
}
i += offset
fieldNum = 2 fieldNum = 2
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.RepeatedStringMarshal(fieldNum, buf, s.FieldB) i += proto.RepeatedStringMarshal(fieldNum, buf, s.FieldB)
if err != nil {
return nil, fmt.Errorf("can't marshal field b: %w", err)
}
i += offset
fieldNum = 3 fieldNum = 3
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.RepeatedInt32Marshal(fieldNum, buf, s.FieldC) i += proto.RepeatedInt32Marshal(fieldNum, buf, s.FieldC)
if err != nil {
return nil, fmt.Errorf("can't marshal field c: %w", err)
}
i += offset
fieldNum = 4 fieldNum = 4
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.RepeatedUInt32Marshal(fieldNum, buf, s.FieldD) i += proto.RepeatedUInt32Marshal(fieldNum, buf, s.FieldD)
if err != nil {
return nil, fmt.Errorf("can't marshal field d: %w", err)
}
i += offset
fieldNum = 5 fieldNum = 5
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.RepeatedInt64Marshal(fieldNum, buf, s.FieldE) i += proto.RepeatedInt64Marshal(fieldNum, buf, s.FieldE)
if err != nil {
return nil, fmt.Errorf("can't marshal field e: %w", err)
}
i += offset
fieldNum = 6 fieldNum = 6
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset, err = proto.RepeatedUInt64Marshal(fieldNum, buf, s.FieldF) i += proto.RepeatedUInt64Marshal(fieldNum, buf, s.FieldF)
if err != nil {
return nil, fmt.Errorf("can't marshal field f: %w", err)
}
i += offset
return buf, nil return buf, nil
} }