forked from TrueCloudLab/frostfs-api-go
[#218] pkg/object: Add marshal operations for SplitInfo
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
664ebfd8a7
commit
b683dbe7e6
3 changed files with 35 additions and 0 deletions
|
@ -47,3 +47,16 @@ func (s *SplitInfo) Link() *ID {
|
|||
func (s *SplitInfo) SetLink(v *ID) {
|
||||
(*object.SplitInfo)(s).SetLink(v.ToV2())
|
||||
}
|
||||
|
||||
func (s *SplitInfo) Marshal(b ...[]byte) ([]byte, error) {
|
||||
var buf []byte
|
||||
if len(b) > 0 {
|
||||
buf = b[0]
|
||||
}
|
||||
|
||||
return (*object.SplitInfo)(s).StableMarshal(buf)
|
||||
}
|
||||
|
||||
func (s *SplitInfo) Unmarshal(data []byte) error {
|
||||
return (*object.SplitInfo)(s).Unmarshal(data)
|
||||
}
|
||||
|
|
|
@ -29,6 +29,17 @@ func TestSplitInfo(t *testing.T) {
|
|||
|
||||
require.Equal(t, s, newS)
|
||||
})
|
||||
|
||||
t.Run("marshal and unmarshal", func(t *testing.T) {
|
||||
data, err := s.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
newS := object.NewSplitInfo()
|
||||
|
||||
err = newS.Unmarshal(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, s, newS)
|
||||
})
|
||||
}
|
||||
|
||||
func generateID() *object.ID {
|
||||
|
|
|
@ -629,6 +629,17 @@ func (s *SplitInfo) StableSize() (size int) {
|
|||
return size
|
||||
}
|
||||
|
||||
func (s *SplitInfo) Unmarshal(data []byte) error {
|
||||
m := new(object.SplitInfo)
|
||||
if err := goproto.Unmarshal(data, m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*s = *SplitInfoFromGRPCMessage(m)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GetRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
||||
if r == nil {
|
||||
return []byte{}, nil
|
||||
|
|
Loading…
Reference in a new issue