[#50] marshal: Use protowire append methods for marshalers
Some checks failed
DCO action / DCO (pull_request) Successful in 48s
Tests and linters / Tests (1.19) (pull_request) Failing after 59s
Tests and linters / Tests with -race (pull_request) Successful in 1m31s
Tests and linters / Tests (1.20) (pull_request) Failing after 5m52s
Tests and linters / Lint (pull_request) Successful in 7m3s

* Use protowire.AppendTag to encode a tag and append it
* Use protowire.AppendVarint to append numeric data
* Use protowire.AppendBytes and protowire.AppendString

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2023-08-31 12:12:43 +03:00
parent 17bed735a1
commit 443098cb28
16 changed files with 443 additions and 590 deletions

View file

@ -21,13 +21,11 @@ func (d *Decimal) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, d.StableSize()) buf = make([]byte, 0, d.StableSize())
} }
var offset int buf = protoutil.Int64Marshal(decimalValueField, buf, d.val)
buf = protoutil.UInt32Marshal(decimalPrecisionField, buf, d.prec)
offset += protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val)
protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec)
return buf return buf
} }
@ -53,10 +51,10 @@ func (b *BalanceRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, b.StableSize()) buf = make([]byte, 0, b.StableSize())
} }
protoutil.NestedStructureMarshal(balanceReqBodyOwnerField, buf, b.ownerID) buf = protoutil.NestedStructureMarshal(balanceReqBodyOwnerField, buf, b.ownerID)
return buf return buf
} }
@ -81,10 +79,10 @@ func (br *BalanceResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, br.StableSize()) buf = make([]byte, 0, br.StableSize())
} }
protoutil.NestedStructureMarshal(balanceRespBodyDecimalField, buf, br.bal) buf = protoutil.NestedStructureMarshal(balanceRespBodyDecimalField, buf, br.bal)
return buf return buf
} }

View file

@ -45,16 +45,14 @@ func (t *Table) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, t.StableSize()) buf = make([]byte, 0, t.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(tableVersionField, buf, t.version)
buf = protoutil.NestedStructureMarshal(tableContainerIDField, buf, t.cid)
offset += protoutil.NestedStructureMarshal(tableVersionField, buf[offset:], t.version)
offset += protoutil.NestedStructureMarshal(tableContainerIDField, buf[offset:], t.cid)
for i := range t.records { for i := range t.records {
offset += protoutil.NestedStructureMarshal(tableRecordsField, buf[offset:], &t.records[i]) buf = protoutil.NestedStructureMarshal(tableRecordsField, buf, &t.records[i])
} }
return buf return buf
@ -88,20 +86,18 @@ func (r *Record) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = protoutil.EnumMarshal(recordOperationField, buf, int32(r.op))
buf = protoutil.EnumMarshal(recordActionField, buf, int32(r.action))
offset += protoutil.EnumMarshal(recordOperationField, buf[offset:], int32(r.op))
offset += protoutil.EnumMarshal(recordActionField, buf[offset:], int32(r.action))
for i := range r.filters { for i := range r.filters {
offset += protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i]) buf = protoutil.NestedStructureMarshal(recordFiltersField, buf, &r.filters[i])
} }
for i := range r.targets { for i := range r.targets {
offset += protoutil.NestedStructureMarshal(recordTargetsField, buf[offset:], &r.targets[i]) buf = protoutil.NestedStructureMarshal(recordTargetsField, buf, &r.targets[i])
} }
return buf return buf
@ -139,15 +135,13 @@ func (f *HeaderFilter) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, f.StableSize()) buf = make([]byte, 0, f.StableSize())
} }
var offset int buf = protoutil.EnumMarshal(filterHeaderTypeField, buf, int32(f.hdrType))
buf = protoutil.EnumMarshal(filterMatchTypeField, buf, int32(f.matchType))
offset += protoutil.EnumMarshal(filterHeaderTypeField, buf[offset:], int32(f.hdrType)) buf = protoutil.StringMarshal(filterNameField, buf, f.key)
offset += protoutil.EnumMarshal(filterMatchTypeField, buf[offset:], int32(f.matchType)) buf = protoutil.StringMarshal(filterValueField, buf, f.value)
offset += protoutil.StringMarshal(filterNameField, buf[offset:], f.key)
protoutil.StringMarshal(filterValueField, buf[offset:], f.value)
return buf return buf
} }
@ -178,13 +172,11 @@ func (t *Target) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, t.StableSize()) buf = make([]byte, 0, t.StableSize())
} }
var offset int buf = protoutil.EnumMarshal(targetTypeField, buf, int32(t.role))
buf = protoutil.RepeatedBytesMarshal(targetKeysField, buf, t.keys)
offset += protoutil.EnumMarshal(targetTypeField, buf[offset:], int32(t.role))
protoutil.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys)
return buf return buf
} }
@ -211,14 +203,12 @@ func (l *TokenLifetime) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, l.StableSize()) buf = make([]byte, 0, l.StableSize())
} }
var offset int buf = protoutil.UInt64Marshal(lifetimeExpirationField, buf, l.exp)
buf = protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf, l.nbf)
offset += protoutil.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp) buf = protoutil.UInt64Marshal(lifetimeIssuedAtField, buf, l.iat)
offset += protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
protoutil.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
return buf return buf
} }
@ -245,15 +235,13 @@ func (bt *BearerTokenBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, bt.StableSize()) buf = make([]byte, 0, bt.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(bearerTokenBodyACLField, buf, bt.eacl)
buf = protoutil.NestedStructureMarshal(bearerTokenBodyOwnerField, buf, bt.ownerID)
offset += protoutil.NestedStructureMarshal(bearerTokenBodyACLField, buf[offset:], bt.eacl) buf = protoutil.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf, bt.lifetime)
offset += protoutil.NestedStructureMarshal(bearerTokenBodyOwnerField, buf[offset:], bt.ownerID) buf = protoutil.BoolMarshal(bearerTokenBodyImpersonate, buf, bt.impersonate)
offset += protoutil.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf[offset:], bt.lifetime)
protoutil.BoolMarshal(bearerTokenBodyImpersonate, buf[offset:], bt.impersonate)
return buf return buf
} }
@ -281,13 +269,11 @@ func (bt *BearerToken) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, bt.StableSize()) buf = make([]byte, 0, bt.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(bearerTokenBodyField, buf, bt.body)
buf = protoutil.NestedStructureMarshal(bearerTokenSignatureField, buf, bt.sig)
offset += protoutil.NestedStructureMarshal(bearerTokenBodyField, buf[offset:], bt.body)
protoutil.NestedStructureMarshal(bearerTokenSignatureField, buf[offset:], bt.sig)
return buf return buf
} }

View file

@ -33,25 +33,23 @@ func (a *DataAuditResult) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, 0, a.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(versionFNum, buf, a.version)
buf = proto.Fixed64Marshal(auditEpochFNum, buf, a.auditEpoch)
offset += proto.NestedStructureMarshal(versionFNum, buf[offset:], a.version) buf = proto.NestedStructureMarshal(cidFNum, buf, a.cid)
offset += proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch) buf = proto.BytesMarshal(pubKeyFNum, buf, a.pubKey)
offset += proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid) buf = proto.BoolMarshal(completeFNum, buf, a.complete)
offset += proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey) buf = proto.UInt32Marshal(requestsFNum, buf, a.requests)
offset += proto.BoolMarshal(completeFNum, buf[offset:], a.complete) buf = proto.UInt32Marshal(retriesFNum, buf, a.retries)
offset += proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests) buf = refs.ObjectIDNestedListMarshal(passSGFNum, buf, a.passSG)
offset += proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries) buf = refs.ObjectIDNestedListMarshal(failSGFNum, buf, a.failSG)
offset += refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG) buf = proto.UInt32Marshal(hitFNum, buf, a.hit)
offset += refs.ObjectIDNestedListMarshal(failSGFNum, buf[offset:], a.failSG) buf = proto.UInt32Marshal(missFNum, buf, a.miss)
offset += proto.UInt32Marshal(hitFNum, buf[offset:], a.hit) buf = proto.UInt32Marshal(failFNum, buf, a.fail)
offset += proto.UInt32Marshal(missFNum, buf[offset:], a.miss) buf = proto.RepeatedBytesMarshal(passNodesFNum, buf, a.passNodes)
offset += proto.UInt32Marshal(failFNum, buf[offset:], a.fail) buf = proto.RepeatedBytesMarshal(failNodesFNum, buf, a.failNodes)
offset += proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes)
proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes)
return buf return buf
} }

View file

