Skip to content

Commit 35b3d88

Browse files
Rename streamingValueReader to streamingByteSrc
1 parent 6c7e606 commit 35b3d88

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

bson/streaming_value_reader.go renamed to bson/streaming_byte_src.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ import (
1111
"io"
1212
)
1313

14-
// streamingValueReader reads from an ioReader wrapped in a bufio.Reader. It
14+
// streamingByteSrc reads from an ioReader wrapped in a bufio.Reader. It
1515
// first reads the BSON length header, then ensures it only ever reads exactly
1616
// that many bytes.
1717
//
1818
// Note: this approach trades memory usage for extra buffering and reader calls,
1919
// so it is less performanted than the in-memory bufferedValueReader.
20-
type streamingValueReader struct {
20+
type streamingByteSrc struct {
2121
br *bufio.Reader
2222
offset int64 // offset is the current read position in the buffer
2323
}
2424

25-
var _ valueReaderByteSrc = (*streamingValueReader)(nil)
25+
var _ valueReaderByteSrc = (*streamingByteSrc)(nil)
2626

2727
// Read reads up to len(p) bytes from the underlying bufio.Reader, advancing
2828
// the offset by the number of bytes read.
29-
func (s *streamingValueReader) readExact(p []byte) (int, error) {
29+
func (s *streamingByteSrc) readExact(p []byte) (int, error) {
3030
n, err := io.ReadFull(s.br, p)
3131
if err == nil {
3232
s.offset += int64(n)
@@ -36,7 +36,7 @@ func (s *streamingValueReader) readExact(p []byte) (int, error) {
3636
}
3737

3838
// ReadByte returns the single byte at buf[offset] and advances offset by 1.
39-
func (s *streamingValueReader) ReadByte() (byte, error) {
39+
func (s *streamingByteSrc) ReadByte() (byte, error) {
4040
c, err := s.br.ReadByte()
4141
if err == nil {
4242
s.offset++
@@ -45,20 +45,20 @@ func (s *streamingValueReader) ReadByte() (byte, error) {
4545
}
4646

4747
// peek returns buf[offset:offset+n] without advancing offset.
48-
func (s *streamingValueReader) peek(n int) ([]byte, error) {
48+
func (s *streamingByteSrc) peek(n int) ([]byte, error) {
4949
return s.br.Peek(n)
5050
}
5151

5252
// discard advances offset by n bytes, returning the number of bytes discarded.
53-
func (s *streamingValueReader) discard(n int) (int, error) {
53+
func (s *streamingByteSrc) discard(n int) (int, error) {
5454
m, err := s.br.Discard(n)
5555
s.offset += int64(m)
5656
return m, err
5757
}
5858

5959
// readSlice scans buf[offset:] for the first occurrence of delim, returns
6060
// buf[offset:idx+1], and advances offset past it; errors if delim not found.
61-
func (s *streamingValueReader) readSlice(delim byte) ([]byte, error) {
61+
func (s *streamingByteSrc) readSlice(delim byte) ([]byte, error) {
6262
data, err := s.br.ReadSlice(delim)
6363
if err != nil {
6464
return nil, err
@@ -68,12 +68,12 @@ func (s *streamingValueReader) readSlice(delim byte) ([]byte, error) {
6868
}
6969

7070
// pos returns the current read position in the buffer.
71-
func (s *streamingValueReader) pos() int64 {
71+
func (s *streamingByteSrc) pos() int64 {
7272
return s.offset
7373
}
7474

7575
// regexLength will return the total byte length of a BSON regex value.
76-
func (s *streamingValueReader) regexLength() (int32, error) {
76+
func (s *streamingByteSrc) regexLength() (int32, error) {
7777
var (
7878
count int32
7979
nulCount int
@@ -95,10 +95,10 @@ func (s *streamingValueReader) regexLength() (int32, error) {
9595
return count, nil
9696
}
9797

98-
func (*streamingValueReader) streamable() bool {
98+
func (*streamingByteSrc) streamable() bool {
9999
return true
100100
}
101101

102-
func (s *streamingValueReader) reset() {
102+
func (s *streamingByteSrc) reset() {
103103
s.offset = 0
104104
}

bson/value_reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func NewDocumentReader(r io.Reader) ValueReader {
107107
}
108108

109109
return &valueReader{
110-
src: &streamingValueReader{br: bufio.NewReader(r), offset: 0},
110+
src: &streamingByteSrc{br: bufio.NewReader(r), offset: 0},
111111
stack: stack,
112112
}
113113
}

bson/value_reader_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestValueReader_ReadBinary(t *testing.T) {
106106

107107
t.Run("streaming", func(t *testing.T) {
108108
vr := &valueReader{
109-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
109+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
110110
stack: []vrState{
111111
{mode: mTopLevel},
112112
{
@@ -196,7 +196,7 @@ func TestValueReader_ReadBoolean(t *testing.T) {
196196

197197
t.Run("streaming", func(t *testing.T) {
198198
vr := &valueReader{
199-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
199+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
200200
stack: []vrState{
201201
{mode: mTopLevel},
202202
{
@@ -238,7 +238,7 @@ func TestValueReader_ReadDocument_TopLevel_InvalidLength(t *testing.T) {
238238

239239
t.Run("streaming", func(t *testing.T) {
240240
vr := &valueReader{
241-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader([]byte{0x00, 0x00}))},
241+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader([]byte{0x00, 0x00}))},
242242
stack: []vrState{{mode: mTopLevel}},
243243
frame: 0,
244244
}
@@ -271,7 +271,7 @@ func TestValueReader_ReadDocument_TopLevel_ValidDocumentWithIncorrectEnd(t *test
271271
t.Run("streaming", func(t *testing.T) {
272272

273273
vr := &valueReader{
274-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader([]byte{0x05, 0x00, 0x00, 0x00, 0x00}))},
274+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader([]byte{0x05, 0x00, 0x00, 0x00, 0x00}))},
275275
stack: []vrState{{mode: mTopLevel}},
276276
frame: 0,
277277
}
@@ -336,7 +336,7 @@ func TestValueReader_ReadDocument_EmbeddedDocument(t *testing.T) {
336336

337337
t.Run("streaming", func(t *testing.T) {
338338
vr := &valueReader{
339-
src: &streamingValueReader{
339+
src: &streamingByteSrc{
340340
br: bufio.NewReader(bytes.NewReader([]byte{0x0a, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00})),
341341
},
342342
stack: []vrState{
@@ -481,7 +481,7 @@ func TestValueReader_ReadCodeWithScope(t *testing.T) {
481481

482482
t.Run("streaming", func(t *testing.T) {
483483
vr := &valueReader{
484-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
484+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
485485
stack: []vrState{
486486
{mode: mTopLevel},
487487
{
@@ -537,7 +537,7 @@ func TestValueReader_ReadCodeWithScope(t *testing.T) {
537537
doc = append(doc, codeWithScope...)
538538
doc = append(doc, 0x00)
539539
vr := &valueReader{
540-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(doc))},
540+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(doc))},
541541
stack: []vrState{
542542
{mode: mTopLevel},
543543
{mode: mElement, vType: TypeCodeWithScope},
@@ -649,7 +649,7 @@ func TestValueReader_ReadDBPointer(t *testing.T) {
649649

650650
t.Run("streaming", func(t *testing.T) {
651651
vr := &valueReader{
652-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
652+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
653653
stack: []vrState{
654654
{mode: mTopLevel},
655655
{
@@ -732,7 +732,7 @@ func TestValueReader_ReadDateTime(t *testing.T) {
732732

733733
t.Run("streaming", func(t *testing.T) {
734734
vr := &valueReader{
735-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
735+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
736736
stack: []vrState{
737737
{mode: mTopLevel},
738738
{
@@ -820,7 +820,7 @@ func TestValueReader_ReadDecimal128(t *testing.T) {
820820

821821
t.Run("streaming", func(t *testing.T) {
822822
vr := &valueReader{
823-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
823+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
824824
stack: []vrState{
825825
{mode: mTopLevel},
826826
{
@@ -905,7 +905,7 @@ func TestValueReader_ReadDouble(t *testing.T) {
905905

906906
t.Run("streaming", func(t *testing.T) {
907907
vr := &valueReader{
908-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
908+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
909909
stack: []vrState{
910910
{mode: mTopLevel},
911911
{
@@ -985,7 +985,7 @@ func TestValueReader_ReadInt32(t *testing.T) {
985985

986986
t.Run("streaming", func(t *testing.T) {
987987
vr := &valueReader{
988-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
988+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
989989
stack: []vrState{
990990
{mode: mTopLevel},
991991
{
@@ -1065,7 +1065,7 @@ func TestValueReader_ReadInt64(t *testing.T) {
10651065

10661066
t.Run("streaming", func(t *testing.T) {
10671067
vr := &valueReader{
1068-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
1068+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
10691069
stack: []vrState{
10701070
{mode: mTopLevel},
10711071
{
@@ -1262,7 +1262,7 @@ func TestValueReader_ReadJavascript_ReadString_ReadSymbol(t *testing.T) {
12621262

12631263
t.Run("streaming", func(t *testing.T) {
12641264
vr := &valueReader{
1265-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
1265+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
12661266
stack: []vrState{
12671267
{mode: mTopLevel},
12681268
{
@@ -1376,7 +1376,7 @@ func TestValueReader_ReadMaxKey_ReadMinKey_ReadNull_ReadUndefined(t *testing.T)
13761376

13771377
t.Run("streaming", func(t *testing.T) {
13781378
vr := &valueReader{
1379-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader([]byte{}))},
1379+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader([]byte{}))},
13801380
stack: []vrState{
13811381
{mode: mTopLevel},
13821382
{
@@ -1454,7 +1454,7 @@ func TestValueReader_ReadObjectID(t *testing.T) {
14541454

14551455
t.Run("streaming", func(t *testing.T) {
14561456
vr := &valueReader{
1457-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
1457+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
14581458
stack: []vrState{
14591459
{mode: mTopLevel},
14601460
{
@@ -1549,7 +1549,7 @@ func TestValueReader_ReadRegex(t *testing.T) {
15491549

15501550
t.Run("streaming", func(t *testing.T) {
15511551
vr := &valueReader{
1552-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
1552+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
15531553
stack: []vrState{
15541554
{mode: mTopLevel},
15551555
{
@@ -1647,7 +1647,7 @@ func TestValueReader_ReadTimestamp(t *testing.T) {
16471647

16481648
t.Run("streaming", func(t *testing.T) {
16491649
vr := &valueReader{
1650-
src: &streamingValueReader{br: bufio.NewReader(bytes.NewReader(tc.data))},
1650+
src: &streamingByteSrc{br: bufio.NewReader(bytes.NewReader(tc.data))},
16511651
stack: []vrState{
16521652
{mode: mTopLevel},
16531653
{
@@ -2391,7 +2391,7 @@ func TestValueReader_ReadBytes_Skip_Streaming(t *testing.T) {
23912391
const startingEnd = 64
23922392
t.Run("Skip", func(t *testing.T) {
23932393
vr := &valueReader{
2394-
src: &streamingValueReader{
2394+
src: &streamingByteSrc{
23952395
br: bufio.NewReader(bytes.NewReader(tc.data[tc.startingOffset:tc.offset])),
23962396
offset: tc.startingOffset,
23972397
},
@@ -2415,7 +2415,7 @@ func TestValueReader_ReadBytes_Skip_Streaming(t *testing.T) {
24152415
})
24162416
t.Run("ReadBytes", func(t *testing.T) {
24172417
vr := &valueReader{
2418-
src: &streamingValueReader{
2418+
src: &streamingByteSrc{
24192419
br: bufio.NewReader(bytes.NewReader(tc.data[tc.startingOffset:tc.offset])),
24202420
offset: tc.startingOffset,
24212421
},
@@ -2475,7 +2475,7 @@ func TestValueReader_ReadBytes_Skip_Streaming(t *testing.T) {
24752475
t.Run(tc.name, func(t *testing.T) {
24762476
t.Parallel()
24772477
vr := &valueReader{
2478-
src: &streamingValueReader{
2478+
src: &streamingByteSrc{
24792479
br: bufio.NewReader(bytes.NewReader(tc.want)),
24802480
},
24812481
stack: []vrState{

0 commit comments

Comments
 (0)