v2/container: Implement Container uni-structure

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-17 15:08:00 +03:00 committed by Stanislav Bogatyrev
parent 9f4d24b592
commit ae2e951b77
2 changed files with 241 additions and 0 deletions

104
v2/container/convert.go Normal file
View file

@ -0,0 +1,104 @@
package container
import (
container "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/service"
)
func AttributeToGRPCMessage(a *Attribute) *container.Container_Attribute {
if a == nil {
return nil
}
m := new(container.Container_Attribute)
m.SetKey(a.GetKey())
m.SetValue(a.GetValue())
return m
}
func AttributeFromGRPCMessage(m *container.Container_Attribute) *Attribute {
if m == nil {
return nil
}
a := new(Attribute)
a.SetKey(m.GetKey())
a.SetValue(m.GetValue())
return a
}
func ContainerToGRPCMessage(c *Container) *container.Container {
if c == nil {
return nil
}
m := new(container.Container)
m.SetVersion(
service.VersionToGRPCMessage(c.GetVersion()),
)
m.SetOwnerId(
refs.OwnerIDToGRPCMessage(c.GetOwnerID()),
)
m.SetNonce(c.GetNonce())
m.SetBasicAcl(c.GetBasicACL())
m.SetPlacementPolicy(
netmap.PlacementPolicyToGRPCMessage(c.GetPlacementPolicy()),
)
attr := c.GetAttributes()
attrMsg := make([]*container.Container_Attribute, 0, len(attr))
for i := range attr {
attrMsg = append(attrMsg, AttributeToGRPCMessage(attr[i]))
}
m.SetAttributes(attrMsg)
return m
}
func ContainerFromGRPCMessage(m *container.Container) *Container {
if m == nil {
return nil
}
c := new(Container)
c.SetVersion(
service.VersionFromGRPCMessage(m.GetVersion()),
)
c.SetOwnerID(
refs.OwnerIDFromGRPCMessage(m.GetOwnerId()),
)
c.SetNonce(m.GetNonce())
c.SetBasicACL(m.GetBasicAcl())
c.SetPlacementPolicy(
netmap.PlacementPolicyFromGRPCMessage(m.GetPlacementPolicy()),
)
attrMsg := m.GetAttributes()
attr := make([]*Attribute, 0, len(attrMsg))
for i := range attrMsg {
attr = append(attr, AttributeFromGRPCMessage(attrMsg[i]))
}
c.SetAttributes(attr)
return c
}

137
v2/container/types.go Normal file
View file

@ -0,0 +1,137 @@
package container
import (
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/service"
)
type Attribute struct {
key, val string
}
type Container struct {
version *service.Version
ownerID *refs.OwnerID
nonce []byte
basicACL uint32
attr []*Attribute
policy *netmap.PlacementPolicy
}
func (a *Attribute) GetKey() string {
if a != nil {
return a.key
}
return ""
}
func (a *Attribute) SetKey(v string) {
if a != nil {
a.key = v
}
}
func (a *Attribute) GetValue() string {
if a != nil {
return a.val
}
return ""
}
func (a *Attribute) SetValue(v string) {
if a != nil {
a.val = v
}
}
func (c *Container) GetVersion() *service.Version {
if c != nil {
return c.version
}
return nil
}
func (c *Container) SetVersion(v *service.Version) {
if c != nil {
c.version = v
}
}
func (c *Container) GetOwnerID() *refs.OwnerID {
if c != nil {
return c.ownerID
}
return nil
}
func (c *Container) SetOwnerID(v *refs.OwnerID) {
if c != nil {
c.ownerID = v
}
}
func (c *Container) GetNonce() []byte {
if c != nil {
return c.nonce
}
return nil
}
func (c *Container) SetNonce(v []byte) {
if c != nil {
c.nonce = v
}
}
func (c *Container) GetBasicACL() uint32 {
if c != nil {
return c.basicACL
}
return 0
}
func (c *Container) SetBasicACL(v uint32) {
if c != nil {
c.basicACL = v
}
}
func (c *Container) GetAttributes() []*Attribute {
if c != nil {
return c.attr
}
return nil
}
func (c *Container) SetAttributes(v []*Attribute) {
if c != nil {
c.attr = v
}
}
func (c *Container) GetPlacementPolicy() *netmap.PlacementPolicy {
if c != nil {
return c.policy
}
return nil
}
func (c *Container) SetPlacementPolicy(v *netmap.PlacementPolicy) {
if c != nil {
c.policy = v
}
}