@ -57,13 +57,11 @@ func (a *Attribute) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, 0, a.StableSize())
} }
var offset int buf = protoutil.StringMarshal(attributeKeyField, buf, a.key)
buf = protoutil.StringMarshal(attributeValueField, buf, a.val)
offset += protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key)
protoutil.StringMarshal(attributeValueField, buf[offset:], a.val)
return buf return buf
} }
@ -89,21 +87,19 @@ func (c *Container) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, c.StableSize()) buf = make([]byte, 0, c.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(containerVersionField, buf, c.version)
buf = protoutil.NestedStructureMarshal(containerOwnerField, buf, c.ownerID)
offset += protoutil.NestedStructureMarshal(containerVersionField, buf[offset:], c.version) buf = protoutil.BytesMarshal(containerNonceField, buf, c.nonce)
offset += protoutil.NestedStructureMarshal(containerOwnerField, buf[offset:], c.ownerID) buf = protoutil.UInt32Marshal(containerBasicACLField, buf, c.basicACL)
offset += protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce)
offset += protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL)
for i := range c.attr { for i := range c.attr {
offset += protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i]) buf = protoutil.NestedStructureMarshal(containerAttributesField, buf, &c.attr[i])
} }
protoutil.NestedStructureMarshal(containerPlacementField, buf[offset:], c.policy) buf = protoutil.NestedStructureMarshal(containerPlacementField, buf, c.policy)
return buf return buf
} }
@ -137,13 +133,11 @@ func (r *PutRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(putReqBodyContainerField, buf, r.cnr)
buf = protoutil.NestedStructureMarshal(putReqBodySignatureField, buf, r.sig)
offset += protoutil.NestedStructureMarshal(putReqBodyContainerField, buf[offset:], r.cnr)
protoutil.NestedStructureMarshal(putReqBodySignatureField, buf[offset:], r.sig)
return buf return buf
} }
@ -169,10 +163,10 @@ func (r *PutResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
protoutil.NestedStructureMarshal(putRespBodyIDField, buf, r.cid) buf = protoutil.NestedStructureMarshal(putRespBodyIDField, buf, r.cid)
return buf return buf
} }
@ -197,13 +191,11 @@ func (r *DeleteRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(deleteReqBodyIDField, buf, r.cid)
buf = protoutil.NestedStructureMarshal(deleteReqBodySignatureField, buf, r.sig)
offset += protoutil.NestedStructureMarshal(deleteReqBodyIDField, buf[offset:], r.cid)
protoutil.NestedStructureMarshal(deleteReqBodySignatureField, buf[offset:], r.sig)
return buf return buf
} }
@ -241,10 +233,10 @@ func (r *GetRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
protoutil.NestedStructureMarshal(getReqBodyIDField, buf, r.cid) buf = protoutil.NestedStructureMarshal(getReqBodyIDField, buf, r.cid)
return buf return buf
} }
@ -269,14 +261,12 @@ func (r *GetResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr)
buf = protoutil.NestedStructureMarshal(getRespBodySignatureField, buf, r.sig)
offset += protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr) buf = protoutil.NestedStructureMarshal(getRespBodyTokenField, buf, r.token)
offset += protoutil.NestedStructureMarshal(getRespBodySignatureField, buf[offset:], r.sig)
protoutil.NestedStructureMarshal(getRespBodyTokenField, buf[offset:], r.token)
return buf return buf
} }
@ -303,10 +293,10 @@ func (r *ListRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
protoutil.NestedStructureMarshal(listReqBodyOwnerField, buf, r.ownerID) buf = protoutil.NestedStructureMarshal(listReqBodyOwnerField, buf, r.ownerID)
return buf return buf
} }
@ -331,13 +321,11 @@ func (r *ListResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int
for i := range r.cidList { for i := range r.cidList {
offset += protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], &r.cidList[i]) buf = protoutil.NestedStructureMarshal(listRespBodyIDsField, buf, &r.cidList[i])
} }
return buf return buf
@ -365,13 +353,11 @@ func (r *SetExtendedACLRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(setEACLReqBodyTableField, buf, r.eacl)
buf = protoutil.NestedStructureMarshal(setEACLReqBodySignatureField, buf, r.sig)
offset += protoutil.NestedStructureMarshal(setEACLReqBodyTableField, buf[offset:], r.eacl)
protoutil.NestedStructureMarshal(setEACLReqBodySignatureField, buf[offset:], r.sig)
return buf return buf
} }
@ -409,10 +395,10 @@ func (r *GetExtendedACLRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
protoutil.NestedStructureMarshal(getEACLReqBodyIDField, buf, r.cid) buf = protoutil.NestedStructureMarshal(getEACLReqBodyIDField, buf, r.cid)
return buf return buf
} }
@ -437,14 +423,12 @@ func (r *GetExtendedACLResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(getEACLRespBodyTableField, buf, r.eacl)
buf = protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf, r.sig)
offset += protoutil.NestedStructureMarshal(getEACLRespBodyTableField, buf[offset:], r.eacl) buf = protoutil.NestedStructureMarshal(getEACLRespBodyTokenField, buf, r.token)
offset += protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig)
protoutil.NestedStructureMarshal(getEACLRespBodyTokenField, buf[offset:], r.token)
return buf return buf
} }
@ -471,14 +455,12 @@ func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, 0, a.StableSize())
} }
var offset int buf = protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf, a.epoch)
buf = protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf, a.cid)
offset += protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch) buf = protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf, a.usedSpace)
offset += protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid)
protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf[offset:], a.usedSpace)
return buf return buf
} }
@ -505,13 +487,11 @@ func (r *AnnounceUsedSpaceRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int
for i := range r.announcements { for i := range r.announcements {
offset += protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf[offset:], &r.announcements[i]) buf = protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf, &r.announcements[i])
} }
return buf return buf

View file

@ -47,18 +47,16 @@ func (f *Filter) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, f.StableSize()) buf = make([]byte, 0, f.StableSize())
} }
var offset int buf = protoutil.StringMarshal(nameFilterField, buf, f.name)
buf = protoutil.StringMarshal(keyFilterField, buf, f.key)
offset += protoutil.StringMarshal(nameFilterField, buf[offset:], f.name) buf = protoutil.EnumMarshal(opFilterField, buf, int32(f.op))
offset += protoutil.StringMarshal(keyFilterField, buf[offset:], f.key) buf = protoutil.StringMarshal(valueFilterField, buf, f.value)
offset += protoutil.EnumMarshal(opFilterField, buf[offset:], int32(f.op))
offset += protoutil.StringMarshal(valueFilterField, buf[offset:], f.value)
for i := range f.filters { for i := range f.filters {
offset += protoutil.NestedStructureMarshal(filtersFilterField, buf[offset:], &f.filters[i]) buf = protoutil.NestedStructureMarshal(filtersFilterField, buf, &f.filters[i])
} }
return buf return buf
@ -90,16 +88,14 @@ func (s *Selector) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.StableSize()) buf = make([]byte, 0, s.StableSize())
} }
var offset int buf = protoutil.StringMarshal(nameSelectorField, buf, s.name)
buf = protoutil.UInt32Marshal(countSelectorField, buf, s.count)
offset += protoutil.StringMarshal(nameSelectorField, buf[offset:], s.name) buf = protoutil.EnumMarshal(clauseSelectorField, buf, int32(s.clause))
offset += protoutil.UInt32Marshal(countSelectorField, buf[offset:], s.count) buf = protoutil.StringMarshal(attributeSelectorField, buf, s.attribute)
offset += protoutil.EnumMarshal(clauseSelectorField, buf[offset:], int32(s.clause)) buf = protoutil.StringMarshal(filterSelectorField, buf, s.filter)
offset += protoutil.StringMarshal(attributeSelectorField, buf[offset:], s.attribute)
protoutil.StringMarshal(filterSelectorField, buf[offset:], s.filter)
return buf return buf
} }
@ -128,13 +124,11 @@ func (r *Replica) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = protoutil.UInt32Marshal(countReplicaField, buf, r.count)
buf = protoutil.StringMarshal(selectorReplicaField, buf, r.selector)
offset += protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count)
protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector)
return buf return buf
} }
@ -160,26 +154,24 @@ func (p *PlacementPolicy) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, p.StableSize()) buf = make([]byte, 0, p.StableSize())
} }
var offset int
for i := range p.replicas { for i := range p.replicas {
offset += protoutil.NestedStructureMarshal(replicasPolicyField, buf[offset:], &p.replicas[i]) buf = protoutil.NestedStructureMarshal(replicasPolicyField, buf, &p.replicas[i])
} }
offset += protoutil.UInt32Marshal(backupPolicyField, buf[offset:], p.backupFactor) buf = protoutil.UInt32Marshal(backupPolicyField, buf, p.backupFactor)
for i := range p.selectors { for i := range p.selectors {
offset += protoutil.NestedStructureMarshal(selectorsPolicyField, buf[offset:], &p.selectors[i]) buf = protoutil.NestedStructureMarshal(selectorsPolicyField, buf, &p.selectors[i])
} }
for i := range p.filters { for i := range p.filters {
offset += protoutil.NestedStructureMarshal(filtersPolicyField, buf[offset:], &p.filters[i]) buf = protoutil.NestedStructureMarshal(filtersPolicyField, buf, &p.filters[i])
} }
protoutil.BoolMarshal(uniquePolicyField, buf[offset:], p.unique) buf = protoutil.BoolMarshal(uniquePolicyField, buf, p.unique)
return buf return buf
} }
@ -218,16 +210,14 @@ func (a *Attribute) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, 0, a.StableSize())
} }
var offset int buf = protoutil.StringMarshal(keyAttributeField, buf, a.key)
buf = protoutil.StringMarshal(valueAttributeField, buf, a.value)
offset += protoutil.StringMarshal(keyAttributeField, buf[offset:], a.key)
offset += protoutil.StringMarshal(valueAttributeField, buf[offset:], a.value)
for i := range a.parents { for i := range a.parents {
offset += protoutil.StringMarshal(parentsAttributeField, buf[offset:], a.parents[i]) buf = protoutil.StringMarshal(parentsAttributeField, buf, a.parents[i])
} }
return buf return buf
@ -258,19 +248,17 @@ func (ni *NodeInfo) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, ni.StableSize()) buf = make([]byte, 0, ni.StableSize())
} }
var offset int buf = protoutil.BytesMarshal(keyNodeInfoField, buf, ni.publicKey)
buf = protoutil.RepeatedStringMarshal(addressNodeInfoField, buf, ni.addresses)
offset += protoutil.BytesMarshal(keyNodeInfoField, buf[offset:], ni.publicKey)
offset += protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses)
for i := range ni.attributes { for i := range ni.attributes {
offset += protoutil.NestedStructureMarshal(attributesNodeInfoField, buf[offset:], &ni.attributes[i]) buf = protoutil.NestedStructureMarshal(attributesNodeInfoField, buf, &ni.attributes[i])
} }
protoutil.EnumMarshal(stateNodeInfoField, buf[offset:], int32(ni.state)) buf = protoutil.EnumMarshal(stateNodeInfoField, buf, int32(ni.state))
return buf return buf
} }
@ -314,13 +302,11 @@ func (l *LocalNodeInfoResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, l.StableSize()) buf = make([]byte, 0, l.StableSize())
} }
var offset int buf = protoutil.NestedStructureMarshal(versionInfoResponseBodyField, buf, l.version)
buf = protoutil.NestedStructureMarshal(nodeInfoResponseBodyField, buf, l.nodeInfo)
offset += protoutil.NestedStructureMarshal(versionInfoResponseBodyField, buf[offset:], l.version)
protoutil.NestedStructureMarshal(nodeInfoResponseBodyField, buf[offset:], l.nodeInfo)
return buf return buf
} }
@ -352,13 +338,11 @@ func (x *NetworkParameter) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
var offset int buf = protoutil.BytesMarshal(netPrmKeyFNum, buf, x.k)
buf = protoutil.BytesMarshal(netPrmValFNum, buf, x.v)
offset += protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k)
protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v)
return buf return buf
} }
@ -385,13 +369,11 @@ func (x *NetworkConfig) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
var offset int
for i := range x.ps { for i := range x.ps {
offset += protoutil.NestedStructureMarshal(netCfgPrmsFNum, buf[offset:], &x.ps[i]) buf = protoutil.NestedStructureMarshal(netCfgPrmsFNum, buf, &x.ps[i])
} }
return buf return buf
@ -423,15 +405,13 @@ func (i *NetworkInfo) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, i.StableSize()) buf = make([]byte, 0, i.StableSize())
} }
var offset int buf = protoutil.UInt64Marshal(netInfoCurEpochFNum, buf, i.curEpoch)
buf = protoutil.UInt64Marshal(netInfoMagicNumFNum, buf, i.magicNum)
offset += protoutil.UInt64Marshal(netInfoCurEpochFNum, buf[offset:], i.curEpoch) buf = protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf, i.msPerBlock)
offset += protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum) buf = protoutil.NestedStructureMarshal(netInfoCfgFNum, buf, i.netCfg)
offset += protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock)
protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg)
return buf return buf
} }
@ -476,10 +456,10 @@ func (i *NetworkInfoResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, i.StableSize()) buf = make([]byte, 0, i.StableSize())
} }
protoutil.NestedStructureMarshal(netInfoRespBodyNetInfoFNum, buf, i.netInfo) buf = protoutil.NestedStructureMarshal(netInfoRespBodyNetInfoFNum, buf, i.netInfo)
return buf return buf
} }
@ -510,13 +490,13 @@ func (x *NetMap) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
offset := protoutil.UInt64Marshal(fNumNetMapEpoch, buf, x.epoch) buf = protoutil.UInt64Marshal(fNumNetMapEpoch, buf, x.epoch)
for i := range x.nodes { for i := range x.nodes {
offset += protoutil.NestedStructureMarshal(fNumNetMapNodes, buf[offset:], &x.nodes[i]) buf = protoutil.NestedStructureMarshal(fNumNetMapNodes, buf, &x.nodes[i])
} }
return buf return buf
@ -553,10 +533,10 @@ func (x *SnapshotResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
protoutil.NestedStructureMarshal(fNumSnapshotResponseBodyNetMap, buf, x.netMap) buf = protoutil.NestedStructureMarshal(fNumSnapshotResponseBodyNetMap, buf, x.netMap)
return buf return buf
} }

