[#356] refs: Implement text encoding of SubnetID

Implement `encoding.TextMarshaler` / `encoding.TextUnmarshaler` interfaces
on `SubnetID` according to NeoFS API V2 protocol.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-11-18 18:16:16 +03:00 committed by LeL
parent f0af5ce759
commit 0e6e0e4678
2 changed files with 62 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package refs_test
import (
"strconv"
"testing"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
@ -18,3 +19,32 @@ func TestZeroSubnet(t *testing.T) {
refs.MakeZeroSubnet(id)
require.True(t, refs.IsZeroSubnet(id))
}
func TestSubnetID_MarshalText(t *testing.T) {
var id refs.SubnetID
const val = 15
id.SetValue(val)
txt, err := id.MarshalText()
require.NoError(t, err)
res, err := strconv.ParseUint(string(txt), 10, 32)
require.NoError(t, err)
require.EqualValues(t, val, res)
}
func TestSubnetID_UnmarshalText(t *testing.T) {
const val = 15
str := strconv.FormatUint(val, 10)
var id refs.SubnetID
err := id.UnmarshalText([]byte(str))
require.NoError(t, err)
require.EqualValues(t, val, id.GetValue())
}