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
|
|
|
}
|
|
|
|
|
2022-03-02 08:18:59 +00:00
|
|
|
func ContainerIDsToGRPCMessage(ids []ContainerID) (res []*refs.ContainerID) {
|
2021-03-12 12:57:23 +00:00
|
|
|
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
|
|
|
|
2022-03-02 08:18:59 +00:00
|
|
|
func ContainerIDsFromGRPCMessage(idsV2 []*refs.ContainerID) (res []ContainerID, err error) {
|
2021-03-12 12:57:23 +00:00
|
|
|
if idsV2 != nil {
|
2022-03-02 08:18:59 +00:00
|
|
|
res = make([]ContainerID, len(idsV2))
|
2020-08-17 09:06:18 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range idsV2 {
|
|
|
|
if idsV2[i] != nil {
|
2022-03-02 08:18:59 +00:00
|
|
|
err = res[i].FromGRPCMessage(idsV2[i])
|
2021-03-12 12:57:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
2022-03-01 12:50:09 +00:00
|
|
|
func ObjectIDListToGRPCMessage(ids []ObjectID) (res []*refs.ObjectID) {
|
2021-03-12 12:57:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-03-01 12:50:09 +00:00
|
|
|
func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []ObjectID, err error) {
|
2021-03-12 12:57:23 +00:00
|
|
|
if idsV2 != nil {
|
2022-03-01 12:50:09 +00:00
|
|
|
res = make([]ObjectID, len(idsV2))
|
2021-03-12 12:57:23 +00:00
|
|
|
|
|
|
|
for i := range idsV2 {
|
|
|
|
if idsV2[i] != nil {
|
2022-03-01 12:50:09 +00:00
|
|
|
err = res[i].FromGRPCMessage(idsV2[i])
|
2021-03-12 12:57:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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)
|
2022-02-22 11:25:43 +00:00
|
|
|
m.SetScheme(refs.SignatureScheme(s.scheme))
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
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()
|
2022-02-22 11:25:43 +00:00
|
|
|
s.scheme = SignatureScheme(v.GetScheme())
|
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:
|
2022-09-15 05:20:13 +00:00
|
|
|
// - refs.SubnetID.
|
2021-11-18 13:32:09 +00:00
|
|
|
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
|
|
|
|
}
|