forked from TrueCloudLab/frostfs-api-go
[#132] v2/object: Implement stable unmarshaler on Object
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
c125749c6e
commit
e222c441e5
2 changed files with 28 additions and 0 deletions
|
@ -2,6 +2,7 @@ package object
|
|||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/util/proto"
|
||||
object "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -440,6 +441,21 @@ func (o *Object) StableSize() (size int) {
|
|||
return size
|
||||
}
|
||||
|
||||
func (o *Object) StableUnmarshal(data []byte) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
objGRPC := new(object.Object)
|
||||
if err := objGRPC.Unmarshal(data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ObjectFromGRPCMessage(objGRPC)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GetRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
||||
if r == nil {
|
||||
return []byte{}, nil
|
||||
|
|
|
@ -688,3 +688,15 @@ func generateRangeHashResponseBody(n int) *object.GetRangeHashResponseBody {
|
|||
|
||||
return resp
|
||||
}
|
||||
|
||||
func TestObject_StableUnmarshal(t *testing.T) {
|
||||
obj := generateObject("some data")
|
||||
|
||||
data, err := obj.StableMarshal(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
obj2 := new(object.Object)
|
||||
require.NoError(t, obj2.StableUnmarshal(data))
|
||||
|
||||
require.Equal(t, obj, obj2)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue