frostfs-api-go/container/service.go

61 lines
1.7 KiB
Go
Raw Normal View History

2019-11-18 13:34:06 +00:00
package container
import (
"bytes"
"encoding/binary"
2020-03-31 07:05:26 +00:00
"github.com/nspcc-dev/neofs-api-go/internal"
"github.com/nspcc-dev/neofs-api-go/refs"
2019-11-18 13:34:06 +00:00
"github.com/pkg/errors"
)
type (
// CID type alias.
CID = refs.CID
// UUID type alias.
UUID = refs.UUID
// OwnerID type alias.
OwnerID = refs.OwnerID
2019-11-21 09:34:54 +00:00
// MessageID type alias.
2019-11-18 13:34:06 +00:00
MessageID = refs.MessageID
)
2019-11-20 09:49:05 +00:00
const (
// ErrNotFound is raised when container could not be found.
ErrNotFound = internal.Error("could not find container")
)
2019-11-18 13:34:06 +00:00
// PrepareData prepares bytes representation of PutRequest to satisfy SignedRequest interface.
func (m *PutRequest) PrepareData() ([]byte, error) {
var (
err error
buf = new(bytes.Buffer)
capBytes = make([]byte, 8)
aclBytes = make([]byte, 4)
2019-11-18 13:34:06 +00:00
)
binary.BigEndian.PutUint64(capBytes, m.Capacity)
binary.BigEndian.PutUint32(capBytes, m.BasicACL)
2019-11-18 13:34:06 +00:00
if _, err = buf.Write(m.MessageID.Bytes()); err != nil {
return nil, errors.Wrap(err, "could not write message id")
} else if _, err = buf.Write(capBytes); err != nil {
return nil, errors.Wrap(err, "could not write capacity")
} else if _, err = buf.Write(m.OwnerID.Bytes()); err != nil {
return nil, errors.Wrap(err, "could not write pub")
} else if data, err := m.Rules.Marshal(); err != nil {
return nil, errors.Wrap(err, "could not marshal placement")
} else if _, err = buf.Write(data); err != nil {
return nil, errors.Wrap(err, "could not write placement")
} else if _, err = buf.Write(aclBytes); err != nil {
return nil, errors.Wrap(err, "could not write basic acl")
2019-11-18 13:34:06 +00:00
}
return buf.Bytes(), nil
}
// PrepareData prepares bytes representation of DeleteRequest to satisfy SignedRequest interface.
func (m *DeleteRequest) PrepareData() ([]byte, error) {
return m.CID.Bytes(), nil
}