Skip to content

Commit dd709d1

Browse files
Update (*valueReader).ReadValue() to support bVR + streaming
1 parent 403445f commit dd709d1

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

bson/value_reader.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,6 @@ func (vr *valueReader) advanceFrame() {
165165
vr.stack[vr.frame].end = 0
166166
}
167167

168-
func (vr *valueReader) pushValue(t Type) {
169-
vr.advanceFrame()
170-
171-
vr.stack[vr.frame].mode = mValue
172-
vr.stack[vr.frame].vType = t
173-
}
174-
175168
func (vr *valueReader) pop() error {
176169
var cnt int
177170
switch vr.stack[vr.frame].mode {
@@ -840,6 +833,8 @@ func (vr *valueReader) ReadElement() (string, ValueReader, error) {
840833
return name, vr, nil
841834
}
842835

836+
// ReadValue reads the next value in the BSON array, advancing the to the end of
837+
// the value.
843838
func (vr *valueReader) ReadValue() (ValueReader, error) {
844839
switch vr.stack[vr.frame].mode {
845840
case mArray:
@@ -853,19 +848,23 @@ func (vr *valueReader) ReadValue() (ValueReader, error) {
853848
}
854849

855850
if t == 0 {
856-
if vr.offset != vr.stack[vr.frame].end {
851+
if vr.src.pos() != vr.stack[vr.frame].end {
857852
return nil, vr.invalidDocumentLengthError()
858853
}
859854

860855
_ = vr.pop() // Ignore the error because the call here never reads from the underlying reader.
861856
return nil, ErrEOA
862857
}
863858

864-
if _, err := vr.readCString(); err != nil {
859+
_, err = vr.src.readSlice(0x00)
860+
if err != nil {
865861
return nil, err
866862
}
867863

868-
vr.pushValue(Type(t))
864+
vr.advanceFrame()
865+
866+
vr.stack[vr.frame].mode = mValue
867+
vr.stack[vr.frame].vType = Type(t)
869868
return vr, nil
870869
}
871870

0 commit comments

Comments
 (0)