*: remove error from StableMarshal return values

We marshal only in-memory structures, no error is expected.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-04-05 11:24:34 +03:00 committed by LeL
parent 84d981e88e
commit 94f068e462
17 changed files with 504 additions and 1358 deletions

View file

@ -15,9 +15,9 @@ const (
balanceRespBodyDecimalField = 1 balanceRespBodyDecimalField = 1
) )
func (d *Decimal) StableMarshal(buf []byte) ([]byte, error) { func (d *Decimal) StableMarshal(buf []byte) []byte {
if d == nil { if d == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -29,7 +29,7 @@ func (d *Decimal) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val) offset += protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val)
protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec) protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec)
return buf, nil return buf
} }
func (d *Decimal) StableSize() (size int) { func (d *Decimal) StableSize() (size int) {
@ -47,21 +47,18 @@ func (d *Decimal) Unmarshal(data []byte) error {
return message.Unmarshal(d, data, new(accounting.Decimal)) return message.Unmarshal(d, data, new(accounting.Decimal))
} }
func (b *BalanceRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (b *BalanceRequestBody) StableMarshal(buf []byte) []byte {
if b == nil { if b == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, b.StableSize()) buf = make([]byte, b.StableSize())
} }
_, err := protoutil.NestedStructureMarshal(balanceReqBodyOwnerField, buf, b.ownerID) protoutil.NestedStructureMarshal(balanceReqBodyOwnerField, buf, b.ownerID)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (b *BalanceRequestBody) StableSize() (size int) { func (b *BalanceRequestBody) StableSize() (size int) {
@ -78,21 +75,18 @@ func (b *BalanceRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(b, data, new(accounting.BalanceRequest_Body)) return message.Unmarshal(b, data, new(accounting.BalanceRequest_Body))
} }
func (br *BalanceResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (br *BalanceResponseBody) StableMarshal(buf []byte) []byte {
if br == nil { if br == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, br.StableSize()) buf = make([]byte, br.StableSize())
} }
_, err := protoutil.NestedStructureMarshal(balanceRespBodyDecimalField, buf, br.bal) protoutil.NestedStructureMarshal(balanceRespBodyDecimalField, buf, br.bal)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (br *BalanceResponseBody) StableSize() (size int) { func (br *BalanceResponseBody) StableSize() (size int) {

View file

@ -38,44 +38,25 @@ const (
// StableMarshal marshals unified acl table structure in a protobuf // StableMarshal marshals unified acl table structure in a protobuf
// compatible way without field order shuffle. // compatible way without field order shuffle.
func (t *Table) StableMarshal(buf []byte) ([]byte, error) { func (t *Table) StableMarshal(buf []byte) []byte {
if t == nil { if t == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, t.StableSize()) buf = make([]byte, t.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(tableVersionField, buf[offset:], t.version) offset += protoutil.NestedStructureMarshal(tableVersionField, buf[offset:], t.version)
if err != nil { offset += protoutil.NestedStructureMarshal(tableContainerIDField, buf[offset:], t.cid)
return nil, err
}
offset += n
n, err = protoutil.NestedStructureMarshal(tableContainerIDField, buf[offset:], t.cid)
if err != nil {
return nil, err
}
offset += n
for i := range t.records { for i := range t.records {
n, err = protoutil.NestedStructureMarshal(tableRecordsField, buf[offset:], &t.records[i]) offset += protoutil.NestedStructureMarshal(tableRecordsField, buf[offset:], &t.records[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
// StableSize of acl table structure marshalled by StableMarshal function. // StableSize of acl table structure marshalled by StableMarshal function.
@ -100,42 +81,29 @@ func (t *Table) Unmarshal(data []byte) error {
// StableMarshal marshals unified acl record structure in a protobuf // StableMarshal marshals unified acl record structure in a protobuf
// compatible way without field order shuffle. // compatible way without field order shuffle.
func (r *Record) StableMarshal(buf []byte) ([]byte, error) { func (r *Record) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += protoutil.EnumMarshal(recordOperationField, buf[offset:], int32(r.op)) offset += protoutil.EnumMarshal(recordOperationField, buf[offset:], int32(r.op))
offset += protoutil.EnumMarshal(recordActionField, buf[offset:], int32(r.action)) offset += protoutil.EnumMarshal(recordActionField, buf[offset:], int32(r.action))
for i := range r.filters { for i := range r.filters {
n, err = protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i]) offset += protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i])
if err != nil {
return nil, err
}
offset += n
} }
for i := range r.targets { for i := range r.targets {
n, err = protoutil.NestedStructureMarshal(recordTargetsField, buf[offset:], &r.targets[i]) offset += protoutil.NestedStructureMarshal(recordTargetsField, buf[offset:], &r.targets[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
// StableSize of acl record structure marshalled by StableMarshal function. // StableSize of acl record structure marshalled by StableMarshal function.
@ -164,9 +132,9 @@ func (r *Record) Unmarshal(data []byte) error {
// StableMarshal marshals unified header filter structure in a protobuf // StableMarshal marshals unified header filter structure in a protobuf
// compatible way without field order shuffle. // compatible way without field order shuffle.
func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) { func (f *HeaderFilter) StableMarshal(buf []byte) []byte {
if f == nil { if f == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -180,7 +148,7 @@ func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.StringMarshal(filterNameField, buf[offset:], f.key) offset += protoutil.StringMarshal(filterNameField, buf[offset:], f.key)
protoutil.StringMarshal(filterValueField, buf[offset:], f.value) protoutil.StringMarshal(filterValueField, buf[offset:], f.value)
return buf, nil return buf
} }
// StableSize of header filter structure marshalled by StableMarshal function. // StableSize of header filter structure marshalled by StableMarshal function.
@ -203,9 +171,9 @@ func (f *HeaderFilter) Unmarshal(data []byte) error {
// StableMarshal marshals unified role info structure in a protobuf // StableMarshal marshals unified role info structure in a protobuf
// compatible way without field order shuffle. // compatible way without field order shuffle.
func (t *Target) StableMarshal(buf []byte) ([]byte, error) { func (t *Target) StableMarshal(buf []byte) []byte {
if t == nil { if t == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -217,7 +185,7 @@ func (t *Target) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.EnumMarshal(targetTypeField, buf[offset:], int32(t.role)) offset += protoutil.EnumMarshal(targetTypeField, buf[offset:], int32(t.role))
protoutil.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys) protoutil.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys)
return buf, nil return buf
} }
// StableSize of role info structure marshalled by StableMarshal function. // StableSize of role info structure marshalled by StableMarshal function.
@ -236,9 +204,9 @@ func (t *Target) Unmarshal(data []byte) error {
return message.Unmarshal(t, data, new(acl.EACLRecord_Target)) return message.Unmarshal(t, data, new(acl.EACLRecord_Target))
} }
func (l *TokenLifetime) StableMarshal(buf []byte) ([]byte, error) { func (l *TokenLifetime) StableMarshal(buf []byte) []byte {
if l == nil { if l == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -251,7 +219,7 @@ func (l *TokenLifetime) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf) offset += protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
protoutil.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat) protoutil.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
return buf, nil return buf
} }
func (l *TokenLifetime) StableSize() (size int) { func (l *TokenLifetime) StableSize() (size int) {
@ -270,40 +238,22 @@ func (l *TokenLifetime) Unmarshal(data []byte) error {
return message.Unmarshal(l, data, new(acl.BearerToken_Body_TokenLifetime)) return message.Unmarshal(l, data, new(acl.BearerToken_Body_TokenLifetime))
} }
func (bt *BearerTokenBody) StableMarshal(buf []byte) ([]byte, error) { func (bt *BearerTokenBody) StableMarshal(buf []byte) []byte {
if bt == nil { if bt == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, bt.StableSize()) buf = make([]byte, bt.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(bearerTokenBodyACLField, buf[offset:], bt.eacl) offset += protoutil.NestedStructureMarshal(bearerTokenBodyACLField, buf[offset:], bt.eacl)
if err != nil { offset += protoutil.NestedStructureMarshal(bearerTokenBodyOwnerField, buf[offset:], bt.ownerID)
return nil, err protoutil.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf[offset:], bt.lifetime)
}
offset += n return buf
n, err = protoutil.NestedStructureMarshal(bearerTokenBodyOwnerField, buf[offset:], bt.ownerID)
if err != nil {
return nil, err
}
offset += n
_, err = protoutil.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf[offset:], bt.lifetime)
if err != nil {
return nil, err
}
return buf, nil
} }
func (bt *BearerTokenBody) StableSize() (size int) { func (bt *BearerTokenBody) StableSize() (size int) {
@ -322,33 +272,21 @@ func (bt *BearerTokenBody) Unmarshal(data []byte) error {
return message.Unmarshal(bt, data, new(acl.BearerToken_Body)) return message.Unmarshal(bt, data, new(acl.BearerToken_Body))
} }
func (bt *BearerToken) StableMarshal(buf []byte) ([]byte, error) { func (bt *BearerToken) StableMarshal(buf []byte) []byte {
if bt == nil { if bt == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, bt.StableSize()) buf = make([]byte, bt.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(bearerTokenBodyField, buf[offset:], bt.body) offset += protoutil.NestedStructureMarshal(bearerTokenBodyField, buf[offset:], bt.body)
if err != nil { protoutil.NestedStructureMarshal(bearerTokenSignatureField, buf[offset:], bt.sig)
return nil, err
}
offset += n return buf
_, err = protoutil.NestedStructureMarshal(bearerTokenSignatureField, buf[offset:], bt.sig)
if err != nil {
return nil, err
}
return buf, nil
} }
func (bt *BearerToken) StableSize() (size int) { func (bt *BearerToken) StableSize() (size int) {

View file

@ -27,62 +27,33 @@ const (
// StableMarshal marshals unified DataAuditResult structure into a protobuf // StableMarshal marshals unified DataAuditResult structure into a protobuf
// binary format without field order shuffle. // binary format without field order shuffle.
func (a *DataAuditResult) StableMarshal(buf []byte) ([]byte, error) { func (a *DataAuditResult) StableMarshal(buf []byte) []byte {
if a == nil { if a == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, a.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(versionFNum, buf[offset:], a.version)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(versionFNum, buf[offset:], a.version)
offset += proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch) offset += proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch)
offset += proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid)
n, err = proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid)
if err != nil {
return nil, err
}
offset += n
offset += proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey) offset += proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey)
offset += proto.BoolMarshal(completeFNum, buf[offset:], a.complete) offset += proto.BoolMarshal(completeFNum, buf[offset:], a.complete)
offset += proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests) offset += proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests)
offset += proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries) offset += proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries)
offset += refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG)
n, err = refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG) offset += refs.ObjectIDNestedListMarshal(failSGFNum, buf[offset:], a.failSG)
if err != nil {
return nil, err
}
offset += n
n, err = refs.ObjectIDNestedListMarshal(failSGFNum, buf[offset:], a.failSG)
if err != nil {
return nil, err
}
offset += n
offset += proto.UInt32Marshal(hitFNum, buf[offset:], a.hit) offset += proto.UInt32Marshal(hitFNum, buf[offset:], a.hit)
offset += proto.UInt32Marshal(missFNum, buf[offset:], a.miss) offset += proto.UInt32Marshal(missFNum, buf[offset:], a.miss)
offset += proto.UInt32Marshal(failFNum, buf[offset:], a.fail) offset += proto.UInt32Marshal(failFNum, buf[offset:], a.fail)
offset += proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes) offset += proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes)
proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes) proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes)
return buf, nil return buf
} }
// StableSize returns byte length of DataAuditResult structure // StableSize returns byte length of DataAuditResult structure

View file

@ -51,9 +51,9 @@ const (
usedSpaceReqBodyAnnouncementsField = 1 usedSpaceReqBodyAnnouncementsField = 1
) )
func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) { func (a *Attribute) StableMarshal(buf []byte) []byte {
if a == nil { if a == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -65,7 +65,7 @@ func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key) offset += protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key)
protoutil.StringMarshal(attributeValueField, buf[offset:], a.val) protoutil.StringMarshal(attributeValueField, buf[offset:], a.val)
return buf, nil return buf
} }
func (a *Attribute) StableSize() (size int) { func (a *Attribute) StableSize() (size int) {
@ -83,52 +83,29 @@ func (a *Attribute) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(container.Container_Attribute)) return message.Unmarshal(a, data, new(container.Container_Attribute))
} }
func (c *Container) StableMarshal(buf []byte) ([]byte, error) { func (c *Container) StableMarshal(buf []byte) []byte {
if c == nil { if c == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, c.StableSize()) buf = make([]byte, c.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(containerVersionField, buf[offset:], c.version)
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.NestedStructureMarshal(containerOwnerField, buf[offset:], c.ownerID)
if err != nil {
return nil, err
}
offset += n
offset += protoutil.NestedStructureMarshal(containerVersionField, buf[offset:], c.version)
offset += protoutil.NestedStructureMarshal(containerOwnerField, buf[offset:], c.ownerID)
offset += protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce) offset += protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce)
offset += protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL) offset += protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL)
for i := range c.attr { for i := range c.attr {
n, err = protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i]) offset += protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i])
if err != nil {
return nil, err
}
offset += n
} }
_, err = protoutil.NestedStructureMarshal(containerPlacementField, buf[offset:], c.policy) protoutil.NestedStructureMarshal(containerPlacementField, buf[offset:], c.policy)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (c *Container) StableSize() (size int) { func (c *Container) StableSize() (size int) {
@ -154,33 +131,21 @@ func (c *Container) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(container.Container)) return message.Unmarshal(c, data, new(container.Container))
} }
func (r *PutRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *PutRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(putReqBodyContainerField, buf[offset:], r.cnr) offset += protoutil.NestedStructureMarshal(putReqBodyContainerField, buf[offset:], r.cnr)
if err != nil { protoutil.NestedStructureMarshal(putReqBodySignatureField, buf[offset:], r.sig)
return nil, err
}
offset += n return buf
_, err = protoutil.NestedStructureMarshal(putReqBodySignatureField, buf[offset:], r.sig)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *PutRequestBody) StableSize() (size int) { func (r *PutRequestBody) StableSize() (size int) {
@ -198,25 +163,18 @@ func (r *PutRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.PutRequest_Body)) return message.Unmarshal(r, data, new(container.PutRequest_Body))
} }
func (r *PutResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *PutResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( protoutil.NestedStructureMarshal(putRespBodyIDField, buf, r.cid)
err error
)
_, err = protoutil.NestedStructureMarshal(putRespBodyIDField, buf, r.cid) return buf
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *PutResponseBody) StableSize() (size int) { func (r *PutResponseBody) StableSize() (size int) {
@ -233,33 +191,21 @@ func (r *PutResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.PutResponse_Body)) return message.Unmarshal(r, data, new(container.PutResponse_Body))
} }
func (r *DeleteRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *DeleteRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(deleteReqBodyIDField, buf[offset:], r.cid) offset += protoutil.NestedStructureMarshal(deleteReqBodyIDField, buf[offset:], r.cid)
if err != nil { protoutil.NestedStructureMarshal(deleteReqBodySignatureField, buf[offset:], r.sig)
return nil, err
}
offset += n return buf
_, err = protoutil.NestedStructureMarshal(deleteReqBodySignatureField, buf[offset:], r.sig)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *DeleteRequestBody) StableSize() (size int) { func (r *DeleteRequestBody) StableSize() (size int) {
@ -277,8 +223,8 @@ func (r *DeleteRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.DeleteRequest_Body)) return message.Unmarshal(r, data, new(container.DeleteRequest_Body))
} }
func (r *DeleteResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *DeleteResponseBody) StableMarshal(buf []byte) []byte {
return nil, nil return nil
} }
func (r *DeleteResponseBody) StableSize() (size int) { func (r *DeleteResponseBody) StableSize() (size int) {
@ -289,21 +235,18 @@ func (r *DeleteResponseBody) Unmarshal([]byte) error {
return nil return nil
} }
func (r *GetRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
_, err := protoutil.NestedStructureMarshal(getReqBodyIDField, buf, r.cid) protoutil.NestedStructureMarshal(getReqBodyIDField, buf, r.cid)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (r *GetRequestBody) StableSize() (size int) { func (r *GetRequestBody) StableSize() (size int) {
@ -320,31 +263,22 @@ func (r *GetRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.GetRequest_Body)) return message.Unmarshal(r, data, new(container.GetRequest_Body))
} }
func (r *GetResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
offset, err := protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr) var offset int
if err != nil {
return nil, err
}
n, err := protoutil.NestedStructureMarshal(getRespBodySignatureField, buf[offset:], r.sig) offset += protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr)
if err != nil { offset += protoutil.NestedStructureMarshal(getRespBodySignatureField, buf[offset:], r.sig)
return nil, err protoutil.NestedStructureMarshal(getRespBodyTokenField, buf[offset:], r.token)
}
_, err = protoutil.NestedStructureMarshal(getRespBodyTokenField, buf[offset+n:], r.token) return buf
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *GetResponseBody) StableSize() (size int) { func (r *GetResponseBody) StableSize() (size int) {
@ -363,21 +297,18 @@ func (r *GetResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.GetResponse_Body)) return message.Unmarshal(r, data, new(container.GetResponse_Body))
} }
func (r *ListRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *ListRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
_, err := protoutil.NestedStructureMarshal(listReqBodyOwnerField, buf, r.ownerID) protoutil.NestedStructureMarshal(listReqBodyOwnerField, buf, r.ownerID)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (r *ListRequestBody) StableSize() (size int) { func (r *ListRequestBody) StableSize() (size int) {
@ -394,30 +325,22 @@ func (r *ListRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.ListRequest_Body)) return message.Unmarshal(r, data, new(container.ListRequest_Body))
} }
func (r *ListResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *ListResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
n, offset int
err error
)
for i := range r.cidList { for i := range r.cidList {
n, err = protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], &r.cidList[i]) offset += protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], &r.cidList[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
func (r *ListResponseBody) StableSize() (size int) { func (r *ListResponseBody) StableSize() (size int) {
@ -436,33 +359,21 @@ func (r *ListResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.ListResponse_Body)) return message.Unmarshal(r, data, new(container.ListResponse_Body))
} }
func (r *SetExtendedACLRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *SetExtendedACLRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(setEACLReqBodyTableField, buf[offset:], r.eacl) offset += protoutil.NestedStructureMarshal(setEACLReqBodyTableField, buf[offset:], r.eacl)
if err != nil { protoutil.NestedStructureMarshal(setEACLReqBodySignatureField, buf[offset:], r.sig)
return nil, err
}
offset += n return buf
_, err = protoutil.NestedStructureMarshal(setEACLReqBodySignatureField, buf[offset:], r.sig)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *SetExtendedACLRequestBody) StableSize() (size int) { func (r *SetExtendedACLRequestBody) StableSize() (size int) {
@ -480,8 +391,8 @@ func (r *SetExtendedACLRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.SetExtendedACLRequest_Body)) return message.Unmarshal(r, data, new(container.SetExtendedACLRequest_Body))
} }
func (r *SetExtendedACLResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *SetExtendedACLResponseBody) StableMarshal(buf []byte) []byte {
return nil, nil return nil
} }
func (r *SetExtendedACLResponseBody) StableSize() (size int) { func (r *SetExtendedACLResponseBody) StableSize() (size int) {
@ -492,21 +403,18 @@ func (r *SetExtendedACLResponseBody) Unmarshal([]byte) error {
return nil return nil
} }
func (r *GetExtendedACLRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetExtendedACLRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
_, err := protoutil.NestedStructureMarshal(getEACLReqBodyIDField, buf, r.cid) protoutil.NestedStructureMarshal(getEACLReqBodyIDField, buf, r.cid)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (r *GetExtendedACLRequestBody) StableSize() (size int) { func (r *GetExtendedACLRequestBody) StableSize() (size int) {
@ -523,40 +431,22 @@ func (r *GetExtendedACLRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.GetExtendedACLRequest_Body)) return message.Unmarshal(r, data, new(container.GetExtendedACLRequest_Body))
} }
func (r *GetExtendedACLResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetExtendedACLResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(getEACLRespBodyTableField, buf[offset:], r.eacl) offset += protoutil.NestedStructureMarshal(getEACLRespBodyTableField, buf[offset:], r.eacl)
if err != nil { offset += protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig)
return nil, err protoutil.NestedStructureMarshal(getEACLRespBodyTokenField, buf[offset:], r.token)
}
offset += n return buf
n, err = protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig)
if err != nil {
return nil, err
}
offset += n
_, err = protoutil.NestedStructureMarshal(getEACLRespBodyTokenField, buf[offset:], r.token)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *GetExtendedACLResponseBody) StableSize() (size int) { func (r *GetExtendedACLResponseBody) StableSize() (size int) {
@ -575,32 +465,22 @@ func (r *GetExtendedACLResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.GetExtendedACLResponse_Body)) return message.Unmarshal(r, data, new(container.GetExtendedACLResponse_Body))
} }
func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) ([]byte, error) { func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) []byte {
if a == nil { if a == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, a.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch) offset += protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch)
offset += protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid)
n, err = protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid)
if err != nil {
return nil, err
}
offset += n
protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf[offset:], a.usedSpace) protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf[offset:], a.usedSpace)
return buf, nil return buf
} }
func (a *UsedSpaceAnnouncement) StableSize() (size int) { func (a *UsedSpaceAnnouncement) StableSize() (size int) {
@ -619,30 +499,22 @@ func (a *UsedSpaceAnnouncement) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(container.AnnounceUsedSpaceRequest_Body_Announcement)) return message.Unmarshal(a, data, new(container.AnnounceUsedSpaceRequest_Body_Announcement))
} }
func (r *AnnounceUsedSpaceRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *AnnounceUsedSpaceRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
for i := range r.announcements { for i := range r.announcements {
n, err = protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf[offset:], &r.announcements[i]) offset += protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf[offset:], &r.announcements[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
func (r *AnnounceUsedSpaceRequestBody) StableSize() (size int) { func (r *AnnounceUsedSpaceRequestBody) StableSize() (size int) {
@ -661,8 +533,8 @@ func (r *AnnounceUsedSpaceRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.AnnounceUsedSpaceRequest_Body)) return message.Unmarshal(r, data, new(container.AnnounceUsedSpaceRequest_Body))
} }
func (r *AnnounceUsedSpaceResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *AnnounceUsedSpaceResponseBody) StableMarshal(buf []byte) []byte {
return nil, nil return nil
} }
func (r *AnnounceUsedSpaceResponseBody) StableSize() (size int) { func (r *AnnounceUsedSpaceResponseBody) StableSize() (size int) {

View file

@ -41,19 +41,16 @@ const (
nodeInfoResponseBodyField = 2 nodeInfoResponseBodyField = 2
) )
func (f *Filter) StableMarshal(buf []byte) ([]byte, error) { func (f *Filter) StableMarshal(buf []byte) []byte {
if f == nil { if f == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, f.StableSize()) buf = make([]byte, f.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += protoutil.StringMarshal(nameFilterField, buf[offset:], f.name) offset += protoutil.StringMarshal(nameFilterField, buf[offset:], f.name)
offset += protoutil.StringMarshal(keyFilterField, buf[offset:], f.key) offset += protoutil.StringMarshal(keyFilterField, buf[offset:], f.key)
@ -61,15 +58,10 @@ func (f *Filter) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.StringMarshal(valueFilterField, buf[offset:], f.value) offset += protoutil.StringMarshal(valueFilterField, buf[offset:], f.value)
for i := range f.filters { for i := range f.filters {
n, err = protoutil.NestedStructureMarshal(filtersFilterField, buf[offset:], &f.filters[i]) offset += protoutil.NestedStructureMarshal(filtersFilterField, buf[offset:], &f.filters[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
func (f *Filter) StableSize() (size int) { func (f *Filter) StableSize() (size int) {
@ -88,9 +80,9 @@ func (f *Filter) Unmarshal(data []byte) error {
return message.Unmarshal(f, data, new(netmap.Filter)) return message.Unmarshal(f, data, new(netmap.Filter))
} }
func (s *Selector) StableMarshal(buf []byte) ([]byte, error) { func (s *Selector) StableMarshal(buf []byte) []byte {
if s == nil { if s == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -105,7 +97,7 @@ func (s *Selector) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.StringMarshal(attributeSelectorField, buf[offset:], s.attribute) offset += protoutil.StringMarshal(attributeSelectorField, buf[offset:], s.attribute)
protoutil.StringMarshal(filterSelectorField, buf[offset:], s.filter) protoutil.StringMarshal(filterSelectorField, buf[offset:], s.filter)
return buf, nil return buf
} }
func (s *Selector) StableSize() (size int) { func (s *Selector) StableSize() (size int) {
@ -122,9 +114,9 @@ func (s *Selector) Unmarshal(data []byte) error {
return message.Unmarshal(s, data, new(netmap.Selector)) return message.Unmarshal(s, data, new(netmap.Selector))
} }
func (r *Replica) StableMarshal(buf []byte) ([]byte, error) { func (r *Replica) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -136,7 +128,7 @@ func (r *Replica) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count) offset += protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count)
protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector) protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector)
return buf, nil return buf
} }
func (r *Replica) StableSize() (size int) { func (r *Replica) StableSize() (size int) {
@ -150,55 +142,34 @@ func (r *Replica) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(netmap.Replica)) return message.Unmarshal(r, data, new(netmap.Replica))
} }
func (p *PlacementPolicy) StableMarshal(buf []byte) ([]byte, error) { func (p *PlacementPolicy) StableMarshal(buf []byte) []byte {
if p == nil { if p == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, p.StableSize()) buf = make([]byte, p.StableSize())
} }
var ( var offset int
offset, n int
err error
)
for i := range p.replicas { for i := range p.replicas {
n, err = protoutil.NestedStructureMarshal(replicasPolicyField, buf[offset:], &p.replicas[i]) offset += protoutil.NestedStructureMarshal(replicasPolicyField, buf[offset:], &p.replicas[i])
if err != nil {
return nil, err
}
offset += n
} }
offset += protoutil.UInt32Marshal(backupPolicyField, buf[offset:], p.backupFactor) offset += protoutil.UInt32Marshal(backupPolicyField, buf[offset:], p.backupFactor)
for i := range p.selectors { for i := range p.selectors {
n, err = protoutil.NestedStructureMarshal(selectorsPolicyField, buf[offset:], &p.selectors[i]) offset += protoutil.NestedStructureMarshal(selectorsPolicyField, buf[offset:], &p.selectors[i])
if err != nil {
return nil, err
}
offset += n
} }
for i := range p.filters { for i := range p.filters {
n, err = protoutil.NestedStructureMarshal(filtersPolicyField, buf[offset:], &p.filters[i]) offset += protoutil.NestedStructureMarshal(filtersPolicyField, buf[offset:], &p.filters[i])
if err != nil {
return nil, err
}
offset += n
} }
_, err = protoutil.NestedStructureMarshal(subnetIDPolicyField, buf[offset:], p.subnetID) protoutil.NestedStructureMarshal(subnetIDPolicyField, buf[offset:], p.subnetID)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (p *PlacementPolicy) StableSize() (size int) { func (p *PlacementPolicy) StableSize() (size int) {
@ -225,9 +196,9 @@ func (p *PlacementPolicy) Unmarshal(data []byte) error {
return message.Unmarshal(p, data, new(netmap.PlacementPolicy)) return message.Unmarshal(p, data, new(netmap.PlacementPolicy))
} }
func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) { func (a *Attribute) StableMarshal(buf []byte) []byte {
if a == nil { if a == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -243,7 +214,7 @@ func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.StringMarshal(parentsAttributeField, buf[offset:], a.parents[i]) offset += protoutil.StringMarshal(parentsAttributeField, buf[offset:], a.parents[i])
} }
return buf, nil return buf
} }
func (a *Attribute) StableSize() (size int) { func (a *Attribute) StableSize() (size int) {
@ -265,35 +236,27 @@ func (a *Attribute) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(netmap.NodeInfo_Attribute)) return message.Unmarshal(a, data, new(netmap.NodeInfo_Attribute))
} }
func (ni *NodeInfo) StableMarshal(buf []byte) ([]byte, error) { func (ni *NodeInfo) StableMarshal(buf []byte) []byte {
if ni == nil { if ni == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, ni.StableSize()) buf = make([]byte, ni.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += protoutil.BytesMarshal(keyNodeInfoField, buf[offset:], ni.publicKey) offset += protoutil.BytesMarshal(keyNodeInfoField, buf[offset:], ni.publicKey)
offset += protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses) offset += protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses)
for i := range ni.attributes { for i := range ni.attributes {
n, err = protoutil.NestedStructureMarshal(attributesNodeInfoField, buf[offset:], &ni.attributes[i]) offset += protoutil.NestedStructureMarshal(attributesNodeInfoField, buf[offset:], &ni.attributes[i])
if err != nil {
return nil, err
}
offset += n
} }
protoutil.EnumMarshal(stateNodeInfoField, buf[offset:], int32(ni.state)) protoutil.EnumMarshal(stateNodeInfoField, buf[offset:], int32(ni.state))
return buf, nil return buf
} }
func (ni *NodeInfo) StableSize() (size int) { func (ni *NodeInfo) StableSize() (size int) {
@ -317,8 +280,8 @@ func (ni *NodeInfo) Unmarshal(data []byte) error {
return message.Unmarshal(ni, data, new(netmap.NodeInfo)) return message.Unmarshal(ni, data, new(netmap.NodeInfo))
} }
func (l *LocalNodeInfoRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (l *LocalNodeInfoRequestBody) StableMarshal(buf []byte) []byte {
return nil, nil return nil
} }
func (l *LocalNodeInfoRequestBody) StableSize() (size int) { func (l *LocalNodeInfoRequestBody) StableSize() (size int) {
@ -329,33 +292,21 @@ func (l *LocalNodeInfoRequestBody) Unmarshal([]byte) error {
return nil return nil
} }
func (l *LocalNodeInfoResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (l *LocalNodeInfoResponseBody) StableMarshal(buf []byte) []byte {
if l == nil { if l == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, l.StableSize()) buf = make([]byte, l.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(versionInfoResponseBodyField, buf[offset:], l.version) offset += protoutil.NestedStructureMarshal(versionInfoResponseBodyField, buf[offset:], l.version)
if err != nil { protoutil.NestedStructureMarshal(nodeInfoResponseBodyField, buf[offset:], l.nodeInfo)
return nil, err
}
offset += n return buf
_, err = protoutil.NestedStructureMarshal(nodeInfoResponseBodyField, buf[offset:], l.nodeInfo)
if err != nil {
return nil, err
}
return buf, nil
} }
func (l *LocalNodeInfoResponseBody) StableSize() (size int) { func (l *LocalNodeInfoResponseBody) StableSize() (size int) {
@ -379,9 +330,9 @@ const (
netPrmValFNum netPrmValFNum
) )
func (x *NetworkParameter) StableMarshal(buf []byte) ([]byte, error) { func (x *NetworkParameter) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -393,7 +344,7 @@ func (x *NetworkParameter) StableMarshal(buf []byte) ([]byte, error) {
offset += protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k) offset += protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k)
protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v) protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v)
return buf, nil return buf
} }
func (x *NetworkParameter) StableSize() (size int) { func (x *NetworkParameter) StableSize() (size int) {
@ -412,30 +363,22 @@ const (
netCfgPrmsFNum netCfgPrmsFNum
) )
func (x *NetworkConfig) StableMarshal(buf []byte) ([]byte, error) { func (x *NetworkConfig) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
for i := range x.ps { for i := range x.ps {
n, err = protoutil.NestedStructureMarshal(netCfgPrmsFNum, buf[offset:], &x.ps[i]) offset += protoutil.NestedStructureMarshal(netCfgPrmsFNum, buf[offset:], &x.ps[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
func (x *NetworkConfig) StableSize() (size int) { func (x *NetworkConfig) StableSize() (size int) {
@ -458,30 +401,23 @@ const (
netInfoCfgFNum netInfoCfgFNum
) )
func (i *NetworkInfo) StableMarshal(buf []byte) ([]byte, error) { func (i *NetworkInfo) StableMarshal(buf []byte) []byte {
if i == nil { if i == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, i.StableSize()) buf = make([]byte, i.StableSize())
} }
var ( var offset int
offset int
err error
)
offset += protoutil.UInt64Marshal(netInfoCurEpochFNum, buf[offset:], i.curEpoch) offset += protoutil.UInt64Marshal(netInfoCurEpochFNum, buf[offset:], i.curEpoch)
offset += protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum) offset += protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum)
offset += protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock) offset += protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock)
protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg)
_, err = protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg) return buf
if err != nil {
return nil, err
}
return buf, nil
} }
func (i *NetworkInfo) StableSize() (size int) { func (i *NetworkInfo) StableSize() (size int) {
@ -501,8 +437,8 @@ func (i *NetworkInfo) Unmarshal(data []byte) error {
return message.Unmarshal(i, data, new(netmap.NetworkInfo)) return message.Unmarshal(i, data, new(netmap.NetworkInfo))
} }
func (l *NetworkInfoRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (l *NetworkInfoRequestBody) StableMarshal(buf []byte) []byte {
return nil, nil return nil
} }
func (l *NetworkInfoRequestBody) StableSize() (size int) { func (l *NetworkInfoRequestBody) StableSize() (size int) {
@ -518,21 +454,18 @@ const (
netInfoRespBodyNetInfoFNum netInfoRespBodyNetInfoFNum
) )
func (i *NetworkInfoResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (i *NetworkInfoResponseBody) StableMarshal(buf []byte) []byte {
if i == nil { if i == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, i.StableSize()) buf = make([]byte, i.StableSize())
} }
_, err := protoutil.NestedStructureMarshal(netInfoRespBodyNetInfoFNum, buf, i.netInfo) protoutil.NestedStructureMarshal(netInfoRespBodyNetInfoFNum, buf, i.netInfo)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (i *NetworkInfoResponseBody) StableSize() (size int) { func (i *NetworkInfoResponseBody) StableSize() (size int) {

View file

@ -48,28 +48,22 @@ const (
// StableMarshal encodes the Lock into Protocol Buffers binary format // StableMarshal encodes the Lock into Protocol Buffers binary format
// with direct field order. // with direct field order.
func (x *Lock) StableMarshal(buf []byte) ([]byte, error) { func (x *Lock) StableMarshal(buf []byte) []byte {
if x == nil || len(x.members) == 0 { if x == nil || len(x.members) == 0 {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var offset, n int var offset int
var err error
for i := range x.members { for i := range x.members {
n, err = proto.NestedStructureMarshal(fNumLockMembers, buf[offset:], &x.members[i]) offset += proto.NestedStructureMarshal(fNumLockMembers, buf[offset:], &x.members[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
// StableSize size of the buffer required to write the Lock in Protocol Buffers // StableSize size of the buffer required to write the Lock in Protocol Buffers
@ -146,11 +140,7 @@ func WriteLock(obj *Object, lock Lock) {
hdr.SetObjectType(TypeLock) hdr.SetObjectType(TypeLock)
payload, err := lock.StableMarshal(nil) payload := lock.StableMarshal(nil)
if err != nil {
panic(fmt.Sprintf("encode lock content: %v", err))
}
obj.SetPayload(payload) obj.SetPayload(payload)
} }

View file

@ -112,52 +112,26 @@ const (
getRangeHashRespBodyHashListField = 2 getRangeHashRespBodyHashListField = 2
) )
func (h *ShortHeader) StableMarshal(buf []byte) ([]byte, error) { func (h *ShortHeader) StableMarshal(buf []byte) []byte {
if h == nil { if h == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, h.StableSize()) buf = make([]byte, h.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(shortHdrVersionField, buf[offset:], h.version)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(shortHdrVersionField, buf[offset:], h.version)
offset += proto.UInt64Marshal(shortHdrEpochField, buf[offset:], h.creatEpoch) offset += proto.UInt64Marshal(shortHdrEpochField, buf[offset:], h.creatEpoch)
offset += proto.NestedStructureMarshal(shortHdrOwnerField, buf[offset:], h.ownerID)
n, err = proto.NestedStructureMarshal(shortHdrOwnerField, buf[offset:], h.ownerID)
if err != nil {
return nil, err
}
offset += n
offset += proto.EnumMarshal(shortHdrObjectTypeField, buf[offset:], int32(h.typ)) offset += proto.EnumMarshal(shortHdrObjectTypeField, buf[offset:], int32(h.typ))
offset += proto.UInt64Marshal(shortHdrPayloadLength, buf[offset:], h.payloadLen) offset += proto.UInt64Marshal(shortHdrPayloadLength, buf[offset:], h.payloadLen)
offset += proto.NestedStructureMarshal(shortHdrHashField, buf[offset:], h.payloadHash)
proto.NestedStructureMarshal(shortHdrHomoHashField, buf[offset:], h.homoHash)
n, err = proto.NestedStructureMarshal(shortHdrHashField, buf[offset:], h.payloadHash) return buf
if err != nil {
return nil, err
}
offset += n
_, err = proto.NestedStructureMarshal(shortHdrHomoHashField, buf[offset:], h.homoHash)
if err != nil {
return nil, err
}
return buf, nil
} }
func (h *ShortHeader) StableSize() (size int) { func (h *ShortHeader) StableSize() (size int) {
@ -180,9 +154,9 @@ func (h *ShortHeader) Unmarshal(data []byte) error {
return message.Unmarshal(h, data, new(object.ShortHeader)) return message.Unmarshal(h, data, new(object.ShortHeader))
} }
func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) { func (a *Attribute) StableMarshal(buf []byte) []byte {
if a == nil { if a == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -194,7 +168,7 @@ func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.StringMarshal(attributeKeyField, buf[offset:], a.key) offset += proto.StringMarshal(attributeKeyField, buf[offset:], a.key)
proto.StringMarshal(attributeValueField, buf[offset:], a.val) proto.StringMarshal(attributeValueField, buf[offset:], a.val)
return buf, nil return buf
} }
func (a *Attribute) StableSize() (size int) { func (a *Attribute) StableSize() (size int) {
@ -212,58 +186,25 @@ func (a *Attribute) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(object.Header_Attribute)) return message.Unmarshal(a, data, new(object.Header_Attribute))
} }
func (h *SplitHeader) StableMarshal(buf []byte) ([]byte, error) { func (h *SplitHeader) StableMarshal(buf []byte) []byte {
if h == nil { if h == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, h.StableSize()) buf = make([]byte, h.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(splitHdrParentField, buf[offset:], h.par)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(splitHdrPreviousField, buf[offset:], h.prev)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(splitHdrParentSignatureField, buf[offset:], h.parSig)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(splitHdrParentHeaderField, buf[offset:], h.parHdr)
if err != nil {
return nil, err
}
offset += n
n, err = refs.ObjectIDNestedListMarshal(splitHdrChildrenField, buf[offset:], h.children)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(splitHdrParentField, buf[offset:], h.par)
offset += proto.NestedStructureMarshal(splitHdrPreviousField, buf[offset:], h.prev)
offset += proto.NestedStructureMarshal(splitHdrParentSignatureField, buf[offset:], h.parSig)
offset += proto.NestedStructureMarshal(splitHdrParentHeaderField, buf[offset:], h.parHdr)
offset += refs.ObjectIDNestedListMarshal(splitHdrChildrenField, buf[offset:], h.children)
proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID) proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID)
return buf, nil return buf
} }
func (h *SplitHeader) StableSize() (size int) { func (h *SplitHeader) StableSize() (size int) {
@ -285,82 +226,34 @@ func (h *SplitHeader) Unmarshal(data []byte) error {
return message.Unmarshal(h, data, new(object.Header_Split)) return message.Unmarshal(h, data, new(object.Header_Split))
} }
func (h *Header) StableMarshal(buf []byte) ([]byte, error) { func (h *Header) StableMarshal(buf []byte) []byte {
if h == nil { if h == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, h.StableSize()) buf = make([]byte, h.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(hdrVersionField, buf[offset:], h.version)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(hdrContainerIDField, buf[offset:], h.cid)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(hdrOwnerIDField, buf[offset:], h.ownerID)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(hdrVersionField, buf[offset:], h.version)
offset += proto.NestedStructureMarshal(hdrContainerIDField, buf[offset:], h.cid)
offset += proto.NestedStructureMarshal(hdrOwnerIDField, buf[offset:], h.ownerID)
offset += proto.UInt64Marshal(hdrEpochField, buf[offset:], h.creatEpoch) offset += proto.UInt64Marshal(hdrEpochField, buf[offset:], h.creatEpoch)
offset += proto.UInt64Marshal(hdrPayloadLengthField, buf[offset:], h.payloadLen) offset += proto.UInt64Marshal(hdrPayloadLengthField, buf[offset:], h.payloadLen)
offset += proto.NestedStructureMarshal(hdrPayloadHashField, buf[offset:], h.payloadHash)
n, err = proto.NestedStructureMarshal(hdrPayloadHashField, buf[offset:], h.payloadHash)
if err != nil {
return nil, err
}
offset += n
offset += proto.EnumMarshal(hdrObjectTypeField, buf[offset:], int32(h.typ)) offset += proto.EnumMarshal(hdrObjectTypeField, buf[offset:], int32(h.typ))
offset += proto.NestedStructureMarshal(hdrHomomorphicHashField, buf[offset:], h.homoHash)
n, err = proto.NestedStructureMarshal(hdrHomomorphicHashField, buf[offset:], h.homoHash) offset += proto.NestedStructureMarshal(hdrSessionTokenField, buf[offset:], h.sessionToken)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(hdrSessionTokenField, buf[offset:], h.sessionToken)
if err != nil {
return nil, err
}
offset += n
for i := range h.attr { for i := range h.attr {
n, err = proto.NestedStructureMarshal(hdrAttributesField, buf[offset:], &h.attr[i]) offset += proto.NestedStructureMarshal(hdrAttributesField, buf[offset:], &h.attr[i])
if err != nil {
return nil, err
}
offset += n
} }
_, err = proto.NestedStructureMarshal(hdrSplitField, buf[offset:], h.split) proto.NestedStructureMarshal(hdrSplitField, buf[offset:], h.split)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (h *Header) StableSize() (size int) { func (h *Header) StableSize() (size int) {
@ -389,33 +282,21 @@ func (h *Header) Unmarshal(data []byte) error {
return message.Unmarshal(h, data, new(object.Header)) return message.Unmarshal(h, data, new(object.Header))
} }
func (h *HeaderWithSignature) StableMarshal(buf []byte) ([]byte, error) { func (h *HeaderWithSignature) StableMarshal(buf []byte) []byte {
if h == nil { if h == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, h.StableSize()) buf = make([]byte, h.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(hdrWithSigHeaderField, buf[offset:], h.header) offset += proto.NestedStructureMarshal(hdrWithSigHeaderField, buf[offset:], h.header)
if err != nil { proto.NestedStructureMarshal(hdrWithSigSignatureField, buf[offset:], h.signature)
return nil, err
}
offset += n return buf
_, err = proto.NestedStructureMarshal(hdrWithSigSignatureField, buf[offset:], h.signature)
if err != nil {
return nil, err
}
return buf, nil
} }
func (h *HeaderWithSignature) StableSize() (size int) { func (h *HeaderWithSignature) StableSize() (size int) {
@ -433,44 +314,23 @@ func (h *HeaderWithSignature) Unmarshal(data []byte) error {
return message.Unmarshal(h, data, new(object.HeaderWithSignature)) return message.Unmarshal(h, data, new(object.HeaderWithSignature))
} }
func (o *Object) StableMarshal(buf []byte) ([]byte, error) { func (o *Object) StableMarshal(buf []byte) []byte {
if o == nil { if o == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, o.StableSize()) buf = make([]byte, o.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(objIDField, buf[offset:], o.objectID)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(objSignatureField, buf[offset:], o.idSig)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(objHeaderField, buf[offset:], o.header)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(objIDField, buf[offset:], o.objectID)
offset += proto.NestedStructureMarshal(objSignatureField, buf[offset:], o.idSig)
offset += proto.NestedStructureMarshal(objHeaderField, buf[offset:], o.header)
proto.BytesMarshal(objPayloadField, buf[offset:], o.payload) proto.BytesMarshal(objPayloadField, buf[offset:], o.payload)
return buf, nil return buf
} }
func (o *Object) StableSize() (size int) { func (o *Object) StableSize() (size int) {
@ -490,35 +350,22 @@ func (o *Object) Unmarshal(data []byte) error {
return message.Unmarshal(o, data, new(object.Object)) return message.Unmarshal(o, data, new(object.Object))
} }
func (s *SplitInfo) StableMarshal(buf []byte) ([]byte, error) { func (s *SplitInfo) StableMarshal(buf []byte) []byte {
if s == nil { if s == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.StableSize()) buf = make([]byte, s.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += proto.BytesMarshal(splitInfoSplitIDField, buf[offset:], s.splitID) offset += proto.BytesMarshal(splitInfoSplitIDField, buf[offset:], s.splitID)
offset += proto.NestedStructureMarshal(splitInfoLastPartField, buf[offset:], s.lastPart)
proto.NestedStructureMarshal(splitInfoLinkField, buf[offset:], s.link)
n, err = proto.NestedStructureMarshal(splitInfoLastPartField, buf[offset:], s.lastPart) return buf
if err != nil {
return nil, err
}
offset += n
_, err = proto.NestedStructureMarshal(splitInfoLinkField, buf[offset:], s.link)
if err != nil {
return nil, err
}
return buf, nil
} }
func (s *SplitInfo) StableSize() (size int) { func (s *SplitInfo) StableSize() (size int) {
@ -537,30 +384,21 @@ func (s *SplitInfo) Unmarshal(data []byte) error {
return message.Unmarshal(s, data, new(object.SplitInfo)) return message.Unmarshal(s, data, new(object.SplitInfo))
} }
func (r *GetRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(getReqBodyAddressField, buf[offset:], r.addr)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(getReqBodyAddressField, buf[offset:], r.addr)
proto.BoolMarshal(getReqBodyRawFlagField, buf[offset:], r.raw) proto.BoolMarshal(getReqBodyRawFlagField, buf[offset:], r.raw)
return buf, nil return buf
} }
func (r *GetRequestBody) StableSize() (size int) { func (r *GetRequestBody) StableSize() (size int) {
@ -578,40 +416,22 @@ func (r *GetRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.GetRequest_Body)) return message.Unmarshal(r, data, new(object.GetRequest_Body))
} }
func (r *GetObjectPartInit) StableMarshal(buf []byte) ([]byte, error) { func (r *GetObjectPartInit) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(getRespInitObjectIDField, buf[offset:], r.id) offset += proto.NestedStructureMarshal(getRespInitObjectIDField, buf[offset:], r.id)
if err != nil { offset += proto.NestedStructureMarshal(getRespInitSignatureField, buf[offset:], r.sig)
return nil, err proto.NestedStructureMarshal(getRespInitHeaderField, buf[offset:], r.hdr)
}
offset += n return buf
n, err = proto.NestedStructureMarshal(getRespInitSignatureField, buf[offset:], r.sig)
if err != nil {
return nil, err
}
offset += n
_, err = proto.NestedStructureMarshal(getRespInitHeaderField, buf[offset:], r.hdr)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *GetObjectPartInit) StableSize() (size int) { func (r *GetObjectPartInit) StableSize() (size int) {
@ -630,9 +450,9 @@ func (r *GetObjectPartInit) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.GetResponse_Body_Init)) return message.Unmarshal(r, data, new(object.GetResponse_Body_Init))
} }
func (r *GetResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -642,24 +462,18 @@ func (r *GetResponseBody) StableMarshal(buf []byte) ([]byte, error) {
switch v := r.objPart.(type) { switch v := r.objPart.(type) {
case nil: case nil:
case *GetObjectPartInit: case *GetObjectPartInit:
_, err := proto.NestedStructureMarshal(getRespBodyInitField, buf, v) proto.NestedStructureMarshal(getRespBodyInitField, buf, v)
if err != nil {
return nil, err
}
case *GetObjectPartChunk: case *GetObjectPartChunk:
if v != nil { if v != nil {
proto.BytesMarshal(getRespBodyChunkField, buf, v.chunk) proto.BytesMarshal(getRespBodyChunkField, buf, v.chunk)
} }
case *SplitInfo: case *SplitInfo:
_, err := proto.NestedStructureMarshal(getRespBodySplitInfoField, buf, v) proto.NestedStructureMarshal(getRespBodySplitInfoField, buf, v)
if err != nil {
return nil, err
}
default: default:
panic("unknown one of object get response body type") panic("unknown one of object get response body type")
} }
return buf, nil return buf
} }
func (r *GetResponseBody) StableSize() (size int) { func (r *GetResponseBody) StableSize() (size int) {
@ -688,44 +502,23 @@ func (r *GetResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.GetResponse_Body)) return message.Unmarshal(r, data, new(object.GetResponse_Body))
} }
func (r *PutObjectPartInit) StableMarshal(buf []byte) ([]byte, error) { func (r *PutObjectPartInit) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(putReqInitObjectIDField, buf[offset:], r.id)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(putReqInitSignatureField, buf[offset:], r.sig)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(putReqInitHeaderField, buf[offset:], r.hdr)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(putReqInitObjectIDField, buf[offset:], r.id)
offset += proto.NestedStructureMarshal(putReqInitSignatureField, buf[offset:], r.sig)
offset += proto.NestedStructureMarshal(putReqInitHeaderField, buf[offset:], r.hdr)
proto.UInt32Marshal(putReqInitCopiesNumField, buf[offset:], r.copyNum) proto.UInt32Marshal(putReqInitCopiesNumField, buf[offset:], r.copyNum)
return buf, nil return buf
} }
func (r *PutObjectPartInit) StableSize() (size int) { func (r *PutObjectPartInit) StableSize() (size int) {
@ -745,9 +538,9 @@ func (r *PutObjectPartInit) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.PutRequest_Body_Init)) return message.Unmarshal(r, data, new(object.PutRequest_Body_Init))
} }
func (r *PutRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *PutRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -757,10 +550,7 @@ func (r *PutRequestBody) StableMarshal(buf []byte) ([]byte, error) {
switch v := r.objPart.(type) { switch v := r.objPart.(type) {
case nil: case nil:
case *PutObjectPartInit: case *PutObjectPartInit:
_, err := proto.NestedStructureMarshal(putReqBodyInitField, buf, v) proto.NestedStructureMarshal(putReqBodyInitField, buf, v)
if err != nil {
return nil, err
}
case *PutObjectPartChunk: case *PutObjectPartChunk:
if v != nil { if v != nil {
proto.BytesMarshal(putReqBodyChunkField, buf, v.chunk) proto.BytesMarshal(putReqBodyChunkField, buf, v.chunk)
@ -769,7 +559,7 @@ func (r *PutRequestBody) StableMarshal(buf []byte) ([]byte, error) {
panic("unknown one of object put request body type") panic("unknown one of object put request body type")
} }
return buf, nil return buf
} }
func (r *PutRequestBody) StableSize() (size int) { func (r *PutRequestBody) StableSize() (size int) {
@ -796,21 +586,18 @@ func (r *PutRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.PutRequest_Body)) return message.Unmarshal(r, data, new(object.PutRequest_Body))
} }
func (r *PutResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *PutResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
_, err := proto.NestedStructureMarshal(putRespBodyObjectIDField, buf, r.id) proto.NestedStructureMarshal(putRespBodyObjectIDField, buf, r.id)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (r *PutResponseBody) StableSize() (size int) { func (r *PutResponseBody) StableSize() (size int) {
@ -827,21 +614,18 @@ func (r *PutResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.PutResponse_Body)) return message.Unmarshal(r, data, new(object.PutResponse_Body))
} }
func (r *DeleteRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *DeleteRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
_, err := proto.NestedStructureMarshal(deleteReqBodyAddressField, buf, r.addr) proto.NestedStructureMarshal(deleteReqBodyAddressField, buf, r.addr)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (r *DeleteRequestBody) StableSize() (size int) { func (r *DeleteRequestBody) StableSize() (size int) {
@ -858,21 +642,18 @@ func (r *DeleteRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.DeleteRequest_Body)) return message.Unmarshal(r, data, new(object.DeleteRequest_Body))
} }
func (r *DeleteResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *DeleteResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
_, err := proto.NestedStructureMarshal(deleteRespBodyTombstoneFNum, buf, r.tombstone) proto.NestedStructureMarshal(deleteRespBodyTombstoneFNum, buf, r.tombstone)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (r *DeleteResponseBody) StableSize() (size int) { func (r *DeleteResponseBody) StableSize() (size int) {
@ -889,31 +670,22 @@ func (r *DeleteResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.DeleteResponse_Body)) return message.Unmarshal(r, data, new(object.DeleteResponse_Body))
} }
func (r *HeadRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *HeadRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(headReqBodyAddressField, buf[offset:], r.addr)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(headReqBodyAddressField, buf[offset:], r.addr)
offset += proto.BoolMarshal(headReqBodyMainFlagField, buf[offset:], r.mainOnly) offset += proto.BoolMarshal(headReqBodyMainFlagField, buf[offset:], r.mainOnly)
proto.BoolMarshal(headReqBodyRawFlagField, buf[offset:], r.raw) proto.BoolMarshal(headReqBodyRawFlagField, buf[offset:], r.raw)
return buf, nil return buf
} }
func (r *HeadRequestBody) StableSize() (size int) { func (r *HeadRequestBody) StableSize() (size int) {
@ -932,9 +704,9 @@ func (r *HeadRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.HeadRequest_Body)) return message.Unmarshal(r, data, new(object.HeadRequest_Body))
} }
func (r *HeadResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *HeadResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -945,30 +717,21 @@ func (r *HeadResponseBody) StableMarshal(buf []byte) ([]byte, error) {
case nil: case nil:
case *HeaderWithSignature: case *HeaderWithSignature:
if v != nil { if v != nil {
_, err := proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v) proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v)
if err != nil {
return nil, err
}
} }
case *ShortHeader: case *ShortHeader:
if v != nil { if v != nil {
_, err := proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v) proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v)
if err != nil {
return nil, err
}
} }
case *SplitInfo: case *SplitInfo:
if v != nil { if v != nil {
_, err := proto.NestedStructureMarshal(headRespBodySplitInfoField, buf, v) proto.NestedStructureMarshal(headRespBodySplitInfoField, buf, v)
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")
} }
return buf, nil return buf
} }
func (r *HeadResponseBody) StableSize() (size int) { func (r *HeadResponseBody) StableSize() (size int) {
@ -1001,9 +764,9 @@ func (r *HeadResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.HeadResponse_Body)) return message.Unmarshal(r, data, new(object.HeadResponse_Body))
} }
func (f *SearchFilter) StableMarshal(buf []byte) ([]byte, error) { func (f *SearchFilter) StableMarshal(buf []byte) []byte {
if f == nil { if f == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -1016,7 +779,7 @@ func (f *SearchFilter) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.StringMarshal(searchFilterNameField, buf[offset:], f.key) offset += proto.StringMarshal(searchFilterNameField, buf[offset:], f.key)
proto.StringMarshal(searchFilterValueField, buf[offset:], f.val) proto.StringMarshal(searchFilterValueField, buf[offset:], f.val)
return buf, nil return buf
} }
func (f *SearchFilter) StableSize() (size int) { func (f *SearchFilter) StableSize() (size int) {
@ -1035,39 +798,25 @@ func (f *SearchFilter) Unmarshal(data []byte) error {
return message.Unmarshal(f, data, new(object.SearchRequest_Body_Filter)) return message.Unmarshal(f, data, new(object.SearchRequest_Body_Filter))
} }
func (r *SearchRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *SearchRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(searchReqBodyContainerIDField, buf[offset:], r.cid)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(searchReqBodyContainerIDField, buf[offset:], r.cid)
offset += proto.UInt32Marshal(searchReqBodyVersionField, buf[offset:], r.version) offset += proto.UInt32Marshal(searchReqBodyVersionField, buf[offset:], r.version)
for i := range r.filters { for i := range r.filters {
n, err = proto.NestedStructureMarshal(searchReqBodyFiltersField, buf[offset:], &r.filters[i]) offset += proto.NestedStructureMarshal(searchReqBodyFiltersField, buf[offset:], &r.filters[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
func (r *SearchRequestBody) StableSize() (size int) { func (r *SearchRequestBody) StableSize() (size int) {
@ -1089,26 +838,20 @@ func (r *SearchRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.SearchRequest_Body)) return message.Unmarshal(r, data, new(object.SearchRequest_Body))
} }
func (r *SearchResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *SearchResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset int
err error
)
_, err = refs.ObjectIDNestedListMarshal(searchRespBodyObjectIDsField, buf[offset:], r.idList) refs.ObjectIDNestedListMarshal(searchRespBodyObjectIDsField, buf[offset:], r.idList)
if err != nil {
return nil, err
}
return buf, nil return buf
} }
func (r *SearchResponseBody) StableSize() (size int) { func (r *SearchResponseBody) StableSize() (size int) {
@ -1125,9 +868,9 @@ func (r *SearchResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.SearchResponse_Body)) return message.Unmarshal(r, data, new(object.SearchResponse_Body))
} }
func (r *Range) StableMarshal(buf []byte) ([]byte, error) { func (r *Range) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -1139,7 +882,7 @@ func (r *Range) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.UInt64Marshal(rangeOffsetField, buf[offset:], r.off) offset += proto.UInt64Marshal(rangeOffsetField, buf[offset:], r.off)
proto.UInt64Marshal(rangeLengthField, buf[offset:], r.len) proto.UInt64Marshal(rangeLengthField, buf[offset:], r.len)
return buf, nil return buf
} }
func (r *Range) StableSize() (size int) { func (r *Range) StableSize() (size int) {
@ -1157,37 +900,22 @@ func (r *Range) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.Range)) return message.Unmarshal(r, data, new(object.Range))
} }
func (r *GetRangeRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetRangeRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(getRangeReqBodyAddressField, buf[offset:], r.addr)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(getRangeReqBodyRangeField, buf[offset:], r.rng)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(getRangeReqBodyAddressField, buf[offset:], r.addr)
offset += proto.NestedStructureMarshal(getRangeReqBodyRangeField, buf[offset:], r.rng)
proto.BoolMarshal(getRangeReqBodyRawField, buf[offset:], r.raw) proto.BoolMarshal(getRangeReqBodyRawField, buf[offset:], r.raw)
return buf, nil return buf
} }
func (r *GetRangeRequestBody) StableSize() (size int) { func (r *GetRangeRequestBody) StableSize() (size int) {
@ -1206,9 +934,9 @@ func (r *GetRangeRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.GetRangeRequest_Body)) return message.Unmarshal(r, data, new(object.GetRangeRequest_Body))
} }
func (r *GetRangeResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetRangeResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -1223,16 +951,13 @@ func (r *GetRangeResponseBody) StableMarshal(buf []byte) ([]byte, error) {
} }
case *SplitInfo: case *SplitInfo:
if v != nil { if v != nil {
_, err := proto.NestedStructureMarshal(getRangeRespSplitInfoField, buf, v) proto.NestedStructureMarshal(getRangeRespSplitInfoField, buf, v)
if err != nil {
return nil, err
}
} }
default: default:
panic("unknown one of object get range request body type") panic("unknown one of object get range request body type")
} }
return buf, nil return buf
} }
func (r *GetRangeResponseBody) StableSize() (size int) { func (r *GetRangeResponseBody) StableSize() (size int) {
@ -1261,40 +986,27 @@ func (r *GetRangeResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.GetRangeResponse_Body)) return message.Unmarshal(r, data, new(object.GetRangeResponse_Body))
} }
func (r *GetRangeHashRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetRangeHashRequestBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(getRangeHashReqBodyAddressField, buf[offset:], r.addr) offset += proto.NestedStructureMarshal(getRangeHashReqBodyAddressField, buf[offset:], r.addr)
if err != nil {
return nil, err
}
offset += n
for i := range r.rngs { for i := range r.rngs {
n, err = proto.NestedStructureMarshal(getRangeHashReqBodyRangesField, buf[offset:], &r.rngs[i]) offset += proto.NestedStructureMarshal(getRangeHashReqBodyRangesField, buf[offset:], &r.rngs[i])
if err != nil {
return nil, err
}
offset += n
} }
offset += proto.BytesMarshal(getRangeHashReqBodySaltField, buf[offset:], r.salt) offset += proto.BytesMarshal(getRangeHashReqBodySaltField, buf[offset:], r.salt)
proto.EnumMarshal(getRangeHashReqBodyTypeField, buf[offset:], int32(r.typ)) proto.EnumMarshal(getRangeHashReqBodyTypeField, buf[offset:], int32(r.typ))
return buf, nil return buf
} }
func (r *GetRangeHashRequestBody) StableSize() (size int) { func (r *GetRangeHashRequestBody) StableSize() (size int) {
@ -1318,9 +1030,9 @@ func (r *GetRangeHashRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.GetRangeHashRequest_Body)) return message.Unmarshal(r, data, new(object.GetRangeHashRequest_Body))
} }
func (r *GetRangeHashResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *GetRangeHashResponseBody) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -1332,7 +1044,7 @@ func (r *GetRangeHashResponseBody) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.EnumMarshal(getRangeHashRespBodyTypeField, buf, int32(r.typ)) offset += proto.EnumMarshal(getRangeHashRespBodyTypeField, buf, int32(r.typ))
proto.RepeatedBytesMarshal(getRangeHashRespBodyHashListField, buf[offset:], r.hashList) proto.RepeatedBytesMarshal(getRangeHashRespBodyHashListField, buf[offset:], r.hashList)
return buf, nil return buf
} }
func (r *GetRangeHashResponseBody) StableSize() (size int) { func (r *GetRangeHashResponseBody) StableSize() (size int) {

View file

@ -44,8 +44,8 @@ func benchmarkObjectIDSlice(b *testing.B, size int) {
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, ObjectIDNestedListSize(1, ids))
_, err := ObjectIDNestedListMarshal(1, buf, ids) n := ObjectIDNestedListMarshal(1, buf, ids)
if err != nil { if n != len(buf) {
b.FailNow() b.FailNow()
} }
} }