View file

@ -54,13 +54,11 @@ func (x *Lock) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
var offset int
for i := range x.members { for i := range x.members {
offset += proto.NestedStructureMarshal(fNumLockMembers, buf[offset:], &x.members[i]) buf = proto.NestedStructureMarshal(fNumLockMembers, buf, &x.members[i])
} }
return buf return buf

View file

@ -121,18 +121,16 @@ func (h *ShortHeader) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, h.StableSize()) buf = make([]byte, 0, h.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(shortHdrVersionField, buf, h.version)
buf = proto.UInt64Marshal(shortHdrEpochField, buf, h.creatEpoch)
offset += proto.NestedStructureMarshal(shortHdrVersionField, buf[offset:], h.version) buf = proto.NestedStructureMarshal(shortHdrOwnerField, buf, h.ownerID)
offset += proto.UInt64Marshal(shortHdrEpochField, buf[offset:], h.creatEpoch) buf = proto.EnumMarshal(shortHdrObjectTypeField, buf, int32(h.typ))
offset += proto.NestedStructureMarshal(shortHdrOwnerField, buf[offset:], h.ownerID) buf = proto.UInt64Marshal(shortHdrPayloadLength, buf, h.payloadLen)
offset += proto.EnumMarshal(shortHdrObjectTypeField, buf[offset:], int32(h.typ)) buf = proto.NestedStructureMarshal(shortHdrHashField, buf, h.payloadHash)
offset += proto.UInt64Marshal(shortHdrPayloadLength, buf[offset:], h.payloadLen) buf = proto.NestedStructureMarshal(shortHdrHomoHashField, buf, h.homoHash)
offset += proto.NestedStructureMarshal(shortHdrHashField, buf[offset:], h.payloadHash)
proto.NestedStructureMarshal(shortHdrHomoHashField, buf[offset:], h.homoHash)
return buf return buf
} }
@ -163,13 +161,11 @@ func (a *Attribute) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, 0, a.StableSize())
} }
var offset int buf = proto.StringMarshal(attributeKeyField, buf, a.key)
buf = proto.StringMarshal(attributeValueField, buf, a.val)
offset += proto.StringMarshal(attributeKeyField, buf[offset:], a.key)
proto.StringMarshal(attributeValueField, buf[offset:], a.val)
return buf return buf
} }
@ -195,17 +191,15 @@ func (h *SplitHeader) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, h.StableSize()) buf = make([]byte, 0, h.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(splitHdrParentField, buf, h.par)
buf = proto.NestedStructureMarshal(splitHdrPreviousField, buf, h.prev)
offset += proto.NestedStructureMarshal(splitHdrParentField, buf[offset:], h.par) buf = proto.NestedStructureMarshal(splitHdrParentSignatureField, buf, h.parSig)
offset += proto.NestedStructureMarshal(splitHdrPreviousField, buf[offset:], h.prev) buf = proto.NestedStructureMarshal(splitHdrParentHeaderField, buf, h.parHdr)
offset += proto.NestedStructureMarshal(splitHdrParentSignatureField, buf[offset:], h.parSig) buf = refs.ObjectIDNestedListMarshal(splitHdrChildrenField, buf, h.children)
offset += proto.NestedStructureMarshal(splitHdrParentHeaderField, buf[offset:], h.parHdr) buf = proto.BytesMarshal(splitHdrSplitIDField, buf, h.splitID)
offset += refs.ObjectIDNestedListMarshal(splitHdrChildrenField, buf[offset:], h.children)
proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID)
return buf return buf
} }
@ -235,26 +229,24 @@ func (h *Header) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, h.StableSize()) buf = make([]byte, 0, h.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(hdrVersionField, buf, h.version)
buf = proto.NestedStructureMarshal(hdrContainerIDField, buf, h.cid)
offset += proto.NestedStructureMarshal(hdrVersionField, buf[offset:], h.version) buf = proto.NestedStructureMarshal(hdrOwnerIDField, buf, h.ownerID)
offset += proto.NestedStructureMarshal(hdrContainerIDField, buf[offset:], h.cid) buf = proto.UInt64Marshal(hdrEpochField, buf, h.creatEpoch)
offset += proto.NestedStructureMarshal(hdrOwnerIDField, buf[offset:], h.ownerID) buf = proto.UInt64Marshal(hdrPayloadLengthField, buf, h.payloadLen)
offset += proto.UInt64Marshal(hdrEpochField, buf[offset:], h.creatEpoch) buf = proto.NestedStructureMarshal(hdrPayloadHashField, buf, h.payloadHash)
offset += proto.UInt64Marshal(hdrPayloadLengthField, buf[offset:], h.payloadLen) buf = proto.EnumMarshal(hdrObjectTypeField, buf, int32(h.typ))
offset += proto.NestedStructureMarshal(hdrPayloadHashField, buf[offset:], h.payloadHash) buf = proto.NestedStructureMarshal(hdrHomomorphicHashField, buf, h.homoHash)
offset += proto.EnumMarshal(hdrObjectTypeField, buf[offset:], int32(h.typ)) buf = proto.NestedStructureMarshal(hdrSessionTokenField, buf, h.sessionToken)
offset += proto.NestedStructureMarshal(hdrHomomorphicHashField, buf[offset:], h.homoHash)
offset += proto.NestedStructureMarshal(hdrSessionTokenField, buf[offset:], h.sessionToken)
for i := range h.attr { for i := range h.attr {
offset += proto.NestedStructureMarshal(hdrAttributesField, buf[offset:], &h.attr[i]) buf = proto.NestedStructureMarshal(hdrAttributesField, buf, &h.attr[i])
} }
proto.NestedStructureMarshal(hdrSplitField, buf[offset:], h.split) buf = proto.NestedStructureMarshal(hdrSplitField, buf, h.split)
return buf return buf
} }
@ -291,13 +283,11 @@ func (h *HeaderWithSignature) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, h.StableSize()) buf = make([]byte, 0, h.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(hdrWithSigHeaderField, buf, h.header)
buf = proto.NestedStructureMarshal(hdrWithSigSignatureField, buf, h.signature)
offset += proto.NestedStructureMarshal(hdrWithSigHeaderField, buf[offset:], h.header)
proto.NestedStructureMarshal(hdrWithSigSignatureField, buf[offset:], h.signature)
return buf return buf
} }
@ -323,15 +313,13 @@ func (o *Object) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, o.StableSize()) buf = make([]byte, 0, o.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(objIDField, buf, o.objectID)
buf = proto.NestedStructureMarshal(objSignatureField, buf, o.idSig)
offset += proto.NestedStructureMarshal(objIDField, buf[offset:], o.objectID) buf = proto.NestedStructureMarshal(objHeaderField, buf, o.header)
offset += proto.NestedStructureMarshal(objSignatureField, buf[offset:], o.idSig) buf = proto.BytesMarshal(objPayloadField, buf, o.payload)
offset += proto.NestedStructureMarshal(objHeaderField, buf[offset:], o.header)
proto.BytesMarshal(objPayloadField, buf[offset:], o.payload)
return buf return buf
} }
@ -359,14 +347,12 @@ func (s *SplitInfo) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.StableSize()) buf = make([]byte, 0, s.StableSize())
} }
var offset int buf = proto.BytesMarshal(splitInfoSplitIDField, buf, s.splitID)
buf = proto.NestedStructureMarshal(splitInfoLastPartField, buf, s.lastPart)
offset += proto.BytesMarshal(splitInfoSplitIDField, buf[offset:], s.splitID) buf = proto.NestedStructureMarshal(splitInfoLinkField, buf, s.link)
offset += proto.NestedStructureMarshal(splitInfoLastPartField, buf[offset:], s.lastPart)
proto.NestedStructureMarshal(splitInfoLinkField, buf[offset:], s.link)
return buf return buf
} }
@ -393,13 +379,11 @@ func (r *GetRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(getReqBodyAddressField, buf, r.addr)
buf = proto.BoolMarshal(getReqBodyRawFlagField, buf, r.raw)
offset += proto.NestedStructureMarshal(getReqBodyAddressField, buf[offset:], r.addr)
proto.BoolMarshal(getReqBodyRawFlagField, buf[offset:], r.raw)
return buf return buf
} }
@ -425,14 +409,12 @@ func (r *GetObjectPartInit) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(getRespInitObjectIDField, buf, r.id)
buf = proto.NestedStructureMarshal(getRespInitSignatureField, buf, r.sig)
offset += proto.NestedStructureMarshal(getRespInitObjectIDField, buf[offset:], r.id) buf = proto.NestedStructureMarshal(getRespInitHeaderField, buf, r.hdr)
offset += proto.NestedStructureMarshal(getRespInitSignatureField, buf[offset:], r.sig)
proto.NestedStructureMarshal(getRespInitHeaderField, buf[offset:], r.hdr)
return buf return buf
} }
@ -459,19 +441,19 @@ func (r *GetResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
switch v := r.objPart.(type) { switch v := r.objPart.(type) {
case nil: case nil:
case *GetObjectPartInit: case *GetObjectPartInit:
proto.NestedStructureMarshal(getRespBodyInitField, buf, v) buf = proto.NestedStructureMarshal(getRespBodyInitField, buf, v)
case *GetObjectPartChunk: case *GetObjectPartChunk:
if v != nil { if v != nil {
proto.BytesMarshal(getRespBodyChunkField, buf, v.chunk) buf = proto.BytesMarshal(getRespBodyChunkField, buf, v.chunk)
} }
case *SplitInfo: case *SplitInfo:
proto.NestedStructureMarshal(getRespBodySplitInfoField, buf, v) buf = proto.NestedStructureMarshal(getRespBodySplitInfoField, buf, v)
default: default:
panic("unknown one of object get response body type") panic("unknown one of object get response body type")
} }
@ -511,15 +493,13 @@ func (r *PutObjectPartInit) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(putReqInitObjectIDField, buf, r.id)
buf = proto.NestedStructureMarshal(putReqInitSignatureField, buf, r.sig)
offset += proto.NestedStructureMarshal(putReqInitObjectIDField, buf[offset:], r.id) buf = proto.NestedStructureMarshal(putReqInitHeaderField, buf, r.hdr)
offset += proto.NestedStructureMarshal(putReqInitSignatureField, buf[offset:], r.sig) buf = proto.RepeatedUInt32Marshal(putReqInitCopiesNumField, buf, r.copyNum)
offset += proto.NestedStructureMarshal(putReqInitHeaderField, buf[offset:], r.hdr)
proto.RepeatedUInt32Marshal(putReqInitCopiesNumField, buf[offset:], r.copyNum)
return buf return buf
} }
@ -549,16 +529,16 @@ func (r *PutRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
switch v := r.objPart.(type) { switch v := r.objPart.(type) {
case nil: case nil:
case *PutObjectPartInit: case *PutObjectPartInit:
proto.NestedStructureMarshal(putReqBodyInitField, buf, v) buf = proto.NestedStructureMarshal(putReqBodyInitField, buf, v)
case *PutObjectPartChunk: case *PutObjectPartChunk:
if v != nil { if v != nil {
proto.BytesMarshal(putReqBodyChunkField, buf, v.chunk) buf = proto.BytesMarshal(putReqBodyChunkField, buf, v.chunk)
} }
default: default:
panic("unknown one of object put request body type") panic("unknown one of object put request body type")
@ -597,10 +577,10 @@ func (r *PutResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
proto.NestedStructureMarshal(putRespBodyObjectIDField, buf, r.id) buf = proto.NestedStructureMarshal(putRespBodyObjectIDField, buf, r.id)
return buf return buf
} }
@ -625,10 +605,10 @@ func (r *DeleteRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
proto.NestedStructureMarshal(deleteReqBodyAddressField, buf, r.addr) buf = proto.NestedStructureMarshal(deleteReqBodyAddressField, buf, r.addr)
return buf return buf
} }
@ -653,10 +633,10 @@ func (r *DeleteResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
proto.NestedStructureMarshal(deleteRespBodyTombstoneFNum, buf, r.tombstone) buf = proto.NestedStructureMarshal(deleteRespBodyTombstoneFNum, buf, r.tombstone)
return buf return buf
} }
@ -681,14 +661,12 @@ func (r *HeadRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(headReqBodyAddressField, buf, r.addr)
buf = proto.BoolMarshal(headReqBodyMainFlagField, buf, r.mainOnly)
offset += proto.NestedStructureMarshal(headReqBodyAddressField, buf[offset:], r.addr) buf = proto.BoolMarshal(headReqBodyRawFlagField, buf, r.raw)
offset += proto.BoolMarshal(headReqBodyMainFlagField, buf[offset:], r.mainOnly)
proto.BoolMarshal(headReqBodyRawFlagField, buf[offset:], r.raw)
return buf return buf
} }
@ -715,22 +693,22 @@ func (r *HeadResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
switch v := r.hdrPart.(type) { switch v := r.hdrPart.(type) {
case nil: case nil:
case *HeaderWithSignature: case *HeaderWithSignature:
if v != nil { if v != nil {
proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v) buf = proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v)
} }
case *ShortHeader: case *ShortHeader:
if v != nil { if v != nil {
proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v) buf = proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v)
} }
case *SplitInfo: case *SplitInfo:
if v != nil { if v != nil {
proto.NestedStructureMarshal(headRespBodySplitInfoField, buf, v) buf = proto.NestedStructureMarshal(headRespBodySplitInfoField, buf, v)
} }
default: default:
panic("unknown one of object put request body type") panic("unknown one of object put request body type")
@ -775,14 +753,12 @@ func (f *SearchFilter) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, f.StableSize()) buf = make([]byte, 0, f.StableSize())
} }
var offset int buf = proto.EnumMarshal(searchFilterMatchField, buf, int32(f.matchType))
buf = proto.StringMarshal(searchFilterNameField, buf, f.key)
offset += proto.EnumMarshal(searchFilterMatchField, buf[offset:], int32(f.matchType)) buf = proto.StringMarshal(searchFilterValueField, buf, f.val)
offset += proto.StringMarshal(searchFilterNameField, buf[offset:], f.key)
proto.StringMarshal(searchFilterValueField, buf[offset:], f.val)
return buf return buf
} }
@ -809,16 +785,14 @@ func (r *SearchRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(searchReqBodyContainerIDField, buf, r.cid)
buf = proto.UInt32Marshal(searchReqBodyVersionField, buf, r.version)
offset += proto.NestedStructureMarshal(searchReqBodyContainerIDField, buf[offset:], r.cid)
offset += proto.UInt32Marshal(searchReqBodyVersionField, buf[offset:], r.version)
for i := range r.filters { for i := range r.filters {
offset += proto.NestedStructureMarshal(searchReqBodyFiltersField, buf[offset:], &r.filters[i]) buf = proto.NestedStructureMarshal(searchReqBodyFiltersField, buf, &r.filters[i])
} }
return buf return buf
@ -849,12 +823,10 @@ func (r *SearchResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = refs.ObjectIDNestedListMarshal(searchRespBodyObjectIDsField, buf, r.idList)
refs.ObjectIDNestedListMarshal(searchRespBodyObjectIDsField, buf[offset:], r.idList)
return buf return buf
} }
@ -879,13 +851,11 @@ func (r *Range) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.UInt64Marshal(rangeOffsetField, buf, r.off)
buf = proto.UInt64Marshal(rangeLengthField, buf, r.len)
offset += proto.UInt64Marshal(rangeOffsetField, buf[offset:], r.off)
proto.UInt64Marshal(rangeLengthField, buf[offset:], r.len)
return buf return buf
} }
@ -911,14 +881,12 @@ func (r *GetRangeRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(getRangeReqBodyAddressField, buf, r.addr)
buf = proto.NestedStructureMarshal(getRangeReqBodyRangeField, buf, r.rng)
offset += proto.NestedStructureMarshal(getRangeReqBodyAddressField, buf[offset:], r.addr) buf = proto.BoolMarshal(getRangeReqBodyRawField, buf, r.raw)
offset += proto.NestedStructureMarshal(getRangeReqBodyRangeField, buf[offset:], r.rng)
proto.BoolMarshal(getRangeReqBodyRawField, buf[offset:], r.raw)
return buf return buf
} }
@ -945,18 +913,18 @@ func (r *GetRangeResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
switch v := r.rngPart.(type) { switch v := r.rngPart.(type) {
case nil: case nil:
case *GetRangePartChunk: case *GetRangePartChunk:
if v != nil { if v != nil {
proto.BytesMarshal(getRangeRespChunkField, buf, v.chunk) buf = proto.BytesMarshal(getRangeRespChunkField, buf, v.chunk)
} }
case *SplitInfo: case *SplitInfo:
if v != nil { if v != nil {
proto.NestedStructureMarshal(getRangeRespSplitInfoField, buf, v) buf = proto.NestedStructureMarshal(getRangeRespSplitInfoField, buf, v)
} }
default: default:
panic("unknown one of object get range request body type") panic("unknown one of object get range request body type")
@ -997,19 +965,17 @@ func (r *GetRangeHashRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(getRangeHashReqBodyAddressField, buf, r.addr)
offset += proto.NestedStructureMarshal(getRangeHashReqBodyAddressField, buf[offset:], r.addr)
for i := range r.rngs { for i := range r.rngs {
offset += proto.NestedStructureMarshal(getRangeHashReqBodyRangesField, buf[offset:], &r.rngs[i]) buf = proto.NestedStructureMarshal(getRangeHashReqBodyRangesField, buf, &r.rngs[i])
} }
offset += proto.BytesMarshal(getRangeHashReqBodySaltField, buf[offset:], r.salt) buf = proto.BytesMarshal(getRangeHashReqBodySaltField, buf, r.salt)
proto.EnumMarshal(getRangeHashReqBodyTypeField, buf[offset:], int32(r.typ)) buf = proto.EnumMarshal(getRangeHashReqBodyTypeField, buf, int32(r.typ))
return buf return buf
} }
@ -1041,13 +1007,11 @@ func (r *GetRangeHashResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.EnumMarshal(getRangeHashRespBodyTypeField, buf, int32(r.typ))
buf = proto.RepeatedBytesMarshal(getRangeHashRespBodyHashListField, buf, r.hashList)
offset += proto.EnumMarshal(getRangeHashRespBodyTypeField, buf, int32(r.typ))
proto.RepeatedBytesMarshal(getRangeHashRespBodyHashListField, buf[offset:], r.hashList)
return buf return buf
} }
@ -1072,12 +1036,11 @@ func (r *PutSingleRequestBody) StableMarshal(buf []byte) []byte {
return []byte{} return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(putSingleReqObjectField, buf, r.object)
offset += proto.NestedStructureMarshal(putSingleReqObjectField, buf[offset:], r.object) buf = proto.RepeatedUInt32Marshal(putSingleReqCopiesNumberField, buf, r.copyNum)
proto.RepeatedUInt32Marshal(putSingleReqCopiesNumberField, buf[offset:], r.copyNum)
return buf return buf
} }
@ -1105,7 +1068,7 @@ func (r *PutSingleResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
return buf return buf

View file

@ -43,9 +43,9 @@ func benchmarkObjectIDSlice(b *testing.B, size int) {
b.Run("marshal", func(b *testing.B) { b.Run("marshal", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
buf := make([]byte, ObjectIDNestedListSize(1, ids)) buf := make([]byte, 0, ObjectIDNestedListSize(1, ids))
n := ObjectIDNestedListMarshal(1, buf, ids) buf = ObjectIDNestedListMarshal(1, buf, ids)
if n != len(buf) { if len(buf) != cap(buf) {
b.FailNow() b.FailNow()
} }
} }

View file

@ -1,8 +1,6 @@
package refs package refs
import ( import (
"encoding/binary"
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
@ -36,10 +34,10 @@ func (o *OwnerID) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, o.StableSize()) buf = make([]byte, 0, o.StableSize())
} }
proto.BytesMarshal(ownerIDValField, buf, o.val) buf = proto.BytesMarshal(ownerIDValField, buf, o.val)
return buf return buf
} }
@ -62,10 +60,10 @@ func (c *ContainerID) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, c.StableSize()) buf = make([]byte, 0, c.StableSize())
} }
proto.BytesMarshal(containerIDValField, buf, c.val) buf = proto.BytesMarshal(containerIDValField, buf, c.val)
return buf return buf
} }
@ -88,10 +86,10 @@ func (o *ObjectID) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, o.StableSize()) buf = make([]byte, 0, o.StableSize())
} }
proto.BytesMarshal(objectIDValField, buf, o.val) buf = proto.BytesMarshal(objectIDValField, buf, o.val)
return buf return buf
} }
@ -116,17 +114,16 @@ func (o *ObjectID) StableSize() int {
// ObjectIDNestedListMarshal writes protobuf repeated ObjectID field // ObjectIDNestedListMarshal writes protobuf repeated ObjectID field
// with fNum number to buf. // with fNum number to buf.
func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int) { func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) []byte {
prefix := protowire.EncodeTag(protowire.Number(fNum), protowire.BytesType)
for i := range ids { for i := range ids {
off += binary.PutUvarint(buf[off:], prefix) buf = protowire.AppendTag(buf, protowire.Number(fNum), protowire.BytesType)
n := ids[i].StableSize() n := ids[i].StableSize()
off += binary.PutUvarint(buf[off:], uint64(n)) buf = protowire.AppendVarint(buf, uint64(n))
off += proto.BytesMarshal(objectIDValField, buf[off:], ids[i].val) buf = proto.BytesMarshal(objectIDValField, buf, ids[i].val)
} }
return return buf
} }
func (o *ObjectID) Unmarshal(data []byte) error { func (o *ObjectID) Unmarshal(data []byte) error {
@ -139,13 +136,11 @@ func (a *Address) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, 0, a.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(addressContainerField, buf, a.cid)
buf = proto.NestedStructureMarshal(addressObjectField, buf, a.oid)
offset += proto.NestedStructureMarshal(addressContainerField, buf[offset:], a.cid)
proto.NestedStructureMarshal(addressObjectField, buf[offset:], a.oid)
return buf return buf
} }
@ -171,13 +166,11 @@ func (c *Checksum) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, c.StableSize()) buf = make([]byte, 0, c.StableSize())
} }
var offset int buf = proto.EnumMarshal(checksumTypeField, buf, int32(c.typ))
buf = proto.BytesMarshal(checksumValueField, buf, c.sum)
offset += proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ))
proto.BytesMarshal(checksumValueField, buf[offset:], c.sum)
return buf return buf
} }
@ -203,14 +196,12 @@ func (s *Signature) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.StableSize()) buf = make([]byte, 0, s.StableSize())
} }
var offset int buf = proto.BytesMarshal(signatureKeyField, buf, s.key)
buf = proto.BytesMarshal(signatureValueField, buf, s.sign)
offset += proto.BytesMarshal(signatureKeyField, buf[offset:], s.key) buf = proto.EnumMarshal(signatureSchemeField, buf, int32(s.scheme))
offset += proto.BytesMarshal(signatureValueField, buf[offset:], s.sign)
proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme))
return buf return buf
} }
@ -237,13 +228,11 @@ func (v *Version) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, v.StableSize()) buf = make([]byte, 0, v.StableSize())
} }
var offset int buf = proto.UInt32Marshal(versionMajorField, buf, v.major)
buf = proto.UInt32Marshal(versionMinorField, buf, v.minor)
offset += proto.UInt32Marshal(versionMajorField, buf[offset:], v.major)
proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor)
return buf return buf
} }

