2020-08-14 16:00:16 +00:00
|
|
|
package refs
|
|
|
|
|
|
|
|
import (
|
|
|
|
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
2021-11-16 17:30:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/grpc"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/message"
|
2020-08-14 16:00:16 +00:00
|
|
|
)
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (o *OwnerID) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *refs.OwnerID
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if o != nil {
|
|
|
|
m = new(refs.OwnerID)
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetValue(o.val)
|
|
|
|
}
|
2020-08-14 16:00:16 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (o *OwnerID) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*refs.OwnerID)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-14 16:00:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
o.val = v.GetValue()
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-14 16:00:16 +00:00
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *ContainerID) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *refs.ContainerID
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if c != nil {
|
|
|
|
m = new(refs.ContainerID)
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetValue(c.val)
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *ContainerID) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*refs.ContainerID)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 09:06:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
c.val = v.GetValue()
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-17 09:06:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func ContainerIDsToGRPCMessage(ids []*ContainerID) (res []*refs.ContainerID) {
|
|
|
|
if ids != nil {
|
|
|
|
res = make([]*refs.ContainerID, 0, len(ids))
|
|
|
|
|
|
|
|
for i := range ids {
|
|
|
|
res = append(res, ids[i].ToGRPCMessage().(*refs.ContainerID))
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func ContainerIDsFromGRPCMessage(idsV2 []*refs.ContainerID) (res []*ContainerID, err error) {
|
|
|
|
if idsV2 != nil {
|
|
|
|
res = make([]*ContainerID, 0, len(idsV2))
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range idsV2 {
|
|
|
|
var id *ContainerID
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if idsV2[i] != nil {
|
|
|
|
id = new(ContainerID)
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = id.FromGRPCMessage(idsV2[i])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
res = append(res, id)
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
2020-08-17 09:06:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (o *ObjectID) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *refs.ObjectID
|
2020-12-21 07:51:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if o != nil {
|
|
|
|
m = new(refs.ObjectID)
|
2020-12-21 07:51:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetValue(o.val)
|
2020-12-21 07:51:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return m
|
2020-12-21 07:51:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (o *ObjectID) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*refs.ObjectID)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-12-21 07:51:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
o.val = v.GetValue()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ObjectIDListToGRPCMessage(ids []*ObjectID) (res []*refs.ObjectID) {
|
|
|
|
if ids != nil {
|
|
|
|
res = make([]*refs.ObjectID, 0, len(ids))
|
2020-12-21 07:51:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range ids {
|
|
|
|
res = append(res, ids[i].ToGRPCMessage().(*refs.ObjectID))
|
|
|
|
}
|
2020-12-21 07:51:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
2020-12-21 07:51:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []*ObjectID, err error) {
|
|
|
|
if idsV2 != nil {
|
|
|
|
res = make([]*ObjectID, 0, len(idsV2))
|
|
|
|
|
|
|
|
for i := range idsV2 {
|
|
|
|
var id *ObjectID
|
|
|
|
|
|
|
|
if idsV2[i] != nil {
|
|
|
|
id = new(ObjectID)
|
|
|
|
|
|
|
|
err = id.FromGRPCMessage(idsV2[i])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res = append(res, id)
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Address) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *refs.Address
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if a != nil {
|
|
|
|
m = new(refs.Address)
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetContainerId(a.cid.ToGRPCMessage().(*refs.ContainerID))
|
|
|
|
m.SetObjectId(a.oid.ToGRPCMessage().(*refs.ObjectID))
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (a *Address) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*refs.Address)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 09:06:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
cid := v.GetContainerId()
|
|
|
|
if cid == nil {
|
|
|
|
a.cid = nil
|
|
|
|
} else {
|
|
|
|
if a.cid == nil {
|
|
|
|
a.cid = new(ContainerID)
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = a.cid.FromGRPCMessage(cid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
oid := v.GetObjectId()
|
|
|
|
if oid == nil {
|
|
|
|
a.oid = nil
|
|
|
|
} else {
|
|
|
|
if a.oid == nil {
|
|
|
|
a.oid = new(ObjectID)
|
|
|
|
}
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = a.oid.FromGRPCMessage(oid)
|
2020-08-20 07:59:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func ChecksumTypeToGRPC(t ChecksumType) refs.ChecksumType {
|
|
|
|
return refs.ChecksumType(t)
|
|
|
|
}
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func ChecksumTypeFromGRPC(t refs.ChecksumType) ChecksumType {
|
|
|
|
return ChecksumType(t)
|
2020-08-20 07:59:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *Checksum) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *refs.Checksum
|
|
|
|
|
|
|
|
if c != nil {
|
|
|
|
m = new(refs.Checksum)
|
|
|
|
|
|
|
|
m.SetChecksumType(ChecksumTypeToGRPC(c.typ))
|
|
|
|
m.SetSum(c.sum)
|
2020-08-20 07:59:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return m
|
|
|
|
}
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *Checksum) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*refs.Checksum)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
|
|
}
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
c.typ = ChecksumTypeFromGRPC(v.GetType())
|
|
|
|
c.sum = v.GetSum()
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 07:59:45 +00:00
|
|
|
}
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (v *Version) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *refs.Version
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if v != nil {
|
|
|
|
m = new(refs.Version)
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetMajor(v.major)
|
|
|
|
m.SetMinor(v.minor)
|
|
|
|
}
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return m
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (v *Version) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
ver, ok := m.(*refs.Version)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
v.major = ver.GetMajor()
|
|
|
|
v.minor = ver.GetMinor()
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (s *Signature) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *refs.Signature
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if s != nil {
|
|
|
|
m = new(refs.Signature)
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetKey(s.key)
|
|
|
|
m.SetSign(s.sign)
|
|
|
|
}
|
2020-08-20 09:43:47 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (s *Signature) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*refs.Signature)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, s)
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
s.key = v.GetKey()
|
|
|
|
s.sign = v.GetSign()
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
2021-11-18 13:32:09 +00:00
|
|
|
|
|
|
|
// ToGRPCMessage forms refs.SubnetID message and returns it as grpc.Message.
|
|
|
|
func (s *SubnetID) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *refs.SubnetID
|
|
|
|
|
|
|
|
if s != nil {
|
|
|
|
m = new(refs.SubnetID)
|
|
|
|
|
|
|
|
m.SetValue(s.value)
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromGRPCMessage restores Info from grpc.Message.
|
|
|
|
//
|
|
|
|
// Supported types:
|
|
|
|
// * refs.SubnetID.
|
|
|
|
func (s *SubnetID) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*refs.SubnetID)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.value = v.GetValue()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|