From 1c7b023f0adb407b37f4b503054920f7847c57c8 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Wed, 10 Aug 2022 15:01:21 +0000 Subject: [PATCH] Fix: add fields cache to encode state --- pkg/scale/encode.go | 3 ++- pkg/scale/encode_test.go | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pkg/scale/encode.go b/pkg/scale/encode.go index 99883df4a82..614581fedba 100644 --- a/pkg/scale/encode.go +++ b/pkg/scale/encode.go @@ -21,7 +21,8 @@ type Encoder struct { func NewEncoder(writer io.Writer) (encoder *Encoder) { return &Encoder{ encodeState: encodeState{ - Writer: writer, + Writer: writer, + fieldScaleIndicesCache: cache, }, } } diff --git a/pkg/scale/encode_test.go b/pkg/scale/encode_test.go index 9e219004d71..79ef16249c4 100644 --- a/pkg/scale/encode_test.go +++ b/pkg/scale/encode_test.go @@ -41,8 +41,30 @@ func Test_Encoder_Encode(t *testing.T) { err = encoder.Encode(uint8(2)) require.NoError(t, err) + array := [2]byte{4, 5} + err = encoder.Encode(array) + require.NoError(t, err) + + type T struct { + Array [2]byte + } + + someStruct := T{Array: [2]byte{6, 7}} + err = encoder.Encode(someStruct) + require.NoError(t, err) + + structSlice := []T{{Array: [2]byte{8, 9}}} + err = encoder.Encode(structSlice) + require.NoError(t, err) + written := buffer.Bytes() - expectedWritten := []byte{1, 0, 2} + expectedWritten := []byte{ + 1, 0, + 2, + 4, 5, + 6, 7, + 4, 8, 9, + } assert.Equal(t, expectedWritten, written) }