View file

@ -1,8 +1,6 @@
package refstest package refstest
import ( import (
"math/rand"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
) )
@ -90,7 +88,7 @@ func GenerateSignature(empty bool) *refs.Signature {
if !empty { if !empty {
m.SetKey([]byte{1}) m.SetKey([]byte{1})
m.SetSign([]byte{2}) m.SetSign([]byte{2})
m.SetScheme(refs.SignatureScheme(rand.Int31() % 3)) m.SetScheme(refs.SignatureScheme(2))
} }
return m return m

View file

@ -67,13 +67,11 @@ func (c *CreateRequestBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, c.StableSize()) buf = make([]byte, 0, c.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(createReqBodyOwnerField, buf, c.ownerID)
buf = proto.UInt64Marshal(createReqBodyExpirationField, buf, c.expiration)
offset += proto.NestedStructureMarshal(createReqBodyOwnerField, buf[offset:], c.ownerID)
proto.UInt64Marshal(createReqBodyExpirationField, buf[offset:], c.expiration)
return buf return buf
} }
@ -99,13 +97,11 @@ func (c *CreateResponseBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, c.StableSize()) buf = make([]byte, 0, c.StableSize())
} }
var offset int buf = proto.BytesMarshal(createRespBodyIDField, buf, c.id)
buf = proto.BytesMarshal(createRespBodyKeyField, buf, c.sessionKey)
offset += proto.BytesMarshal(createRespBodyIDField, buf[offset:], c.id)
proto.BytesMarshal(createRespBodyKeyField, buf[offset:], c.sessionKey)
return buf return buf
} }
@ -131,13 +127,11 @@ func (x *XHeader) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
var offset int buf = proto.StringMarshal(xheaderKeyField, buf, x.key)
buf = proto.StringMarshal(xheaderValueField, buf, x.val)
offset += proto.StringMarshal(xheaderKeyField, buf[offset:], x.key)
proto.StringMarshal(xheaderValueField, buf[offset:], x.val)
return buf return buf
} }
@ -168,14 +162,12 @@ func (l *TokenLifetime) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, l.StableSize()) buf = make([]byte, 0, l.StableSize())
} }
var offset int buf = proto.UInt64Marshal(lifetimeExpirationField, buf, l.exp)
buf = proto.UInt64Marshal(lifetimeNotValidBeforeField, buf, l.nbf)
offset += proto.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp) buf = proto.UInt64Marshal(lifetimeIssuedAtField, buf, l.iat)
offset += proto.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
proto.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
return buf return buf
} }
@ -207,11 +199,11 @@ func (c *ObjectSessionContext) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, c.StableSize()) buf = make([]byte, 0, c.StableSize())
} }
offset := proto.EnumMarshal(objectCtxVerbField, buf, int32(c.verb)) buf = proto.EnumMarshal(objectCtxVerbField, buf, int32(c.verb))
proto.NestedStructureMarshal(objectCtxTargetField, buf[offset:], objectSessionContextTarget{ buf = proto.NestedStructureMarshal(objectCtxTargetField, buf, objectSessionContextTarget{
cnr: c.cnr, cnr: c.cnr,
objs: c.objs, objs: c.objs,
}) })
@ -255,14 +247,12 @@ func (x *ContainerSessionContext) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
var offset int buf = proto.EnumMarshal(cnrCtxVerbFNum, buf, int32(ContainerSessionVerbToGRPCField(x.verb)))
buf = proto.BoolMarshal(cnrCtxWildcardFNum, buf, x.wildcard)
offset += proto.EnumMarshal(cnrCtxVerbFNum, buf[offset:], int32(ContainerSessionVerbToGRPCField(x.verb))) buf = proto.NestedStructureMarshal(cnrCtxCidFNum, buf, x.cid)
offset += proto.BoolMarshal(cnrCtxWildcardFNum, buf[offset:], x.wildcard)
proto.NestedStructureMarshal(cnrCtxCidFNum, buf[offset:], x.cid)
return buf return buf
} }
@ -289,22 +279,20 @@ func (t *TokenBody) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, t.StableSize()) buf = make([]byte, 0, t.StableSize())
} }
var offset int buf = proto.BytesMarshal(sessionTokenBodyIDField, buf, t.id)
buf = proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf, t.ownerID)
offset += proto.BytesMarshal(sessionTokenBodyIDField, buf[offset:], t.id) buf = proto.NestedStructureMarshal(sessionTokenBodyLifetimeField, buf, t.lifetime)
offset += proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf[offset:], t.ownerID) buf = proto.BytesMarshal(sessionTokenBodyKeyField, buf, t.sessionKey)
offset += proto.NestedStructureMarshal(sessionTokenBodyLifetimeField, buf[offset:], t.lifetime)
offset += proto.BytesMarshal(sessionTokenBodyKeyField, buf[offset:], t.sessionKey)
if t.ctx != nil { if t.ctx != nil {
switch v := t.ctx.(type) { switch v := t.ctx.(type) {
case *ObjectSessionContext: case *ObjectSessionContext:
proto.NestedStructureMarshal(sessionTokenBodyObjectCtxField, buf[offset:], v) buf = proto.NestedStructureMarshal(sessionTokenBodyObjectCtxField, buf, v)
case *ContainerSessionContext: case *ContainerSessionContext:
proto.NestedStructureMarshal(sessionTokenBodyCnrCtxField, buf[offset:], v) buf = proto.NestedStructureMarshal(sessionTokenBodyCnrCtxField, buf, v)
default: default:
panic("cannot marshal unknown session token context") panic("cannot marshal unknown session token context")
} }
@ -352,13 +340,11 @@ func (t *Token) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, t.StableSize()) buf = make([]byte, 0, t.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(sessionTokenBodyField, buf, t.body)
buf = proto.NestedStructureMarshal(sessionTokenSignatureField, buf, t.sig)
offset += proto.NestedStructureMarshal(sessionTokenBodyField, buf[offset:], t.body)
proto.NestedStructureMarshal(sessionTokenSignatureField, buf[offset:], t.sig)
return buf return buf
} }
@ -389,23 +375,21 @@ func (r *RequestMetaHeader) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(reqMetaHeaderVersionField, buf, r.version)
buf = proto.UInt64Marshal(reqMetaHeaderEpochField, buf, r.epoch)
offset += proto.NestedStructureMarshal(reqMetaHeaderVersionField, buf[offset:], r.version) buf = proto.UInt32Marshal(reqMetaHeaderTTLField, buf, r.ttl)
offset += proto.UInt64Marshal(reqMetaHeaderEpochField, buf[offset:], r.epoch)
offset += proto.UInt32Marshal(reqMetaHeaderTTLField, buf[offset:], r.ttl)
for i := range r.xHeaders { for i := range r.xHeaders {
offset += proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i]) buf = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf, &r.xHeaders[i])
} }
offset += proto.NestedStructureMarshal(reqMetaHeaderSessionTokenField, buf[offset:], r.sessionToken) buf = proto.NestedStructureMarshal(reqMetaHeaderSessionTokenField, buf, r.sessionToken)
offset += proto.NestedStructureMarshal(reqMetaHeaderBearerTokenField, buf[offset:], r.bearerToken) buf = proto.NestedStructureMarshal(reqMetaHeaderBearerTokenField, buf, r.bearerToken)
offset += proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf[offset:], r.origin) buf = proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf, r.origin)
proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf[offset:], r.netMagic) buf = proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf, r.netMagic)
return buf return buf
} }
@ -449,15 +433,13 @@ func (r *RequestVerificationHeader) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(reqVerifHeaderBodySignatureField, buf, r.bodySig)
buf = proto.NestedStructureMarshal(reqVerifHeaderMetaSignatureField, buf, r.metaSig)
offset += proto.NestedStructureMarshal(reqVerifHeaderBodySignatureField, buf[offset:], r.bodySig) buf = proto.NestedStructureMarshal(reqVerifHeaderOriginSignatureField, buf, r.originSig)
offset += proto.NestedStructureMarshal(reqVerifHeaderMetaSignatureField, buf[offset:], r.metaSig) buf = proto.NestedStructureMarshal(reqVerifHeaderOriginField, buf, r.origin)
offset += proto.NestedStructureMarshal(reqVerifHeaderOriginSignatureField, buf[offset:], r.originSig)
proto.NestedStructureMarshal(reqVerifHeaderOriginField, buf[offset:], r.origin)
return buf return buf
} }
@ -490,21 +472,19 @@ func (r *ResponseMetaHeader) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(respMetaHeaderVersionField, buf, r.version)
buf = proto.UInt64Marshal(respMetaHeaderEpochField, buf, r.epoch)
offset += proto.NestedStructureMarshal(respMetaHeaderVersionField, buf[offset:], r.version) buf = proto.UInt32Marshal(respMetaHeaderTTLField, buf, r.ttl)
offset += proto.UInt64Marshal(respMetaHeaderEpochField, buf[offset:], r.epoch)
offset += proto.UInt32Marshal(respMetaHeaderTTLField, buf[offset:], r.ttl)
for i := range r.xHeaders { for i := range r.xHeaders {
offset += proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i]) buf = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf, &r.xHeaders[i])
} }
offset += proto.NestedStructureMarshal(respMetaHeaderOriginField, buf[offset:], r.origin) buf = proto.NestedStructureMarshal(respMetaHeaderOriginField, buf, r.origin)
proto.NestedStructureMarshal(respMetaHeaderStatusField, buf[offset:], r.status) buf = proto.NestedStructureMarshal(respMetaHeaderStatusField, buf, r.status)
return buf return buf
} }
@ -546,15 +526,13 @@ func (r *ResponseVerificationHeader) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, 0, r.StableSize())
} }
var offset int buf = proto.NestedStructureMarshal(respVerifHeaderBodySignatureField, buf, r.bodySig)
buf = proto.NestedStructureMarshal(respVerifHeaderMetaSignatureField, buf, r.metaSig)
offset += proto.NestedStructureMarshal(respVerifHeaderBodySignatureField, buf[offset:], r.bodySig) buf = proto.NestedStructureMarshal(respVerifHeaderOriginSignatureField, buf, r.originSig)
offset += proto.NestedStructureMarshal(respVerifHeaderMetaSignatureField, buf[offset:], r.metaSig) buf = proto.NestedStructureMarshal(respVerifHeaderOriginField, buf, r.origin)
offset += proto.NestedStructureMarshal(respVerifHeaderOriginSignatureField, buf[offset:], r.originSig)
proto.NestedStructureMarshal(respVerifHeaderOriginField, buf[offset:], r.origin)
return buf return buf
} }

