diff --git a/v2/container/convert.go b/v2/container/convert.go new file mode 100644 index 0000000..0ca1118 --- /dev/null +++ b/v2/container/convert.go @@ -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 +} diff --git a/v2/container/types.go b/v2/container/types.go new file mode 100644 index 0000000..bfb7530 --- /dev/null +++ b/v2/container/types.go @@ -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 + } +}