View file

@ -27,9 +27,9 @@ const (
versionMinorField = 2 versionMinorField = 2
) )
func (o *OwnerID) StableMarshal(buf []byte) ([]byte, error) { func (o *OwnerID) StableMarshal(buf []byte) []byte {
if o == nil { if o == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -38,7 +38,7 @@ func (o *OwnerID) StableMarshal(buf []byte) ([]byte, error) {
proto.BytesMarshal(ownerIDValField, buf, o.val) proto.BytesMarshal(ownerIDValField, buf, o.val)
return buf, nil return buf
} }
func (o *OwnerID) StableSize() int { func (o *OwnerID) StableSize() int {
@ -53,9 +53,9 @@ func (o *OwnerID) Unmarshal(data []byte) error {
return message.Unmarshal(o, data, new(refs.OwnerID)) return message.Unmarshal(o, data, new(refs.OwnerID))
} }
func (c *ContainerID) StableMarshal(buf []byte) ([]byte, error) { func (c *ContainerID) StableMarshal(buf []byte) []byte {
if c == nil { if c == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -64,7 +64,7 @@ func (c *ContainerID) StableMarshal(buf []byte) ([]byte, error) {
proto.BytesMarshal(containerIDValField, buf, c.val) proto.BytesMarshal(containerIDValField, buf, c.val)
return buf, nil return buf
} }
func (c *ContainerID) StableSize() int { func (c *ContainerID) StableSize() int {
@ -79,9 +79,9 @@ func (c *ContainerID) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(refs.ContainerID)) return message.Unmarshal(c, data, new(refs.ContainerID))
} }
func (o *ObjectID) StableMarshal(buf []byte) ([]byte, error) { func (o *ObjectID) StableMarshal(buf []byte) []byte {
if o == nil { if o == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -90,7 +90,7 @@ func (o *ObjectID) StableMarshal(buf []byte) ([]byte, error) {
proto.BytesMarshal(objectIDValField, buf, o.val) proto.BytesMarshal(objectIDValField, buf, o.val)
return buf, nil return buf
} }
// ObjectIDNestedListSize returns byte length of nested // ObjectIDNestedListSize returns byte length of nested
@ -113,16 +113,9 @@ 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, err error) { func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int) {
for i := range ids { for i := range ids {
var n int off += proto.NestedStructureMarshal(fNum, buf[off:], &ids[i])
n, err = proto.NestedStructureMarshal(fNum, buf[off:], &ids[i])
if err != nil {
return
}
off += n
} }
return return
@ -132,33 +125,21 @@ func (o *ObjectID) Unmarshal(data []byte) error {
return message.Unmarshal(o, data, new(refs.ObjectID)) return message.Unmarshal(o, data, new(refs.ObjectID))
} }
func (a *Address) StableMarshal(buf []byte) ([]byte, error) { func (a *Address) StableMarshal(buf []byte) []byte {
if a == nil { if a == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, a.StableSize()) buf = make([]byte, a.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(addressContainerField, buf[offset:], a.cid) offset += proto.NestedStructureMarshal(addressContainerField, buf[offset:], a.cid)
if err != nil { proto.NestedStructureMarshal(addressObjectField, buf[offset:], a.oid)
return nil, err
}
offset += n return buf
_, err = proto.NestedStructureMarshal(addressObjectField, buf[offset:], a.oid)
if err != nil {
return nil, err
}
return buf, nil
} }
func (a *Address) StableSize() (size int) { func (a *Address) StableSize() (size int) {
@ -167,7 +148,6 @@ func (a *Address) StableSize() (size int) {
} }
size += proto.NestedStructureSize(addressContainerField, a.cid) size += proto.NestedStructureSize(addressContainerField, a.cid)
size += proto.NestedStructureSize(addressObjectField, a.oid) size += proto.NestedStructureSize(addressObjectField, a.oid)
return size return size
@ -177,9 +157,9 @@ func (a *Address) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(refs.Address)) return message.Unmarshal(a, data, new(refs.Address))
} }
func (c *Checksum) StableMarshal(buf []byte) ([]byte, error) { func (c *Checksum) StableMarshal(buf []byte) []byte {
if c == nil { if c == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -191,7 +171,7 @@ func (c *Checksum) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ)) offset += proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ))
proto.BytesMarshal(checksumValueField, buf[offset:], c.sum) proto.BytesMarshal(checksumValueField, buf[offset:], c.sum)
return buf, nil return buf
} }
func (c *Checksum) StableSize() (size int) { func (c *Checksum) StableSize() (size int) {
@ -209,9 +189,9 @@ func (c *Checksum) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(refs.Checksum)) return message.Unmarshal(c, data, new(refs.Checksum))
} }
func (s *Signature) StableMarshal(buf []byte) ([]byte, error) { func (s *Signature) StableMarshal(buf []byte) []byte {
if s == nil { if s == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -224,7 +204,7 @@ func (s *Signature) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.BytesMarshal(signatureValueField, buf[offset:], s.sign) offset += proto.BytesMarshal(signatureValueField, buf[offset:], s.sign)
proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme)) proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme))
return buf, nil return buf
} }
func (s *Signature) StableSize() (size int) { func (s *Signature) StableSize() (size int) {
@ -243,9 +223,9 @@ func (s *Signature) Unmarshal(data []byte) error {
return message.Unmarshal(s, data, new(refs.Signature)) return message.Unmarshal(s, data, new(refs.Signature))
} }
func (v *Version) StableMarshal(buf []byte) ([]byte, error) { func (v *Version) StableMarshal(buf []byte) []byte {
if v == nil { if v == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -257,7 +237,7 @@ func (v *Version) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.UInt32Marshal(versionMajorField, buf[offset:], v.major) offset += proto.UInt32Marshal(versionMajorField, buf[offset:], v.major)
proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor) proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor)
return buf, nil return buf
} }
func (v *Version) StableSize() (size int) { func (v *Version) StableSize() (size int) {
@ -284,9 +264,9 @@ const (
// StableMarshal marshals SubnetID to NeoFS API V2 binary format (Protocol Buffers with direct field order). // StableMarshal marshals SubnetID to NeoFS API V2 binary format (Protocol Buffers with direct field order).
// //
// Returns a slice of recorded data. Data is written to the provided buffer if there is enough space. // Returns a slice of recorded data. Data is written to the provided buffer if there is enough space.
func (s *SubnetID) StableMarshal(buf []byte) ([]byte, error) { func (s *SubnetID) StableMarshal(buf []byte) []byte {
if s == nil { if s == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -295,7 +275,7 @@ func (s *SubnetID) StableMarshal(buf []byte) ([]byte, error) {
proto.Fixed32Marshal(subnetIDValFNum, buf, s.value) proto.Fixed32Marshal(subnetIDValFNum, buf, s.value)
return buf, nil return buf
} }
// StableSize returns the number of bytes required to write SubnetID in NeoFS API V2 binary format (see StableMarshal). // StableSize returns the number of bytes required to write SubnetID in NeoFS API V2 binary format (see StableMarshal).

View file

@ -11,9 +11,9 @@ const (
peerIDPubKeyFNum peerIDPubKeyFNum
) )
func (x *PeerID) StableMarshal(buf []byte) ([]byte, error) { func (x *PeerID) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -22,7 +22,7 @@ func (x *PeerID) StableMarshal(buf []byte) ([]byte, error) {
protoutil.BytesMarshal(peerIDPubKeyFNum, buf, x.publicKey) protoutil.BytesMarshal(peerIDPubKeyFNum, buf, x.publicKey)
return buf, nil return buf
} }
func (x *PeerID) StableSize() (size int) { func (x *PeerID) StableSize() (size int) {
@ -41,30 +41,21 @@ const (
trustValueFNum trustValueFNum
) )
func (x *Trust) StableMarshal(buf []byte) ([]byte, error) { func (x *Trust) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(trustPeerFNum, buf[offset:], x.peer)
if err != nil {
return nil, err
}
offset += n
offset += protoutil.NestedStructureMarshal(trustPeerFNum, buf[offset:], x.peer)
protoutil.Float64Marshal(trustValueFNum, buf[offset:], x.val) protoutil.Float64Marshal(trustValueFNum, buf[offset:], x.val)
return buf, nil return buf
} }
func (x *Trust) StableSize() (size int) { func (x *Trust) StableSize() (size int) {
@ -84,26 +75,21 @@ const (
p2pTrustValueFNum p2pTrustValueFNum
) )
func (x *PeerToPeerTrust) StableMarshal(buf []byte) ([]byte, error) { func (x *PeerToPeerTrust) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
offset, err := protoutil.NestedStructureMarshal(p2pTrustTrustingFNum, buf, x.trusting) var offset int
if err != nil {
return nil, err
}
_, err = protoutil.NestedStructureMarshal(p2pTrustValueFNum, buf[offset:], x.trust) offset += protoutil.NestedStructureMarshal(p2pTrustTrustingFNum, buf, x.trusting)
if err != nil { protoutil.NestedStructureMarshal(p2pTrustValueFNum, buf[offset:], x.trust)
return nil, err
}
return buf, nil return buf
} }
func (x *PeerToPeerTrust) StableSize() (size int) { func (x *PeerToPeerTrust) StableSize() (size int) {
@ -123,26 +109,21 @@ const (
globalTrustBodyValueFNum globalTrustBodyValueFNum
) )
func (x *GlobalTrustBody) StableMarshal(buf []byte) ([]byte, error) { func (x *GlobalTrustBody) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
offset, err := protoutil.NestedStructureMarshal(globalTrustBodyManagerFNum, buf, x.manager) var offset int
if err != nil {
return nil, err
}
_, err = protoutil.NestedStructureMarshal(globalTrustBodyValueFNum, buf[offset:], x.trust) offset += protoutil.NestedStructureMarshal(globalTrustBodyManagerFNum, buf, x.manager)
if err != nil { protoutil.NestedStructureMarshal(globalTrustBodyValueFNum, buf[offset:], x.trust)
return nil, err
}
return buf, nil return buf
} }
func (x *GlobalTrustBody) StableSize() (size int) { func (x *GlobalTrustBody) StableSize() (size int) {
@ -163,33 +144,22 @@ const (
globalTrustSigFNum globalTrustSigFNum
) )
func (x *GlobalTrust) StableMarshal(buf []byte) ([]byte, error) { func (x *GlobalTrust) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
offset, err := protoutil.NestedStructureMarshal(globalTrustVersionFNum, buf, x.version) var offset int
if err != nil {
return nil, err
}
n, err := protoutil.NestedStructureMarshal(globalTrustBodyFNum, buf[offset:], x.body) offset += protoutil.NestedStructureMarshal(globalTrustVersionFNum, buf, x.version)
if err != nil { offset += protoutil.NestedStructureMarshal(globalTrustBodyFNum, buf[offset:], x.body)
return nil, err protoutil.NestedStructureMarshal(globalTrustSigFNum, buf[offset:], x.sig)
}
offset += n return buf
_, err = protoutil.NestedStructureMarshal(globalTrustSigFNum, buf[offset:], x.sig)
if err != nil {
return nil, err
}
return buf, nil
} }
func (x *GlobalTrust) StableSize() (size int) { func (x *GlobalTrust) StableSize() (size int) {
@ -210,32 +180,24 @@ const (
announceLocalTrustBodyTrustsFNum announceLocalTrustBodyTrustsFNum
) )
func (x *AnnounceLocalTrustRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (x *AnnounceLocalTrustRequestBody) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += protoutil.UInt64Marshal(announceLocalTrustBodyEpochFNum, buf[offset:], x.epoch) offset += protoutil.UInt64Marshal(announceLocalTrustBodyEpochFNum, buf[offset:], x.epoch)
for i := range x.trusts { for i := range x.trusts {
n, err = protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], &x.trusts[i]) offset += protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], &x.trusts[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
func (x *AnnounceLocalTrustRequestBody) StableSize() (size int) { func (x *AnnounceLocalTrustRequestBody) StableSize() (size int) {
@ -252,8 +214,8 @@ func (x *AnnounceLocalTrustRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(x, data, new(reputation.AnnounceLocalTrustRequest_Body)) return message.Unmarshal(x, data, new(reputation.AnnounceLocalTrustRequest_Body))
} }
func (x *AnnounceLocalTrustResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (x *AnnounceLocalTrustResponseBody) StableMarshal(buf []byte) []byte {
return buf, nil return buf
} }
func (x *AnnounceLocalTrustResponseBody) StableSize() int { func (x *AnnounceLocalTrustResponseBody) StableSize() int {
@ -271,29 +233,22 @@ const (
announceInterResBodyTrustFNum announceInterResBodyTrustFNum
) )
func (x *AnnounceIntermediateResultRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (x *AnnounceIntermediateResultRequestBody) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset int
err error
)
offset += protoutil.UInt64Marshal(announceInterResBodyEpochFNum, buf, x.epoch) offset += protoutil.UInt64Marshal(announceInterResBodyEpochFNum, buf, x.epoch)
offset += protoutil.UInt32Marshal(announceInterResBodyIterFNum, buf[offset:], x.iter) offset += protoutil.UInt32Marshal(announceInterResBodyIterFNum, buf[offset:], x.iter)
protoutil.NestedStructureMarshal(announceInterResBodyTrustFNum, buf[offset:], x.trust)
_, err = protoutil.NestedStructureMarshal(announceInterResBodyTrustFNum, buf[offset:], x.trust) return buf
if err != nil {
return nil, err
}
return buf, nil
} }
func (x *AnnounceIntermediateResultRequestBody) StableSize() (size int) { func (x *AnnounceIntermediateResultRequestBody) StableSize() (size int) {
@ -308,8 +263,8 @@ func (x *AnnounceIntermediateResultRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(x, data, new(reputation.AnnounceIntermediateResultRequest_Body)) return message.Unmarshal(x, data, new(reputation.AnnounceIntermediateResultRequest_Body))
} }
func (x *AnnounceIntermediateResultResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (x *AnnounceIntermediateResultResponseBody) StableMarshal(buf []byte) []byte {
return buf, nil return buf
} }
func (x *AnnounceIntermediateResultResponseBody) StableSize() int { func (x *AnnounceIntermediateResultResponseBody) StableSize() int {

View file

@ -61,30 +61,21 @@ const (
respVerifHeaderOriginField = 4 respVerifHeaderOriginField = 4
) )
func (c *CreateRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (c *CreateRequestBody) StableMarshal(buf []byte) []byte {
if c == nil { if c == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, c.StableSize()) buf = make([]byte, c.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(createReqBodyOwnerField, buf[offset:], c.ownerID)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(createReqBodyOwnerField, buf[offset:], c.ownerID)
proto.UInt64Marshal(createReqBodyExpirationField, buf[offset:], c.expiration) proto.UInt64Marshal(createReqBodyExpirationField, buf[offset:], c.expiration)
return buf, nil return buf
} }
func (c *CreateRequestBody) StableSize() (size int) { func (c *CreateRequestBody) StableSize() (size int) {
@ -102,9 +93,9 @@ func (c *CreateRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(session.CreateRequest_Body)) return message.Unmarshal(c, data, new(session.CreateRequest_Body))
} }
func (c *CreateResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (c *CreateResponseBody) StableMarshal(buf []byte) []byte {
if c == nil { if c == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -116,7 +107,7 @@ func (c *CreateResponseBody) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.BytesMarshal(createRespBodyIDField, buf[offset:], c.id) offset += proto.BytesMarshal(createRespBodyIDField, buf[offset:], c.id)
proto.BytesMarshal(createRespBodyKeyField, buf[offset:], c.sessionKey) proto.BytesMarshal(createRespBodyKeyField, buf[offset:], c.sessionKey)
return buf, nil return buf
} }
func (c *CreateResponseBody) StableSize() (size int) { func (c *CreateResponseBody) StableSize() (size int) {
@ -134,9 +125,9 @@ func (c *CreateResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(session.CreateResponse_Body)) return message.Unmarshal(c, data, new(session.CreateResponse_Body))
} }
func (x *XHeader) StableMarshal(buf []byte) ([]byte, error) { func (x *XHeader) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -148,7 +139,7 @@ func (x *XHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.StringMarshal(xheaderKeyField, buf[offset:], x.key) offset += proto.StringMarshal(xheaderKeyField, buf[offset:], x.key)
proto.StringMarshal(xheaderValueField, buf[offset:], x.val) proto.StringMarshal(xheaderValueField, buf[offset:], x.val)
return buf, nil return buf
} }
func (x *XHeader) StableSize() (size int) { func (x *XHeader) StableSize() (size int) {
@ -171,9 +162,9 @@ func (x *XHeader) Unmarshal(data []byte) error {
return x.FromGRPCMessage(m) return x.FromGRPCMessage(m)
} }
func (l *TokenLifetime) StableMarshal(buf []byte) ([]byte, error) { func (l *TokenLifetime) StableMarshal(buf []byte) []byte {
if l == nil { if l == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -186,7 +177,7 @@ func (l *TokenLifetime) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf) offset += proto.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
proto.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat) proto.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
return buf, nil return buf
} }
func (l *TokenLifetime) StableSize() (size int) { func (l *TokenLifetime) StableSize() (size int) {
@ -210,9 +201,9 @@ func (l *TokenLifetime) Unmarshal(data []byte) error {
return l.FromGRPCMessage(m) return l.FromGRPCMessage(m)
} }
func (c *ObjectSessionContext) StableMarshal(buf []byte) ([]byte, error) { func (c *ObjectSessionContext) StableMarshal(buf []byte) []byte {
if c == nil { if c == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -224,7 +215,7 @@ func (c *ObjectSessionContext) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.EnumMarshal(objectCtxVerbField, buf[offset:], int32(c.verb)) offset += proto.EnumMarshal(objectCtxVerbField, buf[offset:], int32(c.verb))
proto.NestedStructureMarshal(objectCtxAddressField, buf[offset:], c.addr) proto.NestedStructureMarshal(objectCtxAddressField, buf[offset:], c.addr)
return buf, nil return buf
} }
func (c *ObjectSessionContext) StableSize() (size int) { func (c *ObjectSessionContext) StableSize() (size int) {
@ -254,9 +245,9 @@ const (
cnrCtxCidFNum cnrCtxCidFNum
) )
func (x *ContainerSessionContext) StableMarshal(buf []byte) ([]byte, error) { func (x *ContainerSessionContext) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -269,7 +260,7 @@ func (x *ContainerSessionContext) StableMarshal(buf []byte) ([]byte, error) {
offset += proto.BoolMarshal(cnrCtxWildcardFNum, buf[offset:], x.wildcard) offset += proto.BoolMarshal(cnrCtxWildcardFNum, buf[offset:], x.wildcard)
proto.NestedStructureMarshal(cnrCtxCidFNum, buf[offset:], x.cid) proto.NestedStructureMarshal(cnrCtxCidFNum, buf[offset:], x.cid)
return buf, nil return buf
} }
func (x *ContainerSessionContext) StableSize() (size int) { func (x *ContainerSessionContext) StableSize() (size int) {
@ -288,56 +279,34 @@ func (x *ContainerSessionContext) Unmarshal(data []byte) error {
return message.Unmarshal(x, data, new(session.ContainerSessionContext)) return message.Unmarshal(x, data, new(session.ContainerSessionContext))
} }
func (t *TokenBody) StableMarshal(buf []byte) ([]byte, error) { func (t *TokenBody) StableMarshal(buf []byte) []byte {
if t == nil { if t == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, t.StableSize()) buf = make([]byte, t.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += proto.BytesMarshal(sessionTokenBodyIDField, buf[offset:], t.id) offset += proto.BytesMarshal(sessionTokenBodyIDField, buf[offset:], t.id)
offset += proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf[offset:], t.ownerID)
n, err = proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf[offset:], t.ownerID) offset += proto.NestedStructureMarshal(sessionTokenBodyLifetimeField, buf[offset:], t.lifetime)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(sessionTokenBodyLifetimeField, buf[offset:], t.lifetime)
if err != nil {
return nil, err
}
offset += n
offset += proto.BytesMarshal(sessionTokenBodyKeyField, buf[offset:], t.sessionKey) 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:
_, err = proto.NestedStructureMarshal(sessionTokenBodyObjectCtxField, buf[offset:], v) proto.NestedStructureMarshal(sessionTokenBodyObjectCtxField, buf[offset:], v)
if err != nil {
return nil, err
}
case *ContainerSessionContext: case *ContainerSessionContext:
_, err = proto.NestedStructureMarshal(sessionTokenBodyCnrCtxField, buf[offset:], v) proto.NestedStructureMarshal(sessionTokenBodyCnrCtxField, buf[offset:], v)
if err != nil {
return nil, err
}
default: default:
panic("cannot marshal unknown session token context") panic("cannot marshal unknown session token context")
} }
} }
return buf, nil return buf
} }
func (t *TokenBody) StableSize() (size int) { func (t *TokenBody) StableSize() (size int) {
@ -373,33 +342,21 @@ func (t *TokenBody) Unmarshal(data []byte) error {
return t.FromGRPCMessage(m) return t.FromGRPCMessage(m)
} }
func (t *Token) StableMarshal(buf []byte) ([]byte, error) { func (t *Token) StableMarshal(buf []byte) []byte {
if t == nil { if t == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, t.StableSize()) buf = make([]byte, t.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(sessionTokenBodyField, buf[offset:], t.body) offset += proto.NestedStructureMarshal(sessionTokenBodyField, buf[offset:], t.body)
if err != nil { proto.NestedStructureMarshal(sessionTokenSignatureField, buf[offset:], t.sig)
return nil, err
}
offset += n return buf
_, err = proto.NestedStructureMarshal(sessionTokenSignatureField, buf[offset:], t.sig)
if err != nil {
return nil, err
}
return buf, nil
} }
func (t *Token) StableSize() (size int) { func (t *Token) StableSize() (size int) {
@ -422,63 +379,31 @@ func (t *Token) Unmarshal(data []byte) error {
return t.FromGRPCMessage(m) return t.FromGRPCMessage(m)
} }
func (r *RequestMetaHeader) StableMarshal(buf []byte) ([]byte, error) { func (r *RequestMetaHeader) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(reqMetaHeaderVersionField, buf[offset:], r.version)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(reqMetaHeaderVersionField, buf[offset:], r.version)
offset += proto.UInt64Marshal(reqMetaHeaderEpochField, buf[offset:], r.epoch) offset += proto.UInt64Marshal(reqMetaHeaderEpochField, buf[offset:], r.epoch)
offset += proto.UInt32Marshal(reqMetaHeaderTTLField, buf[offset:], r.ttl) offset += proto.UInt32Marshal(reqMetaHeaderTTLField, buf[offset:], r.ttl)
for i := range r.xHeaders { for i := range r.xHeaders {
n, err = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i]) offset += proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i])
if err != nil {
return nil, err
}
offset += n
} }
n, err = proto.NestedStructureMarshal(reqMetaHeaderSessionTokenField, buf[offset:], r.sessionToken) offset += proto.NestedStructureMarshal(reqMetaHeaderSessionTokenField, buf[offset:], r.sessionToken)
if err != nil { offset += proto.NestedStructureMarshal(reqMetaHeaderBearerTokenField, buf[offset:], r.bearerToken)
return nil, err offset += proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf[offset:], r.origin)
}
offset += n
n, err = proto.NestedStructureMarshal(reqMetaHeaderBearerTokenField, buf[offset:], r.bearerToken)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf[offset:], r.origin)
if err != nil {
return nil, err
}
offset += n
proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf[offset:], r.netMagic) proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf[offset:], r.netMagic)
return buf, nil return buf
} }
func (r *RequestMetaHeader) StableSize() (size int) { func (r *RequestMetaHeader) StableSize() (size int) {
@ -514,47 +439,23 @@ func (r *RequestMetaHeader) Unmarshal(data []byte) error {
return r.FromGRPCMessage(m) return r.FromGRPCMessage(m)
} }
func (r *RequestVerificationHeader) StableMarshal(buf []byte) ([]byte, error) { func (r *RequestVerificationHeader) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(reqVerifHeaderBodySignatureField, buf[offset:], r.bodySig) offset += proto.NestedStructureMarshal(reqVerifHeaderBodySignatureField, buf[offset:], r.bodySig)
if err != nil { offset += proto.NestedStructureMarshal(reqVerifHeaderMetaSignatureField, buf[offset:], r.metaSig)
return nil, err offset += proto.NestedStructureMarshal(reqVerifHeaderOriginSignatureField, buf[offset:], r.originSig)
} proto.NestedStructureMarshal(reqVerifHeaderOriginField, buf[offset:], r.origin)
offset += n return buf
n, err = proto.NestedStructureMarshal(reqVerifHeaderMetaSignatureField, buf[offset:], r.metaSig)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(reqVerifHeaderOriginSignatureField, buf[offset:], r.originSig)
if err != nil {
return nil, err
}
offset += n
_, err = proto.NestedStructureMarshal(reqVerifHeaderOriginField, buf[offset:], r.origin)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *RequestVerificationHeader) StableSize() (size int) { func (r *RequestVerificationHeader) StableSize() (size int) {
@ -579,52 +480,29 @@ func (r *RequestVerificationHeader) Unmarshal(data []byte) error {
return r.FromGRPCMessage(m) return r.FromGRPCMessage(m)
} }
func (r *ResponseMetaHeader) StableMarshal(buf []byte) ([]byte, error) { func (r *ResponseMetaHeader) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(respMetaHeaderVersionField, buf[offset:], r.version)
if err != nil {
return nil, err
}
offset += n
offset += proto.NestedStructureMarshal(respMetaHeaderVersionField, buf[offset:], r.version)
offset += proto.UInt64Marshal(respMetaHeaderEpochField, buf[offset:], r.epoch) offset += proto.UInt64Marshal(respMetaHeaderEpochField, buf[offset:], r.epoch)
offset += proto.UInt32Marshal(respMetaHeaderTTLField, buf[offset:], r.ttl) offset += proto.UInt32Marshal(respMetaHeaderTTLField, buf[offset:], r.ttl)
for i := range r.xHeaders { for i := range r.xHeaders {
n, err = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i]) offset += proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i])
if err != nil {
return nil, err
}
offset += n
} }
n, err = proto.NestedStructureMarshal(respMetaHeaderOriginField, buf[offset:], r.origin) offset += proto.NestedStructureMarshal(respMetaHeaderOriginField, buf[offset:], r.origin)
if err != nil { proto.NestedStructureMarshal(respMetaHeaderStatusField, buf[offset:], r.status)
return nil, err
}
offset += n return buf
_, err = proto.NestedStructureMarshal(respMetaHeaderStatusField, buf[offset:], r.status)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *ResponseMetaHeader) StableSize() (size int) { func (r *ResponseMetaHeader) StableSize() (size int) {
@ -658,47 +536,23 @@ func (r *ResponseMetaHeader) Unmarshal(data []byte) error {
return r.FromGRPCMessage(m) return r.FromGRPCMessage(m)
} }
func (r *ResponseVerificationHeader) StableMarshal(buf []byte) ([]byte, error) { func (r *ResponseVerificationHeader) StableMarshal(buf []byte) []byte {
if r == nil { if r == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, r.StableSize()) buf = make([]byte, r.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = proto.NestedStructureMarshal(respVerifHeaderBodySignatureField, buf[offset:], r.bodySig) offset += proto.NestedStructureMarshal(respVerifHeaderBodySignatureField, buf[offset:], r.bodySig)
if err != nil { offset += proto.NestedStructureMarshal(respVerifHeaderMetaSignatureField, buf[offset:], r.metaSig)
return nil, err offset += proto.NestedStructureMarshal(respVerifHeaderOriginSignatureField, buf[offset:], r.originSig)
} proto.NestedStructureMarshal(respVerifHeaderOriginField, buf[offset:], r.origin)
offset += n return buf
n, err = proto.NestedStructureMarshal(respVerifHeaderMetaSignatureField, buf[offset:], r.metaSig)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(respVerifHeaderOriginSignatureField, buf[offset:], r.originSig)
if err != nil {
return nil, err
}
offset += n
_, err = proto.NestedStructureMarshal(respVerifHeaderOriginField, buf[offset:], r.origin)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *ResponseVerificationHeader) StableSize() (size int) { func (r *ResponseVerificationHeader) StableSize() (size int) {

View file

@ -28,7 +28,7 @@ type serviceResponse interface {
} }
type stableMarshaler interface { type stableMarshaler interface {
StableMarshal([]byte) ([]byte, error) StableMarshal([]byte) []byte
StableSize() int StableSize() int
} }
@ -117,7 +117,7 @@ func (r *responseVerificationHeader) setOrigin(m stableMarshaler) {
func (s StableMarshalerWrapper) ReadSignedData(buf []byte) ([]byte, error) { func (s StableMarshalerWrapper) ReadSignedData(buf []byte) ([]byte, error) {
if s.SM != nil { if s.SM != nil {
return s.SM.StableMarshal(buf) return s.SM.StableMarshal(buf), nil
} }
return nil, nil return nil, nil

View file

@ -12,9 +12,9 @@ const (
detailValueFNum detailValueFNum
) )
func (x *Detail) StableMarshal(buf []byte) ([]byte, error) { func (x *Detail) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
@ -24,9 +24,9 @@ func (x *Detail) StableMarshal(buf []byte) ([]byte, error) {
var offset int var offset int
offset += protoutil.UInt32Marshal(detailIDFNum, buf[offset:], x.id) offset += protoutil.UInt32Marshal(detailIDFNum, buf[offset:], x.id)
offset += protoutil.BytesMarshal(detailValueFNum, buf[offset:], x.val) protoutil.BytesMarshal(detailValueFNum, buf[offset:], x.val)
return buf, nil return buf
} }
func (x *Detail) StableSize() (size int) { func (x *Detail) StableSize() (size int) {
@ -47,40 +47,25 @@ const (
statusDetailsFNum statusDetailsFNum
) )
func (x *Status) StableMarshal(buf []byte) ([]byte, error) { func (x *Status) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += protoutil.UInt32Marshal(statusCodeFNum, buf[offset:], CodeToGRPC(x.code)) offset += protoutil.UInt32Marshal(statusCodeFNum, buf[offset:], CodeToGRPC(x.code))
if err != nil {
return nil, err
}
offset += protoutil.StringMarshal(statusMsgFNum, buf[offset:], x.msg) offset += protoutil.StringMarshal(statusMsgFNum, buf[offset:], x.msg)
if err != nil {
return nil, err
}
for i := range x.details { for i := range x.details {
n, err = protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i]) offset += protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
func (x *Status) StableSize() (size int) { func (x *Status) StableSize() (size int) {

View file

@ -16,37 +16,23 @@ const (
// StableMarshal marshals unified storage group structure in a protobuf // StableMarshal marshals unified storage group structure in a protobuf
// compatible way without field order shuffle. // compatible way without field order shuffle.
func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) { func (s *StorageGroup) StableMarshal(buf []byte) []byte {
if s == nil { if s == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.StableSize()) buf = make([]byte, s.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += proto.UInt64Marshal(sizeField, buf[offset:], s.size) offset += proto.UInt64Marshal(sizeField, buf[offset:], s.size)
offset += proto.NestedStructureMarshal(hashField, buf[offset:], s.hash)
n, err = proto.NestedStructureMarshal(hashField, buf[offset:], s.hash)
if err != nil {
return nil, err
}
offset += n
offset += proto.UInt64Marshal(expirationField, buf[offset:], s.exp) offset += proto.UInt64Marshal(expirationField, buf[offset:], s.exp)
refs.ObjectIDNestedListMarshal(objectIDsField, buf[offset:], s.members)
_, err = refs.ObjectIDNestedListMarshal(objectIDsField, buf[offset:], s.members) return buf
if err != nil {
return nil, err
}
return buf, nil
} }
// StableSize of storage group structure marshalled by StableMarshal function. // StableSize of storage group structure marshalled by StableMarshal function.

View file

@ -105,33 +105,21 @@ const (
// StableMarshal marshals Info to NeoFS API V2 binary format (Protocol Buffers with direct field order). // StableMarshal marshals Info to NeoFS API V2 binary format (Protocol Buffers with direct field order).
// //
// Returns a slice of recorded data. Data is written to the provided buffer if there is enough space. // Returns a slice of recorded data. Data is written to the provided buffer if there is enough space.
func (x *Info) StableMarshal(buf []byte) ([]byte, error) { func (x *Info) StableMarshal(buf []byte) []byte {
if x == nil { if x == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var ( var offset int
offset, n int
err error
)
n, err = protoutil.NestedStructureMarshal(subnetInfoIDFNum, buf[offset:], x.id) offset += protoutil.NestedStructureMarshal(subnetInfoIDFNum, buf[offset:], x.id)
if err != nil { protoutil.NestedStructureMarshal(subnetInfoOwnerFNum, buf[offset:], x.owner)
return nil, err
}
offset += n return buf
_, err = protoutil.NestedStructureMarshal(subnetInfoOwnerFNum, buf[offset:], x.owner)
if err != nil {
return nil, err
}
return buf, nil
} }
// StableSize returns the number of bytes required to write Info in NeoFS API V2 binary format (see StableMarshal). // StableSize returns the number of bytes required to write Info in NeoFS API V2 binary format (see StableMarshal).

View file

@ -14,33 +14,25 @@ const (
// StableMarshal marshals unified tombstone message in a protobuf // StableMarshal marshals unified tombstone message in a protobuf
// compatible way without field order shuffle. // compatible way without field order shuffle.
func (s *Tombstone) StableMarshal(buf []byte) ([]byte, error) { func (s *Tombstone) StableMarshal(buf []byte) []byte {
if s == nil { if s == nil {
return []byte{}, nil return []byte{}
} }
if buf == nil { if buf == nil {
buf = make([]byte, s.StableSize()) buf = make([]byte, s.StableSize())
} }
var ( var offset int
offset, n int
err error
)
offset += proto.UInt64Marshal(expFNum, buf[offset:], s.exp) offset += proto.UInt64Marshal(expFNum, buf[offset:], s.exp)
offset += proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID) offset += proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID)
for i := range s.members { for i := range s.members {
n, err = proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i]) offset += proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i])
if err != nil {
return nil, err
}
offset += n
} }
return buf, nil return buf
} }
// StableSize returns size of tombstone message marshalled by StableMarshal function. // StableSize returns size of tombstone message marshalled by StableMarshal function.

View file

@ -15,7 +15,7 @@ import (
type ( type (
stableMarshaller interface { stableMarshaller interface {
StableMarshal([]byte) ([]byte, error) StableMarshal([]byte) []byte
StableSize() int StableSize() int
} }
) )
@ -296,9 +296,9 @@ func NestedStructurePrefix(field int64) (prefix uint64, ln int) {
return prefix, VarUIntSize(prefix) return prefix, VarUIntSize(prefix)
} }
func NestedStructureMarshal(field int64, buf []byte, v stableMarshaller) (int, error) { func NestedStructureMarshal(field int64, buf []byte, v stableMarshaller) int {
if v == nil || reflect.ValueOf(v).IsNil() { if v == nil || reflect.ValueOf(v).IsNil() {
return 0, nil return 0
} }
prefix, _ := NestedStructurePrefix(field) prefix, _ := NestedStructurePrefix(field)
@ -306,13 +306,9 @@ func NestedStructureMarshal(field int64, buf []byte, v stableMarshaller) (int, e
n := v.StableSize() n := v.StableSize()
offset += binary.PutUvarint(buf[offset:], uint64(n)) offset += binary.PutUvarint(buf[offset:], uint64(n))
v.StableMarshal(buf[offset:])
_, err := v.StableMarshal(buf[offset:]) return offset + n
if err != nil {
return 0, err
}
return offset + n, nil
} }
func NestedStructureSize(field int64, v stableMarshaller) (size int) { func NestedStructureSize(field int64, v stableMarshaller) (size int) {