View file

@ -55,13 +55,13 @@ const (
func (x objectSessionContextTarget) StableMarshal(buf []byte) []byte { func (x objectSessionContextTarget) StableMarshal(buf []byte) []byte {
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
offset := proto.NestedStructureMarshal(fNumObjectTargetContainer, buf, x.cnr) buf = proto.NestedStructureMarshal(fNumObjectTargetContainer, buf, x.cnr)
for i := range x.objs { for i := range x.objs {
offset += proto.NestedStructureMarshal(fNumObjectTargetObjects, buf[offset:], &x.objs[i]) buf = proto.NestedStructureMarshal(fNumObjectTargetObjects, buf, &x.objs[i])
} }
return buf return buf

View file

@ -18,13 +18,13 @@ func (x *Detail) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
var offset int var offset int
offset += protoutil.UInt32Marshal(detailIDFNum, buf[offset:], x.id) buf = protoutil.UInt32Marshal(detailIDFNum, buf[offset:], x.id)
protoutil.BytesMarshal(detailValueFNum, buf[offset:], x.val) buf = protoutil.BytesMarshal(detailValueFNum, buf[offset:], x.val)
return buf return buf
} }
@ -57,16 +57,16 @@ func (x *Status) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, 0, x.StableSize())
} }
var offset int var offset int
offset += protoutil.UInt32Marshal(statusCodeFNum, buf[offset:], CodeToGRPC(x.code)) buf = protoutil.UInt32Marshal(statusCodeFNum, buf[offset:], CodeToGRPC(x.code))
offset += protoutil.StringMarshal(statusMsgFNum, buf[offset:], x.msg) buf = protoutil.StringMarshal(statusMsgFNum, buf[offset:], x.msg)
for i := range x.details { for i := range x.details {
offset += protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i]) buf = protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i])
} }
return buf return buf

