diff --git a/nocopy/types_test.go b/nocopy/types_test.go index 3f38ceb..8a4911d 100644 --- a/nocopy/types_test.go +++ b/nocopy/types_test.go @@ -4,12 +4,28 @@ package nocopy import ( + "bytes" "testing" "github.com/kelindar/binary" "github.com/stretchr/testify/assert" ) +func TestStreamDecodeRetainsStrings(t *testing.T) { + type pair struct { + First String + Second String + } + + want := pair{First: "first", Second: "second"} + data, err := binary.Marshal(want) + assert.NoError(t, err) + + var got pair + assert.NoError(t, binary.NewDecoder(bytes.NewReader(data)).Decode(&got)) + assert.Equal(t, want, got) +} + type composite map[string]column type column struct { diff --git a/reader.go b/reader.go index 36b2d69..fe8748c 100644 --- a/reader.go +++ b/reader.go @@ -156,7 +156,6 @@ func (r *sliceReader) Reset(b []byte) { // streamReader represents a reader implementation for a generic reader (i.e. streams) type streamReader struct { Reader - scratch [10]byte } // Reader represents the interface a reader should implement. @@ -179,12 +178,7 @@ func newStreamReader(r io.Reader) *streamReader { // Slice selects a sub-slice of next bytes. func (r *streamReader) Slice(n int) (buffer []byte, err error) { - if n <= 10 { - buffer = r.scratch[:n] - } else { - buffer = make([]byte, n, n) - } - + buffer = make([]byte, n) _, err = io.ReadFull(r, buffer) return }