From 81975017b2eeba981d66dad58cb02ff0cfe9d1ac Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 21 Sep 2020 17:22:35 +0300 Subject: [PATCH] sdk/v2: Remove unused marshallers All default marshallers defined on unified structure in `v2` package Signed-off-by: Alex Vanin --- v2/refs/grpc/marshal.go | 49 ------------------------------------ v2/refs/grpc/marshal_test.go | 45 --------------------------------- 2 files changed, 94 deletions(-) delete mode 100644 v2/refs/grpc/marshal.go delete mode 100644 v2/refs/grpc/marshal_test.go diff --git a/v2/refs/grpc/marshal.go b/v2/refs/grpc/marshal.go deleted file mode 100644 index 3503a44..0000000 --- a/v2/refs/grpc/marshal.go +++ /dev/null @@ -1,49 +0,0 @@ -package refs - -import ( - "encoding/binary" - "math/bits" -) - -func (m *OwnerID) StableMarshal(buf []byte) ([]byte, error) { - if m == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, m.StableSize()) - } - - var ( - i, n, offset int - ) - - // Write key field. - - buf[i] = 0x0A // id:0x1 << 3 | wiretype:0x2 - offset = binary.PutUvarint(buf[i+1:], uint64(len(m.Value))) - n = copy(buf[i+1+offset:], m.Value) - i += 1 + offset + n - - return buf, nil -} - -func (m *OwnerID) StableSize() int { - if m == nil { - return 0 - } - - var ( - ln, size int - ) - - ln = len(m.Value) // size of key field - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + size of string + string - - return size -} - -// uvarIntSize returns length of varint byte sequence for uint64 value 'x'. -func uvarIntSize(x uint64) int { - return (bits.Len64(x|1) + 6) / 7 -} diff --git a/v2/refs/grpc/marshal_test.go b/v2/refs/grpc/marshal_test.go deleted file mode 100644 index 8f822fb..0000000 --- a/v2/refs/grpc/marshal_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package refs - -import ( - "crypto/rand" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestOwnerID_StableMarshal(t *testing.T) { - owner := make([]byte, 25) - _, err := rand.Read(owner) - require.NoError(t, err) - - expectedOwner := new(OwnerID) - expectedOwner.Value = owner - - gotOwner := new(OwnerID) - - t.Run("small buffer", func(t *testing.T) { - require.Panics(t, func() { - expectedOwner.StableMarshal(make([]byte, 1)) - }) - }) - - t.Run("empty owner", func(t *testing.T) { - data, err := new(OwnerID).StableMarshal(nil) - require.NoError(t, err) - - err = gotOwner.Unmarshal(data) - require.NoError(t, err) - - require.Len(t, gotOwner.Value, 0) - }) - - t.Run("non empty owner", func(t *testing.T) { - data, err := expectedOwner.StableMarshal(nil) - require.NoError(t, err) - - err = gotOwner.Unmarshal(data) - require.NoError(t, err) - - require.Equal(t, expectedOwner, gotOwner) - }) -}