2020-08-18 13:48:58 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2020-11-13 12:14:39 +00:00
|
|
|
protoutil "github.com/nspcc-dev/neofs-api-go/util/proto"
|
|
|
|
container "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
|
|
|
|
"google.golang.org/protobuf/proto"
|
2020-08-18 13:48:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
attributeKeyField = 1
|
|
|
|
attributeValueField = 2
|
|
|
|
|
|
|
|
containerVersionField = 1
|
|
|
|
containerOwnerField = 2
|
|
|
|
containerNonceField = 3
|
|
|
|
containerBasicACLField = 4
|
|
|
|
containerAttributesField = 5
|
|
|
|
containerPlacementField = 6
|
|
|
|
|
|
|
|
putReqBodyContainerField = 1
|
|
|
|
putReqBodySignatureField = 2
|
|
|
|
|
|
|
|
putRespBodyIDField = 1
|
|
|
|
|
|
|
|
deleteReqBodyIDField = 1
|
|
|
|
deleteReqBodySignatureField = 2
|
|
|
|
|
|
|
|
getReqBodyIDField = 1
|
|
|
|
|
|
|
|
getRespBodyContainerField = 1
|
|
|
|
|
|
|
|
listReqBodyOwnerField = 1
|
|
|
|
|
|
|
|
listRespBodyIDsField = 1
|
|
|
|
|
|
|
|
setEACLReqBodyTableField = 1
|
|
|
|
setEACLReqBodySignatureField = 2
|
|
|
|
|
|
|
|
getEACLReqBodyIDField = 1
|
|
|
|
|
|
|
|
getEACLRespBodyTableField = 1
|
|
|
|
getEACLRespBodySignatureField = 2
|
|
|
|
)
|
|
|
|
|
|
|
|
func (a *Attribute) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if a == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, a.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
offset, n int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err = protoutil.StringMarshal(attributeValueField, buf[offset:], a.val)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Attribute) StableSize() (size int) {
|
|
|
|
if a == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.StringSize(attributeKeyField, a.key)
|
|
|
|
size += protoutil.StringSize(attributeValueField, a.val)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
func (a *Attribute) Unmarshal(data []byte) error {
|
|
|
|
m := new(container.Container_Attribute)
|
|
|
|
if err := proto.Unmarshal(data, m); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*a = *AttributeFromGRPCMessage(m)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-18 13:48:58 +00:00
|
|
|
func (c *Container) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if c == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, c.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
offset, n int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.NestedStructureMarshal(containerVersionField, buf[offset:], c.version)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.NestedStructureMarshal(containerOwnerField, buf[offset:], c.ownerID)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
|
|
|
for i := range c.attr {
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], c.attr[i])
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err = protoutil.NestedStructureMarshal(containerPlacementField, buf[offset:], c.policy)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Container) StableSize() (size int) {
|
|
|
|
if c == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(containerVersionField, c.version)
|
|
|
|
size += protoutil.NestedStructureSize(containerOwnerField, c.ownerID)
|
|
|
|
size += protoutil.BytesSize(containerNonceField, c.nonce)
|
|
|
|
size += protoutil.UInt32Size(containerBasicACLField, c.basicACL)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
for i := range c.attr {
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(containerAttributesField, c.attr[i])
|
2020-08-18 13:48:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(containerPlacementField, c.policy)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:21:34 +00:00
|
|
|
func (c *Container) Unmarshal(data []byte) error {
|
|
|
|
m := new(container.Container)
|
|
|
|
if err := proto.Unmarshal(data, m); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*c = *ContainerFromGRPCMessage(m)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-18 13:48:58 +00:00
|
|
|
func (r *PutRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
offset, n int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.NestedStructureMarshal(putReqBodyContainerField, buf[offset:], r.cnr)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err = protoutil.NestedStructureMarshal(putReqBodySignatureField, buf[offset:], r.sig)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *PutRequestBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(putReqBodyContainerField, r.cnr)
|
|
|
|
size += protoutil.NestedStructureSize(putReqBodySignatureField, r.sig)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *PutResponseBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err = protoutil.NestedStructureMarshal(putRespBodyIDField, buf, r.cid)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *PutResponseBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(putRespBodyIDField, r.cid)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *DeleteRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
offset, n int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.NestedStructureMarshal(deleteReqBodyIDField, buf[offset:], r.cid)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err = protoutil.NestedStructureMarshal(deleteReqBodySignatureField, buf[offset:], r.sig)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *DeleteRequestBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(deleteReqBodyIDField, r.cid)
|
|
|
|
size += protoutil.NestedStructureSize(deleteReqBodySignatureField, r.sig)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *DeleteResponseBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *DeleteResponseBody) StableSize() (size int) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *GetRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err := protoutil.NestedStructureMarshal(getReqBodyIDField, buf, r.cid)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *GetRequestBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(getReqBodyIDField, r.cid)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *GetResponseBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err := protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *GetResponseBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(getRespBodyContainerField, r.cnr)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ListRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err := protoutil.NestedStructureMarshal(listReqBodyOwnerField, buf, r.ownerID)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ListRequestBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(listReqBodyOwnerField, r.ownerID)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ListResponseBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
n, offset int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
for i := range r.cidList {
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], r.cidList[i])
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ListResponseBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range r.cidList {
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(listRespBodyIDsField, r.cidList[i])
|
2020-08-18 13:48:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *SetExtendedACLRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
offset, n int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.NestedStructureMarshal(setEACLReqBodyTableField, buf[offset:], r.eacl)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err = protoutil.NestedStructureMarshal(setEACLReqBodySignatureField, buf[offset:], r.sig)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *SetExtendedACLRequestBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(setEACLReqBodyTableField, r.eacl)
|
|
|
|
size += protoutil.NestedStructureSize(setEACLReqBodySignatureField, r.sig)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *SetExtendedACLResponseBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *SetExtendedACLResponseBody) StableSize() (size int) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *GetExtendedACLRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err := protoutil.NestedStructureMarshal(getEACLReqBodyIDField, buf, r.cid)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *GetExtendedACLRequestBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(getEACLReqBodyIDField, r.cid)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *GetExtendedACLResponseBody) StableMarshal(buf []byte) ([]byte, error) {
|
|
|
|
if r == nil {
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
offset, n int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
n, err = protoutil.NestedStructureMarshal(getEACLRespBodyTableField, buf[offset:], r.eacl)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += n
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
_, err = protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig)
|
2020-08-18 13:48:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *GetExtendedACLResponseBody) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:14:39 +00:00
|
|
|
size += protoutil.NestedStructureSize(getEACLRespBodyTableField, r.eacl)
|
|
|
|
size += protoutil.NestedStructureSize(getEACLRespBodySignatureField, r.sig)
|
2020-08-18 13:48:58 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|