[#1048] control: Add marshalling and setters to ListShards

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-12-17 18:23:05 +03:00 committed by Alex Vanin
parent a42b3d37f6
commit a6b3e16975
2 changed files with 267 additions and 0 deletions

View file

@ -594,3 +594,157 @@ func (x *DropObjectsResponse) ReadSignedData(buf []byte) ([]byte, error) {
func (x *DropObjectsResponse) SignedDataSize() int {
return x.GetBody().StableSize()
}
// StableMarshal reads binary representation of list shards request body
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *ListShardsRequest_Body) StableMarshal(buf []byte) ([]byte, error) {
return buf, nil
}
// StableSize returns binary size of list shards request body
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *ListShardsRequest_Body) StableSize() int {
return 0
}
// SetBody sets list shards request body.
func (x *ListShardsRequest) SetBody(v *ListShardsRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetSignature sets signature of the health check request body.
func (x *ListShardsRequest) SetSignature(body *Signature) {
if x != nil {
x.Signature = body
}
}
// ReadSignedData reads signed data of list shard request to buf.
//
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *ListShardsRequest) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf)
}
// SignedDataSize returns binary size of the signed data
// of list shard request.
//
// Structures with the same field values have the same signed data size.
func (x *ListShardsRequest) SignedDataSize() int {
return x.GetBody().StableSize()
}
// SetShards sets shards of the storage node.
func (x *ListShardsResponse_Body) SetShards(v []*ShardInfo) {
if x != nil {
x.Shards = v
}
}
const (
_ = iota
listShardsRespBodyShardsFNum
)
// StableMarshal reads binary representation of list shards response body
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *ListShardsResponse_Body) StableMarshal(buf []byte) ([]byte, error) {
if x == nil {
return []byte{}, nil
}
if sz := x.StableSize(); len(buf) < sz {
buf = make([]byte, sz)
}
var (
offset, n int
err error
)
for i := range x.Shards {
n, err = proto.NestedStructureMarshal(listShardsRespBodyShardsFNum, buf[offset:], x.Shards[i])
if err != nil {
return nil, err
}
offset += n
}
return buf, nil
}
// StableSize returns binary size of list shards response body
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *ListShardsResponse_Body) StableSize() int {
if x == nil {
return 0
}
size := 0
for i := range x.Shards {
size += proto.NestedStructureSize(listShardsRespBodyShardsFNum, x.Shards[i])
}
return size
}
// SetBody sets list shards response body.
func (x *ListShardsResponse) SetBody(v *ListShardsResponse_Body) {
if x != nil {
x.Body = v
}
}
// SetSignature sets signature of the list shards response body.
func (x *ListShardsResponse) SetSignature(v *Signature) {
if x != nil {
x.Signature = v
}
}
// ReadSignedData reads signed data of list shards response to buf.
//
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *ListShardsResponse) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf)
}
// SignedDataSize returns binary size of the signed data
// of list shards response.
//
// Structures with the same field values have the same signed data size.
func (x *ListShardsResponse) SignedDataSize() int {
return x.GetBody().StableSize()
}

View file

@ -316,3 +316,116 @@ func (x *Netmap) MarshalJSON() ([]byte, error) {
EmitUnpopulated: true,
}.Marshal(x)
}
// SetID sets identificator of the shard.
func (x *ShardInfo) SetID(v []byte) {
x.Shard_ID = v
}
// SetMetabasePath sets path to shard's metabase.
func (x *ShardInfo) SetMetabasePath(v string) {
x.MetabasePath = v
}
// SetBlobstorePath sets path to shard's blobstore.
func (x *ShardInfo) SetBlobstorePath(v string) {
x.BlobstorePath = v
}
// SetWriteCachePath sets path to shard's write-cache.
func (x *ShardInfo) SetWriteCachePath(v string) {
x.WritecachePath = v
}
// SetMode sets path to shard's work mode.
func (x *ShardInfo) SetMode(v ShardMode) {
x.Mode = v
}
const (
_ = iota
shardInfoIDFNum
shardInfoMetabaseFNum
shardInfoBlobstoreFNum
shardInfoWriteCacheFNum
shardInfoModeFNum
)
// StableSize returns binary size of shard information
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *ShardInfo) StableSize() int {
if x == nil {
return 0
}
size := 0
size += proto.BytesSize(shardInfoIDFNum, x.Shard_ID)
size += proto.StringSize(shardInfoMetabaseFNum, x.MetabasePath)
size += proto.StringSize(shardInfoBlobstoreFNum, x.BlobstorePath)
size += proto.StringSize(shardInfoWriteCacheFNum, x.WritecachePath)
size += proto.EnumSize(shardInfoModeFNum, int32(x.Mode))
return size
}
// StableMarshal reads binary representation of shard information
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *ShardInfo) StableMarshal(buf []byte) ([]byte, error) {
if x == nil {
return []byte{}, nil
}
if sz := x.StableSize(); len(buf) < sz {
buf = make([]byte, sz)
}
var (
offset, n int
err error
)
n, err = proto.BytesMarshal(shardInfoIDFNum, buf[offset:], x.Shard_ID)
if err != nil {
return nil, err
}
offset += n
n, err = proto.StringMarshal(shardInfoMetabaseFNum, buf[offset:], x.MetabasePath)
if err != nil {
return nil, err
}
offset += n
n, err = proto.StringMarshal(shardInfoBlobstoreFNum, buf[offset:], x.BlobstorePath)
if err != nil {
return nil, err
}
offset += n
n, err = proto.StringMarshal(shardInfoWriteCacheFNum, buf[offset:], x.WritecachePath)
if err != nil {
return nil, err
}
offset += n
_, err = proto.EnumMarshal(shardInfoModeFNum, buf[offset:], int32(x.Mode))
if err != nil {
return nil, err
}
return buf, nil
}