View file

@ -20,16 +20,16 @@ func (s *Tombstone) StableMarshal(buf []byte) []byte {
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.StableSize()) buf = make([]byte, 0, s.StableSize())
} }
var offset int var offset int
offset += proto.UInt64Marshal(expFNum, buf[offset:], s.exp) buf = proto.UInt64Marshal(expFNum, buf[offset:], s.exp)
offset += proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID) buf = proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID)
for i := range s.members { for i := range s.members {
offset += proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i]) buf = proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i])
} }
return buf return buf

View file

@ -7,7 +7,6 @@ runtime function calls.
package proto package proto
import ( import (
"encoding/binary"
"math" "math"
"math/bits" "math/bits"
@ -21,7 +20,7 @@ type (
} }
) )
func BytesMarshal(field int, buf, v []byte) int { func BytesMarshal(field int, buf, v []byte) []byte {
return bytesMarshal(field, buf, v) return bytesMarshal(field, buf, v)
} }
@ -29,23 +28,30 @@ func BytesSize(field int, v []byte) int {
return bytesSize(field, v) return bytesSize(field, v)
} }
func bytesMarshal[T ~[]byte | ~string](field int, buf []byte, v T) int { func bytesMarshal(field int, buf []byte, v []byte) []byte {
if len(v) == 0 { if len(v) == 0 {
return 0 return buf
} }
return bytesMarshalNoCheck(field, buf, v) return bytesMarshalNoCheck(field, buf, v)
} }
func bytesMarshalNoCheck[T ~[]byte | ~string](field int, buf []byte, v T) int { func stringMarshal(field int, buf []byte, v string) []byte {
prefix := protowire.EncodeTag(protowire.Number(field), protowire.BytesType) if len(v) == 0 {
return buf
}
return stringMarshalNoCheck(field, buf, v)
}
// buf length check can prevent panic at PutUvarint, but it will make func stringMarshalNoCheck(field int, buf []byte, v string) []byte {
// marshaller a bit slower. buf = protowire.AppendTag(buf, protowire.Number(field), protowire.BytesType)
i := binary.PutUvarint(buf, uint64(prefix)) buf = protowire.AppendString(buf, v)
i += binary.PutUvarint(buf[i:], uint64(len(v))) return buf
i += copy(buf[i:], v) }
return i func bytesMarshalNoCheck(field int, buf []byte, v []byte) []byte {
buf = protowire.AppendTag(buf, protowire.Number(field), protowire.BytesType)
buf = protowire.AppendBytes(buf, v)
return buf
} }
func bytesSize[T ~[]byte | ~string](field int, v T) int { func bytesSize[T ~[]byte | ~string](field int, v T) int {
@ -59,28 +65,25 @@ func bytesSizeNoCheck[T ~[]byte | ~string](field int, v T) int {
return protowire.SizeGroup(protowire.Number(field), protowire.SizeBytes(len(v))) return protowire.SizeGroup(protowire.Number(field), protowire.SizeBytes(len(v)))
} }
func StringMarshal(field int, buf []byte, v string) int { func StringMarshal(field int, buf []byte, v string) []byte {
return bytesMarshal(field, buf, v) return stringMarshal(field, buf, v)
} }
func StringSize(field int, v string) int { func StringSize(field int, v string) int {
return bytesSize(field, v) return bytesSize(field, v)
} }
func BoolMarshal(field int, buf []byte, v bool) int { func BoolMarshal(field int, buf []byte, v bool) []byte {
if !v { if !v {
return 0 return buf
} }
prefix := protowire.EncodeTag(protowire.Number(field), protowire.VarintType)
// buf length check can prevent panic at PutUvarint, but it will make
// marshaller a bit slower.
i := binary.PutUvarint(buf, uint64(prefix))
const boolTrueValue = 0x1 const boolTrueValue = 0x1
buf[i] = boolTrueValue
return i + 1 buf = protowire.AppendTag(buf, protowire.Number(field), protowire.VarintType)
buf = protowire.AppendVarint(buf, boolTrueValue)
return buf
} }
func BoolSize(field int, v bool) int { func BoolSize(field int, v bool) int {
@ -91,19 +94,15 @@ func BoolSize(field int, v bool) int {
return protowire.SizeGroup(protowire.Number(field), boolLength) return protowire.SizeGroup(protowire.Number(field), boolLength)
} }
func UInt64Marshal(field int, buf []byte, v uint64) int { func UInt64Marshal(field int, buf []byte, v uint64) []byte {
if v == 0 { if v == 0 {
return 0 return buf
} }
prefix := protowire.EncodeTag(protowire.Number(field), protowire.VarintType) buf = protowire.AppendTag(buf, protowire.Number(field), protowire.VarintType)
buf = protowire.AppendVarint(buf, v)
// buf length check can prevent panic at PutUvarint, but it will make return buf
// marshaller a bit slower.
i := binary.PutUvarint(buf, uint64(prefix))
i += binary.PutUvarint(buf[i:], v)
return i
} }
func UInt64Size(field int, v uint64) int { func UInt64Size(field int, v uint64) int {
@ -113,7 +112,7 @@ func UInt64Size(field int, v uint64) int {
return protowire.SizeGroup(protowire.Number(field), protowire.SizeVarint(v)) return protowire.SizeGroup(protowire.Number(field), protowire.SizeVarint(v))
} }
func Int64Marshal(field int, buf []byte, v int64) int { func Int64Marshal(field int, buf []byte, v int64) []byte {
return UInt64Marshal(field, buf, uint64(v)) return UInt64Marshal(field, buf, uint64(v))
} }
@ -121,7 +120,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 { func UInt32Marshal(field int, buf []byte, v uint32) []byte {
return UInt64Marshal(field, buf, uint64(v)) return UInt64Marshal(field, buf, uint64(v))
} }
@ -129,7 +128,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 { func Int32Marshal(field int, buf []byte, v int32) []byte {
return UInt64Marshal(field, buf, uint64(v)) return UInt64Marshal(field, buf, uint64(v))
} }
@ -137,7 +136,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 { func EnumMarshal(field int, buf []byte, v int32) []byte {
return UInt64Marshal(field, buf, uint64(v)) return UInt64Marshal(field, buf, uint64(v))
} }
@ -145,14 +144,12 @@ 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 { func RepeatedBytesMarshal(field int, buf []byte, v [][]byte) []byte {
var offset int
for i := range v { for i := range v {
offset += bytesMarshalNoCheck(field, buf[offset:], v[i]) buf = bytesMarshalNoCheck(field, buf, v[i])
} }
return offset return buf
} }
func RepeatedBytesSize(field int, v [][]byte) (size int) { func RepeatedBytesSize(field int, v [][]byte) (size int) {
@ -163,14 +160,14 @@ func RepeatedBytesSize(field int, v [][]byte) (size int) {
return size return size
} }
func RepeatedStringMarshal(field int, buf []byte, v []string) int { func RepeatedStringMarshal(field int, buf []byte, v []string) []byte {
var offset int var offset int
for i := range v { for i := range v {
offset += bytesMarshalNoCheck(field, buf[offset:], v[i]) buf = stringMarshalNoCheck(field, buf[offset:], v[i])
} }
return offset return buf
} }
func RepeatedStringSize(field int, v []string) (size int) { func RepeatedStringSize(field int, v []string) (size int) {
@ -195,24 +192,23 @@ func repeatedUIntSize[T ~uint64 | ~int64 | ~uint32 | ~int32](field int, v []T) (
return return
} }
func repeatedUIntMarshal[T ~uint64 | ~int64 | ~uint32 | ~int32](field int, buf []byte, v []T) int { func repeatedUIntMarshal[T ~uint64 | ~int64 | ~uint32 | ~int32](field int, buf []byte, v []T) []byte {
if len(v) == 0 { if len(v) == 0 {
return 0 return buf
} }
prefix := protowire.EncodeTag(protowire.Number(field), protowire.BytesType) buf = protowire.AppendTag(buf, protowire.Number(field), protowire.BytesType)
offset := binary.PutUvarint(buf, uint64(prefix))
_, arrSize := repeatedUIntSize(field, v) _, arrSize := repeatedUIntSize(field, v)
offset += binary.PutUvarint(buf[offset:], uint64(arrSize)) buf = protowire.AppendVarint(buf, uint64(arrSize))
for i := range v { for i := range v {
offset += binary.PutUvarint(buf[offset:], uint64(v[i])) buf = protowire.AppendVarint(buf, uint64(v[i]))
} }
return offset return buf
} }
func RepeatedUInt64Marshal(field int, buf []byte, v []uint64) int { func RepeatedUInt64Marshal(field int, buf []byte, v []uint64) []byte {
return repeatedUIntMarshal(field, buf, v) return repeatedUIntMarshal(field, buf, v)
} }
@ -220,7 +216,7 @@ func RepeatedUInt64Size(field int, v []uint64) (size, arraySize int) {
return repeatedUIntSize(field, v) return repeatedUIntSize(field, v)
} }
func RepeatedInt64Marshal(field int, buf []byte, v []int64) int { func RepeatedInt64Marshal(field int, buf []byte, v []int64) []byte {
return repeatedUIntMarshal(field, buf, v) return repeatedUIntMarshal(field, buf, v)
} }
@ -228,7 +224,7 @@ func RepeatedInt64Size(field int, v []int64) (size, arraySize int) {
return repeatedUIntSize(field, v) return repeatedUIntSize(field, v)
} }
func RepeatedUInt32Marshal(field int, buf []byte, v []uint32) int { func RepeatedUInt32Marshal(field int, buf []byte, v []uint32) []byte {
return repeatedUIntMarshal(field, buf, v) return repeatedUIntMarshal(field, buf, v)
} }
@ -236,7 +232,7 @@ func RepeatedUInt32Size(field int, v []uint32) (size, arraySize int) {
return repeatedUIntSize(field, v) return repeatedUIntSize(field, v)
} }
func RepeatedInt32Marshal(field int, buf []byte, v []int32) int { func RepeatedInt32Marshal(field int, buf []byte, v []int32) []byte {
return repeatedUIntMarshal(field, buf, v) return repeatedUIntMarshal(field, buf, v)
} }
@ -249,18 +245,17 @@ func VarUIntSize(x uint64) int {
return (bits.Len64(x|1) + 6) / 7 return (bits.Len64(x|1) + 6) / 7
} }
func NestedStructureMarshal[T stableMarshaller](field int64, buf []byte, v T) int { func NestedStructureMarshal[T stableMarshaller](field int64, buf []byte, v T) []byte {
n := v.StableSize() n := v.StableSize()
if n == 0 { if n == 0 {
return 0 return buf
} }
prefix := protowire.EncodeTag(protowire.Number(field), protowire.BytesType) buf = protowire.AppendTag(buf, protowire.Number(field), protowire.BytesType)
offset := binary.PutUvarint(buf, prefix) buf = protowire.AppendVarint(buf, uint64(n))
offset += binary.PutUvarint(buf[offset:], uint64(n)) buf = v.StableMarshal(buf)
v.StableMarshal(buf[offset:])
return offset + n return buf
} }
func NestedStructureSize[T stableMarshaller](field int64, v T) (size int) { func NestedStructureSize[T stableMarshaller](field int64, v T) (size int) {
@ -272,19 +267,15 @@ func NestedStructureSize[T stableMarshaller](field int64, v T) (size int) {
return return
} }
func Fixed64Marshal(field int, buf []byte, v uint64) int { func Fixed64Marshal(field int, buf []byte, v uint64) []byte {
if v == 0 { if v == 0 {
return 0 return buf
} }
prefix := protowire.EncodeTag(protowire.Number(field), protowire.Fixed64Type) buf = protowire.AppendTag(buf, protowire.Number(field), protowire.Fixed64Type)
buf = protowire.AppendFixed64(buf, v)
// buf length check can prevent panic at PutUvarint, but it will make return buf
// marshaller a bit slower.
i := binary.PutUvarint(buf, uint64(prefix))
binary.LittleEndian.PutUint64(buf[i:], v)
return i + 8
} }
func Fixed64Size(fNum int, v uint64) int { func Fixed64Size(fNum int, v uint64) int {
@ -294,17 +285,15 @@ func Fixed64Size(fNum int, v uint64) int {
return protowire.SizeGroup(protowire.Number(fNum), protowire.SizeFixed64()) return protowire.SizeGroup(protowire.Number(fNum), protowire.SizeFixed64())
} }
func Float64Marshal(field int, buf []byte, v float64) int { func Float64Marshal(field int, buf []byte, v float64) []byte {
if v == 0 { if v == 0 {
return 0 return buf
} }
prefix := protowire.EncodeTag(protowire.Number(field), protowire.Fixed64Type) buf = protowire.AppendTag(buf, protowire.Number(field), protowire.Fixed64Type)
buf = protowire.AppendFixed64(buf, math.Float64bits(v))
i := binary.PutUvarint(buf, uint64(prefix)) return buf
binary.LittleEndian.PutUint64(buf[i:], math.Float64bits(v))
return i + 8
} }
func Float64Size(fNum int, v float64) int { func Float64Size(fNum int, v float64) int {
@ -318,19 +307,15 @@ func Float64Size(fNum int, v float64) int {
// and writes it to specified buffer. Returns number of bytes written. // and writes it to specified buffer. Returns number of bytes written.
// //
// Panics if the buffer is undersized. // Panics if the buffer is undersized.
func Fixed32Marshal(field int, buf []byte, v uint32) int { func Fixed32Marshal(field int, buf []byte, v uint32) []byte {
if v == 0 { if v == 0 {
return 0 return buf
} }
prefix := protowire.EncodeTag(protowire.Number(field), protowire.Fixed32Type) buf = protowire.AppendTag(buf, protowire.Number(field), protowire.Fixed32Type)
buf = protowire.AppendFixed32(buf, v)
// buf length check can prevent panic at PutUvarint, but it will make return buf
// marshaller a bit slower.
i := binary.PutUvarint(buf, uint64(prefix))
binary.LittleEndian.PutUint32(buf[i:], v)
return i + 4
} }
// Fixed32Size returns number of bytes required to encode uint32 value to Protocol Buffers fixed32 field // Fixed32Size returns number of bytes required to encode uint32 value to Protocol Buffers fixed32 field

View file

@ -47,7 +47,7 @@ func (s *stablePrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte, e
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.stableSize()) buf = make([]byte, 0, s.stableSize())
} }
var ( var (
@ -58,62 +58,62 @@ func (s *stablePrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte, e
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.BytesMarshal(fieldNum, buf, s.FieldA) buf = proto.BytesMarshal(fieldNum, buf, s.FieldA)
fieldNum = 2 fieldNum = 2
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.StringMarshal(fieldNum, buf, s.FieldB) buf = proto.StringMarshal(fieldNum, buf, s.FieldB)
fieldNum = 200 fieldNum = 200
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.BoolMarshal(fieldNum, buf, s.FieldC) buf = proto.BoolMarshal(fieldNum, buf, s.FieldC)
fieldNum = 201 fieldNum = 201
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.Int32Marshal(fieldNum, buf, s.FieldD) buf = proto.Int32Marshal(fieldNum, buf, s.FieldD)
fieldNum = 202 fieldNum = 202
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.UInt32Marshal(fieldNum, buf, s.FieldE) buf = proto.UInt32Marshal(fieldNum, buf, s.FieldE)
fieldNum = 203 fieldNum = 203
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.Int64Marshal(fieldNum, buf, s.FieldF) buf = proto.Int64Marshal(fieldNum, buf, s.FieldF)
fieldNum = 204 fieldNum = 204
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.UInt64Marshal(fieldNum, buf, s.FieldG) buf = proto.UInt64Marshal(fieldNum, buf, s.FieldG)
fieldNum = 205 fieldNum = 205
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.Fixed64Marshal(fieldNum, buf, s.FieldI) buf = proto.Fixed64Marshal(fieldNum, buf, s.FieldI)
fieldNum = 206 fieldNum = 206
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.Float64Marshal(fieldNum, buf, s.FieldJ) buf = proto.Float64Marshal(fieldNum, buf, s.FieldJ)
fieldNum = 207 fieldNum = 207
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
offset = proto.Fixed32Marshal(fieldNum, buf, s.FieldK) buf = proto.Fixed32Marshal(fieldNum, buf, s.FieldK)
i += offset i += offset
@ -121,7 +121,7 @@ func (s *stablePrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte, e
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.EnumMarshal(fieldNum, buf, int32(s.FieldH)) buf = proto.EnumMarshal(fieldNum, buf, int32(s.FieldH))
return buf, nil return buf, nil
} }
@ -146,46 +146,46 @@ func (s *stableRepPrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.stableSize()) buf = make([]byte, 0, s.stableSize())
} }
var i, fieldNum int var fieldNum int
fieldNum = 1 fieldNum = 1
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.RepeatedBytesMarshal(fieldNum, buf, s.FieldA) buf = proto.RepeatedBytesMarshal(fieldNum, buf, s.FieldA)
fieldNum = 2 fieldNum = 2
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.RepeatedStringMarshal(fieldNum, buf, s.FieldB) buf = proto.RepeatedStringMarshal(fieldNum, buf, s.FieldB)
fieldNum = 3 fieldNum = 3
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.RepeatedInt32Marshal(fieldNum, buf, s.FieldC) buf = proto.RepeatedInt32Marshal(fieldNum, buf, s.FieldC)
fieldNum = 4 fieldNum = 4
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.RepeatedUInt32Marshal(fieldNum, buf, s.FieldD) buf = proto.RepeatedUInt32Marshal(fieldNum, buf, s.FieldD)
fieldNum = 5 fieldNum = 5
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.RepeatedInt64Marshal(fieldNum, buf, s.FieldE) buf = proto.RepeatedInt64Marshal(fieldNum, buf, s.FieldE)
fieldNum = 6 fieldNum = 6
if wrongField { if wrongField {
fieldNum++ fieldNum++
} }
i += proto.RepeatedUInt64Marshal(fieldNum, buf, s.FieldF) buf = proto.RepeatedUInt64Marshal(fieldNum, buf, s.FieldF)
return buf, nil return buf, nil
} }