[#45] api-go: Add PutSingle request wrappers

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-06-30 15:00:51 +03:00
parent b17995a238
commit 2cb57a8835
6 changed files with 157 additions and 0 deletions

View file

@ -2042,3 +2042,75 @@ func (r *GetRangeHashResponse) FromGRPCMessage(m grpc.Message) error {
return r.ResponseHeaders.FromMessage(v)
}
func (r *PutSingleRequestBody) ToGRPCMessage() grpc.Message {
var m *object.PutSingleRequest_Body
if r != nil {
m = new(object.PutSingleRequest_Body)
m.SetObject(r.GetObject().ToGRPCMessage().(*object.Object))
m.SetCopiesNumber(r.GetCopiesNumber())
}
return m
}
func (r *PutSingleRequestBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*object.PutSingleRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
if v.GetObject() == nil {
r.object = nil
} else {
if r.object == nil {
r.object = new(Object)
}
err := r.object.FromGRPCMessage(v.GetObject())
if err != nil {
return err
}
}
r.copyNum = v.GetCopiesNumber()
return nil
}
func (r *PutSingleRequest) ToGRPCMessage() grpc.Message {
var m *object.PutSingleRequest
if r != nil {
m = new(object.PutSingleRequest)
m.SetBody(r.body.ToGRPCMessage().(*object.PutSingleRequest_Body))
r.RequestHeaders.ToMessage(m)
}
return m
}
func (r *PutSingleRequest) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*object.PutSingleRequest)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
body := v.GetBody()
if body == nil {
r.body = nil
} else {
if r.body == nil {
r.body = new(PutSingleRequestBody)
}
err := r.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return r.RequestHeaders.FromMessage(v)
}

View file

@ -495,3 +495,28 @@ func (m *GetRangeHashResponse) SetMetaHeader(v *session.ResponseMetaHeader) {
func (m *GetRangeHashResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) {
m.VerifyHeader = v
}
// SetObject set object of the body.
func (m *PutSingleRequest_Body) SetObject(o *Object) {
m.Object = o
}
// SetCopiesNumber sets copies number of the body.
func (m *PutSingleRequest_Body) SetCopiesNumber(v []uint32) {
m.CopiesNumber = v
}
// SetBody sets body of the request.
func (m *PutSingleRequest) SetBody(b *PutSingleRequest_Body) {
m.Body = b
}
// SetMetaHeader sets meta header of the request.
func (m *PutSingleRequest) SetMetaHeader(v *session.RequestMetaHeader) {
m.MetaHeader = v
}
// SetVerifyHeader sets verification header of the request.
func (m *PutSingleRequest) SetVerifyHeader(v *session.RequestVerificationHeader) {
m.VerifyHeader = v
}

View file

@ -110,6 +110,9 @@ const (
getRangeHashRespBodyTypeField = 1
getRangeHashRespBodyHashListField = 2
putSingleReqObjectField = 1
putSingleReqCopiesNumberField = 2
)
func (h *ShortHeader) StableMarshal(buf []byte) []byte {
@ -1063,3 +1066,35 @@ func (r *GetRangeHashResponseBody) StableSize() (size int) {
func (r *GetRangeHashResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.GetRangeHashResponse_Body))
}
func (r *PutSingleRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(putSingleReqObjectField, buf[offset:], r.object)
proto.RepeatedUInt32Marshal(putSingleReqCopiesNumberField, buf[offset:], r.copyNum)
return buf
}
func (r *PutSingleRequestBody) StableSize() int {
if r == nil {
return 0
}
var size int
size += proto.NestedStructureSize(putSingleReqObjectField, r.object)
arrSize, _ := proto.RepeatedUInt32Size(putSingleReqCopiesNumberField, r.copyNum)
size += arrSize
return size
}
func (r *PutSingleRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(object.PutSingleRequest_Body))
}

View file

@ -51,5 +51,6 @@ func TestMessageConvert(t *testing.T) {
func(empty bool) message.Message { return objecttest.GenerateGetRangeHashResponseBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeHashResponse(empty) },
func(empty bool) message.Message { return objecttest.GenerateLock(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutSingleRequest(empty) },
)
}

View file

@ -610,3 +610,25 @@ func GenerateLock(empty bool) *object.Lock {
return m
}
func GeneratePutSingleRequest(empty bool) *object.PutSingleRequest {
m := new(object.PutSingleRequest)
if !empty {
m.SetBody(GeneratePutSingleRequestBody(false))
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GeneratePutSingleRequestBody(empty bool) *object.PutSingleRequestBody {
b := new(object.PutSingleRequestBody)
if !empty {
b.SetObject(GenerateObject(empty))
b.SetCopiesNumber([]uint32{12345})
}
return b
}

View file

@ -87,6 +87,8 @@ func serviceMessageBody(req any) stableMarshaler {
return v.GetBody()
case *object.GetRangeHashResponse:
return v.GetBody()
case *object.PutSingleRequest:
return v.GetBody()
/* Netmap */
case *netmap.LocalNodeInfoRequest: