2020-08-17 10:41:09 +00:00
|
|
|
package refs
|
|
|
|
|
|
|
|
import (
|
2022-04-05 08:33:36 +00:00
|
|
|
"encoding/binary"
|
|
|
|
|
2023-03-07 10:38:56 +00:00
|
|
|
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
|
2023-08-02 13:53:47 +00:00
|
|
|
"google.golang.org/protobuf/encoding/protowire"
|
2020-08-17 10:41:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-08-18 07:42:47 +00:00
|
|
|
ownerIDValField = 1
|
2020-08-17 10:41:09 +00:00
|
|
|
|
2020-08-18 07:42:47 +00:00
|
|
|
containerIDValField = 1
|
2020-08-17 10:41:09 +00:00
|
|
|
|
2020-08-18 07:42:47 +00:00
|
|
|
objectIDValField = 1
|
2020-08-17 10:41:09 +00:00
|
|
|
|
2020-08-18 07:42:47 +00:00
|
|
|
addressContainerField = 1
|
|
|
|
addressObjectField = 2
|
2020-08-20 07:59:45 +00:00
|
|
|
|
|
|
|
checksumTypeField = 1
|
|
|
|
checksumValueField = 2
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2022-02-22 11:25:43 +00:00
|
|
|
signatureKeyField = 1
|
|
|
|
signatureValueField = 2
|
|
|
|
signatureSchemeField = 3
|
2020-08-20 09:43:47 +00:00
|
|
|
|
|
|
|
versionMajorField = 1
|
|
|
|
versionMinorField = 2
|
2020-08-17 10:41:09 +00:00
|
|
|
)
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (o *OwnerID) StableMarshal(buf []byte) []byte {
|
2020-08-17 10:41:09 +00:00
|
|
|
if o == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, o.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
proto.BytesMarshal(ownerIDValField, buf, o.val)
|
2020-08-17 10:41:09 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (o *OwnerID) StableSize() int {
|
|
|
|
if o == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2020-08-18 07:42:47 +00:00
|
|
|
|
|
|
|
return proto.BytesSize(ownerIDValField, o.val)
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 13:14:00 +00:00
|
|
|
func (o *OwnerID) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(o, data, new(refs.OwnerID))
|
2020-11-13 13:14:00 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (c *ContainerID) StableMarshal(buf []byte) []byte {
|
2020-08-17 10:41:09 +00:00
|
|
|
if c == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, c.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
proto.BytesMarshal(containerIDValField, buf, c.val)
|
2020-08-17 10:41:09 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ContainerID) StableSize() int {
|
|
|
|
if c == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2020-08-18 07:42:47 +00:00
|
|
|
|
|
|
|
return proto.BytesSize(containerIDValField, c.val)
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 13:07:32 +00:00
|
|
|
func (c *ContainerID) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(c, data, new(refs.ContainerID))
|
2020-11-13 13:07:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (o *ObjectID) StableMarshal(buf []byte) []byte {
|
2020-08-17 10:41:09 +00:00
|
|
|
if o == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, o.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
proto.BytesMarshal(objectIDValField, buf, o.val)
|
2020-08-17 10:41:09 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 07:51:45 +00:00
|
|
|
// ObjectIDNestedListSize returns byte length of nested
|
|
|
|
// repeated ObjectID field with fNum number.
|
2022-03-01 12:50:09 +00:00
|
|
|
func ObjectIDNestedListSize(fNum int64, ids []ObjectID) (sz int) {
|
2020-12-21 07:51:45 +00:00
|
|
|
for i := range ids {
|
2022-03-01 12:50:09 +00:00
|
|
|
sz += proto.NestedStructureSize(fNum, &ids[i])
|
2020-12-21 07:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-17 10:41:09 +00:00
|
|
|
func (o *ObjectID) StableSize() int {
|
|
|
|
if o == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-08-18 07:42:47 +00:00
|
|
|
return proto.BytesSize(objectIDValField, o.val)
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 07:51:45 +00:00
|
|
|
// ObjectIDNestedListMarshal writes protobuf repeated ObjectID field
|
|
|
|
// with fNum number to buf.
|
2022-04-05 08:24:34 +00:00
|
|
|
func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int) {
|
2023-08-02 13:53:47 +00:00
|
|
|
prefix := protowire.EncodeTag(protowire.Number(fNum), protowire.BytesType)
|
2020-12-21 07:51:45 +00:00
|
|
|
for i := range ids {
|
2022-04-25 18:24:19 +00:00
|
|
|
off += binary.PutUvarint(buf[off:], prefix)
|
2022-04-05 08:33:36 +00:00
|
|
|
|
|
|
|
n := ids[i].StableSize()
|
|
|
|
off += binary.PutUvarint(buf[off:], uint64(n))
|
2022-04-25 18:24:19 +00:00
|
|
|
off += proto.BytesMarshal(objectIDValField, buf[off:], ids[i].val)
|
2020-12-21 07:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-13 13:04:09 +00:00
|
|
|
func (o *ObjectID) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(o, data, new(refs.ObjectID))
|
2020-11-13 13:04:09 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (a *Address) StableMarshal(buf []byte) []byte {
|
2020-08-17 10:41:09 +00:00
|
|
|
if a == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, a.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
var offset int
|
2020-08-17 10:41:09 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += proto.NestedStructureMarshal(addressContainerField, buf[offset:], a.cid)
|
|
|
|
proto.NestedStructureMarshal(addressObjectField, buf[offset:], a.oid)
|
2020-08-17 10:41:09 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 10:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Address) StableSize() (size int) {
|
|
|
|
if a == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-08-18 07:42:47 +00:00
|
|
|
size += proto.NestedStructureSize(addressContainerField, a.cid)
|
|
|
|
size += proto.NestedStructureSize(addressObjectField, a.oid)
|
2020-08-17 10:41:09 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2020-11-13 12:58:53 +00:00
|
|
|
func (a *Address) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(a, data, new(refs.Address))
|
2020-09-02 11:40:20 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (c *Checksum) StableMarshal(buf []byte) []byte {
|
2020-08-20 07:59:45 +00:00
|
|
|
if c == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-20 07:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, c.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
var offset int
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ))
|
|
|
|
proto.BytesMarshal(checksumValueField, buf[offset:], c.sum)
|
2020-08-20 07:59:45 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-20 07:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Checksum) StableSize() (size int) {
|
|
|
|
if c == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
size += proto.EnumSize(checksumTypeField, int32(c.typ))
|
|
|
|
size += proto.BytesSize(checksumValueField, c.sum)
|
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2020-11-13 13:30:35 +00:00
|
|
|
func (c *Checksum) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(c, data, new(refs.Checksum))
|
2020-11-13 13:30:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (s *Signature) StableMarshal(buf []byte) []byte {
|
2020-08-20 09:43:47 +00:00
|
|
|
if s == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, s.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
var offset int
|
2022-02-22 11:25:43 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += proto.BytesMarshal(signatureKeyField, buf[offset:], s.key)
|
|
|
|
offset += proto.BytesMarshal(signatureValueField, buf[offset:], s.sign)
|
|
|
|
proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme))
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Signature) StableSize() (size int) {
|
|
|
|
if s == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
size += proto.BytesSize(signatureKeyField, s.key)
|
|
|
|
size += proto.BytesSize(signatureValueField, s.sign)
|
2022-02-22 11:25:43 +00:00
|
|
|
size += proto.EnumSize(signatureSchemeField, int32(s.scheme))
|
2020-08-20 09:43:47 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2020-11-13 13:23:41 +00:00
|
|
|
func (s *Signature) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(s, data, new(refs.Signature))
|
2020-11-13 13:23:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (v *Version) StableMarshal(buf []byte) []byte {
|
2020-08-20 09:43:47 +00:00
|
|
|
if v == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, v.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
var offset int
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += proto.UInt32Marshal(versionMajorField, buf[offset:], v.major)
|
|
|
|
proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor)
|
2020-08-20 09:43:47 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-20 09:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Version) StableSize() (size int) {
|
|
|
|
if v == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
size += proto.UInt32Size(versionMajorField, v.major)
|
|
|
|
size += proto.UInt32Size(versionMinorField, v.minor)
|
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
2020-11-13 13:19:16 +00:00
|
|
|
|
|
|
|
func (v *Version) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(v, data, new(refs.Version))
|
2020-11-13 13:19:16 +00:00
|
|
|
}
|