forked from TrueCloudLab/frostfs-api-go
Airat Arifullin
f0642d7f13
* Add plugin option for protogen in Makefile * Fix the generator for the plugin in util/protogen * Fix marshaler.go for refs Signed-off-by: Airat Arifullin a.arifullin@yadro.com
141 lines
3.5 KiB
Go
141 lines
3.5 KiB
Go
package refs
|
|
|
|
import (
|
|
"encoding/binary"
|
|
|
|
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"
|
|
)
|
|
|
|
const (
|
|
ownerIDValField = 1
|
|
|
|
containerIDValField = 1
|
|
|
|
objectIDValField = 1
|
|
|
|
addressContainerField = 1
|
|
addressObjectField = 2
|
|
|
|
checksumTypeField = 1
|
|
checksumValueField = 2
|
|
|
|
signatureKeyField = 1
|
|
signatureValueField = 2
|
|
signatureSchemeField = 3
|
|
|
|
versionMajorField = 1
|
|
versionMinorField = 2
|
|
)
|
|
|
|
func (o *OwnerID) StableMarshal(buf []byte) []byte {
|
|
return message.StableMarshal[*refs.OwnerID](o, buf)
|
|
}
|
|
|
|
func (o *OwnerID) StableSize() int {
|
|
return message.StableSize[*refs.OwnerID](o)
|
|
}
|
|
|
|
func (o *OwnerID) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(o, data, new(refs.OwnerID))
|
|
}
|
|
|
|
func (c *ContainerID) StableMarshal(buf []byte) []byte {
|
|
return message.StableMarshal[*refs.ContainerID](c, buf)
|
|
}
|
|
|
|
func (c *ContainerID) StableSize() int {
|
|
return message.StableSize[*refs.ContainerID](c)
|
|
}
|
|
|
|
func (c *ContainerID) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(c, data, new(refs.ContainerID))
|
|
}
|
|
|
|
func (o *ObjectID) StableMarshal(buf []byte) []byte {
|
|
return message.StableMarshal[*refs.ObjectID](o, buf)
|
|
}
|
|
|
|
// ObjectIDNestedListSize returns byte length of nested
|
|
// repeated ObjectID field with fNum number.
|
|
func ObjectIDNestedListSize(fNum int64, ids []ObjectID) (sz int) {
|
|
// TODO (aarifullin): remove this method when all marshalers are refactored
|
|
for i := range ids {
|
|
sz += proto.NestedStructureSize(fNum, &ids[i])
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (o *ObjectID) StableSize() int {
|
|
return message.StableSize[*refs.ObjectID](o)
|
|
}
|
|
|
|
// ObjectIDNestedListMarshal writes protobuf repeated ObjectID field
|
|
// with fNum number to buf.
|
|
func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int) {
|
|
// TODO (aarifullin): remove this method when all marshalers are refactored
|
|
prefix, _ := proto.NestedStructurePrefix(fNum)
|
|
for i := range ids {
|
|
off += binary.PutUvarint(buf[off:], prefix)
|
|
|
|
n := ids[i].StableSize()
|
|
off += binary.PutUvarint(buf[off:], uint64(n))
|
|
off += proto.BytesMarshal(objectIDValField, buf[off:], ids[i].val)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (o *ObjectID) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(o, data, new(refs.ObjectID))
|
|
}
|
|
|
|
func (a *Address) StableMarshal(buf []byte) []byte {
|
|
return message.StableMarshal[*refs.Address](a, buf)
|
|
}
|
|
|
|
func (a *Address) StableSize() (size int) {
|
|
return message.StableSize[*refs.Address](a)
|
|
}
|
|
|
|
func (a *Address) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(a, data, new(refs.Address))
|
|
}
|
|
|
|
func (c *Checksum) StableMarshal(buf []byte) []byte {
|
|
return message.StableMarshal[*refs.Checksum](c, buf)
|
|
}
|
|
|
|
func (c *Checksum) StableSize() (size int) {
|
|
return message.StableSize[*refs.Checksum](c)
|
|
}
|
|
|
|
func (c *Checksum) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(c, data, new(refs.Checksum))
|
|
}
|
|
|
|
func (s *Signature) StableMarshal(buf []byte) []byte {
|
|
return message.StableMarshal[*refs.Signature](s, buf)
|
|
}
|
|
|
|
func (s *Signature) StableSize() (size int) {
|
|
return message.StableSize[*refs.Signature](s)
|
|
}
|
|
|
|
func (s *Signature) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(s, data, new(refs.Signature))
|
|
}
|
|
|
|
func (v *Version) StableMarshal(buf []byte) []byte {
|
|
return message.StableMarshal[*refs.Version](v, buf)
|
|
}
|
|
|
|
func (v *Version) StableSize() (size int) {
|
|
return message.StableSize[*refs.Version](v)
|
|
}
|
|
|
|
func (v *Version) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(v, data, new(refs.Version))
|
|
}
|