[#226] v2/object: Add tombstone field to DeleteResponseBody

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-10 12:15:17 +03:00 committed by Leonard Lyubich
parent c064760f5d
commit 4567986682
5 changed files with 61 additions and 6 deletions

View file

@ -909,6 +909,9 @@ func DeleteResponseBodyToGRPCMessage(r *DeleteResponseBody) *object.DeleteRespon
} }
m := new(object.DeleteResponse_Body) m := new(object.DeleteResponse_Body)
m.SetTombstone(
refs.AddressToGRPCMessage(r.GetTombstone()),
)
return m return m
} }
@ -919,6 +922,9 @@ func DeleteResponseBodyFromGRPCMessage(m *object.DeleteResponse_Body) *DeleteRes
} }
r := new(DeleteResponseBody) r := new(DeleteResponseBody)
r.SetTombstone(
refs.AddressFromGRPCMessage(m.GetTombstone()),
)
return r return r
} }

View file

@ -260,6 +260,13 @@ func (m *DeleteRequest) SetVerifyHeader(v *session.RequestVerificationHeader) {
} }
} }
// SetTombstone sets tombstone address.
func (x *DeleteResponse_Body) SetTombstone(v *refs.Address) {
if x != nil {
x.Tombstone = v
}
}
// SetBody sets body of the response. // SetBody sets body of the response.
func (m *DeleteResponse) SetBody(v *DeleteResponse_Body) { func (m *DeleteResponse) SetBody(v *DeleteResponse_Body) {
if m != nil { if m != nil {

View file

@ -70,6 +70,8 @@ const (
deleteReqBodyAddressField = 1 deleteReqBodyAddressField = 1
deleteRespBodyTombstoneFNum = 1
headReqBodyAddressField = 1 headReqBodyAddressField = 1
headReqBodyMainFlagField = 2 headReqBodyMainFlagField = 2
headReqBodyRawFlagField = 3 headReqBodyRawFlagField = 3
@ -953,11 +955,30 @@ func (r *DeleteRequestBody) StableSize() (size int) {
} }
func (r *DeleteResponseBody) StableMarshal(buf []byte) ([]byte, error) { func (r *DeleteResponseBody) StableMarshal(buf []byte) ([]byte, error) {
return nil, nil if r == nil {
return []byte{}, nil
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
_, err := proto.NestedStructureMarshal(deleteRespBodyTombstoneFNum, buf, r.tombstone)
if err != nil {
return nil, err
}
return buf, nil
} }
func (r *DeleteResponseBody) StableSize() (size int) { func (r *DeleteResponseBody) StableSize() (size int) {
return 0 if r == nil {
return 0
}
size += proto.NestedStructureSize(deleteRespBodyTombstoneFNum, r.tombstone)
return size
} }
func (r *HeadRequestBody) StableMarshal(buf []byte) ([]byte, error) { func (r *HeadRequestBody) StableMarshal(buf []byte) ([]byte, error) {

View file

@ -207,7 +207,7 @@ func TestDeleteRequestBody_StableMarshal(t *testing.T) {
} }
func TestDeleteResponseBody_StableMarshal(t *testing.T) { func TestDeleteResponseBody_StableMarshal(t *testing.T) {
from := generateDeleteResponseBody() from := generateDeleteResponseBody("CID", "OID")
transport := new(grpc.DeleteResponse_Body) transport := new(grpc.DeleteResponse_Body)
t.Run("non empty", func(t *testing.T) { t.Run("non empty", func(t *testing.T) {
@ -613,8 +613,11 @@ func generateDeleteRequestBody(cid, oid string) *object.DeleteRequestBody {
return req return req
} }
func generateDeleteResponseBody() *object.DeleteResponseBody { func generateDeleteResponseBody(cid, oid string) *object.DeleteResponseBody {
return new(object.DeleteResponseBody) resp := new(object.DeleteResponseBody)
resp.SetTombstone(generateAddress(cid, oid))
return resp
} }
func generateHeadRequestBody(cid, oid string) *object.HeadRequestBody { func generateHeadRequestBody(cid, oid string) *object.HeadRequestBody {

View file

@ -139,7 +139,9 @@ type DeleteRequestBody struct {
addr *refs.Address addr *refs.Address
} }
type DeleteResponseBody struct{} type DeleteResponseBody struct {
tombstone *refs.Address
}
type HeadRequestBody struct { type HeadRequestBody struct {
addr *refs.Address addr *refs.Address
@ -1124,6 +1126,22 @@ func (r *DeleteRequest) SetVerificationHeader(v *session.RequestVerificationHead
} }
} }
// GetTombstone returns tombstone address.
func (r *DeleteResponseBody) GetTombstone() *refs.Address {
if r != nil {
return r.tombstone
}
return nil
}
// SetTombstone sets tombstone address.
func (r *DeleteResponseBody) SetTombstone(v *refs.Address) {
if r != nil {
r.tombstone = v
}
}
func (r *DeleteResponse) GetBody() *DeleteResponseBody { func (r *DeleteResponse) GetBody() *DeleteResponseBody {
if r != nil { if r != nil {
return r.body return r.body