summaryrefslogtreecommitdiff
path: root/vendor/go.mongodb.org/mongo-driver/bson/bsonrw
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.mongodb.org/mongo-driver/bson/bsonrw')
-rw-r--r--vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_parser.go2
-rw-r--r--vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_wrappers.go4
-rw-r--r--vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_writer.go13
-rw-r--r--vendor/go.mongodb.org/mongo-driver/bson/bsonrw/json_scanner.go37
-rw-r--r--vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_reader.go12
-rw-r--r--vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_writer.go2
6 files changed, 36 insertions, 34 deletions
diff --git a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_parser.go b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_parser.go
index bb52a0ec3..f0702d9d3 100644
--- a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_parser.go
+++ b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_parser.go
@@ -305,7 +305,7 @@ func (ejp *extJSONParser) readValue(t bsontype.Type) (*extJSONValue, error) {
}
// remove hyphens
- uuidNoHyphens := strings.Replace(uuid, "-", "", -1)
+ uuidNoHyphens := strings.ReplaceAll(uuid, "-", "")
if len(uuidNoHyphens) != 32 {
return nil, fmt.Errorf("$uuid value does not follow RFC 4122 format regarding length and hyphens")
}
diff --git a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_wrappers.go b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_wrappers.go
index 969570424..af6ae7b76 100644
--- a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_wrappers.go
+++ b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_wrappers.go
@@ -95,9 +95,9 @@ func (ejv *extJSONValue) parseBinary() (b []byte, subType byte, err error) {
return nil, 0, fmt.Errorf("$binary subType value should be string, but instead is %s", val.t)
}
- i, err := strconv.ParseInt(val.v.(string), 16, 64)
+ i, err := strconv.ParseUint(val.v.(string), 16, 8)
if err != nil {
- return nil, 0, fmt.Errorf("invalid $binary subType string: %s", val.v.(string))
+ return nil, 0, fmt.Errorf("invalid $binary subType string: %q: %w", val.v.(string), err)
}
subType = byte(i)
diff --git a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_writer.go b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_writer.go
index bb9303167..57781ff9f 100644
--- a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_writer.go
+++ b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/extjson_writer.go
@@ -628,13 +628,14 @@ func (ejvw *extJSONValueWriter) WriteArrayEnd() error {
func formatDouble(f float64) string {
var s string
- if math.IsInf(f, 1) {
+ switch {
+ case math.IsInf(f, 1):
s = "Infinity"
- } else if math.IsInf(f, -1) {
+ case math.IsInf(f, -1):
s = "-Infinity"
- } else if math.IsNaN(f) {
+ case math.IsNaN(f):
s = "NaN"
- } else {
+ default:
// Print exactly one decimalType place for integers; otherwise, print as many are necessary to
// perfectly represent it.
s = strconv.FormatFloat(f, 'G', -1, 64)
@@ -739,9 +740,7 @@ func (ss sortableString) Less(i, j int) bool {
}
func (ss sortableString) Swap(i, j int) {
- oldI := ss[i]
- ss[i] = ss[j]
- ss[j] = oldI
+ ss[i], ss[j] = ss[j], ss[i]
}
func sortStringAlphebeticAscending(s string) string {
diff --git a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/json_scanner.go b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/json_scanner.go
index 43f3e4f38..978289191 100644
--- a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/json_scanner.go
+++ b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/json_scanner.go
@@ -82,12 +82,13 @@ func (js *jsonScanner) nextToken() (*jsonToken, error) {
return js.scanString()
default:
// check if it's a number
- if c == '-' || isDigit(c) {
+ switch {
+ case c == '-' || isDigit(c):
return js.scanNumber(c)
- } else if c == 't' || c == 'f' || c == 'n' {
+ case c == 't' || c == 'f' || c == 'n':
// maybe a literal
return js.scanLiteral(c)
- } else {
+ default:
return nil, fmt.Errorf("invalid JSON input. Position: %d. Character: %c", js.pos-1, c)
}
}
@@ -174,7 +175,7 @@ func getu4(s []byte) rune {
for _, c := range s[:4] {
switch {
case '0' <= c && c <= '9':
- c = c - '0'
+ c -= '0'
case 'a' <= c && c <= 'f':
c = c - 'a' + 10
case 'A' <= c && c <= 'F':
@@ -325,13 +326,14 @@ func (js *jsonScanner) scanLiteral(first byte) (*jsonToken, error) {
c5, err := js.readNextByte()
- if bytes.Equal([]byte("true"), lit) && (isValueTerminator(c5) || errors.Is(err, io.EOF)) {
+ switch {
+ case bytes.Equal([]byte("true"), lit) && (isValueTerminator(c5) || errors.Is(err, io.EOF)):
js.pos = int(math.Max(0, float64(js.pos-1)))
return &jsonToken{t: jttBool, v: true, p: p}, nil
- } else if bytes.Equal([]byte("null"), lit) && (isValueTerminator(c5) || errors.Is(err, io.EOF)) {
+ case bytes.Equal([]byte("null"), lit) && (isValueTerminator(c5) || errors.Is(err, io.EOF)):
js.pos = int(math.Max(0, float64(js.pos-1)))
return &jsonToken{t: jttNull, v: nil, p: p}, nil
- } else if bytes.Equal([]byte("fals"), lit) {
+ case bytes.Equal([]byte("fals"), lit):
if c5 == 'e' {
c5, err = js.readNextByte()
@@ -430,12 +432,13 @@ func (js *jsonScanner) scanNumber(first byte) (*jsonToken, error) {
case '}', ']', ',':
s = nssDone
default:
- if isWhiteSpace(c) || errors.Is(err, io.EOF) {
+ switch {
+ case isWhiteSpace(c) || errors.Is(err, io.EOF):
s = nssDone
- } else if isDigit(c) {
+ case isDigit(c):
s = nssSawIntegerDigits
b.WriteByte(c)
- } else {
+ default:
s = nssInvalid
}
}
@@ -455,12 +458,13 @@ func (js *jsonScanner) scanNumber(first byte) (*jsonToken, error) {
case '}', ']', ',':
s = nssDone
default:
- if isWhiteSpace(c) || errors.Is(err, io.EOF) {
+ switch {
+ case isWhiteSpace(c) || errors.Is(err, io.EOF):
s = nssDone
- } else if isDigit(c) {
+ case isDigit(c):
s = nssSawFractionDigits
b.WriteByte(c)
- } else {
+ default:
s = nssInvalid
}
}
@@ -490,12 +494,13 @@ func (js *jsonScanner) scanNumber(first byte) (*jsonToken, error) {
case '}', ']', ',':
s = nssDone
default:
- if isWhiteSpace(c) || errors.Is(err, io.EOF) {
+ switch {
+ case isWhiteSpace(c) || errors.Is(err, io.EOF):
s = nssDone
- } else if isDigit(c) {
+ case isDigit(c):
s = nssSawExponentDigits
b.WriteByte(c)
- } else {
+ default:
s = nssInvalid
}
}
diff --git a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_reader.go b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_reader.go
index a242bb57c..0e07d5055 100644
--- a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_reader.go
+++ b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_reader.go
@@ -842,7 +842,7 @@ func (vr *valueReader) peekLength() (int32, error) {
}
idx := vr.offset
- return (int32(vr.d[idx]) | int32(vr.d[idx+1])<<8 | int32(vr.d[idx+2])<<16 | int32(vr.d[idx+3])<<24), nil
+ return int32(binary.LittleEndian.Uint32(vr.d[idx:])), nil
}
func (vr *valueReader) readLength() (int32, error) { return vr.readi32() }
@@ -854,7 +854,7 @@ func (vr *valueReader) readi32() (int32, error) {
idx := vr.offset
vr.offset += 4
- return (int32(vr.d[idx]) | int32(vr.d[idx+1])<<8 | int32(vr.d[idx+2])<<16 | int32(vr.d[idx+3])<<24), nil
+ return int32(binary.LittleEndian.Uint32(vr.d[idx:])), nil
}
func (vr *valueReader) readu32() (uint32, error) {
@@ -864,7 +864,7 @@ func (vr *valueReader) readu32() (uint32, error) {
idx := vr.offset
vr.offset += 4
- return (uint32(vr.d[idx]) | uint32(vr.d[idx+1])<<8 | uint32(vr.d[idx+2])<<16 | uint32(vr.d[idx+3])<<24), nil
+ return binary.LittleEndian.Uint32(vr.d[idx:]), nil
}
func (vr *valueReader) readi64() (int64, error) {
@@ -874,8 +874,7 @@ func (vr *valueReader) readi64() (int64, error) {
idx := vr.offset
vr.offset += 8
- return int64(vr.d[idx]) | int64(vr.d[idx+1])<<8 | int64(vr.d[idx+2])<<16 | int64(vr.d[idx+3])<<24 |
- int64(vr.d[idx+4])<<32 | int64(vr.d[idx+5])<<40 | int64(vr.d[idx+6])<<48 | int64(vr.d[idx+7])<<56, nil
+ return int64(binary.LittleEndian.Uint64(vr.d[idx:])), nil
}
func (vr *valueReader) readu64() (uint64, error) {
@@ -885,6 +884,5 @@ func (vr *valueReader) readu64() (uint64, error) {
idx := vr.offset
vr.offset += 8
- return uint64(vr.d[idx]) | uint64(vr.d[idx+1])<<8 | uint64(vr.d[idx+2])<<16 | uint64(vr.d[idx+3])<<24 |
- uint64(vr.d[idx+4])<<32 | uint64(vr.d[idx+5])<<40 | uint64(vr.d[idx+6])<<48 | uint64(vr.d[idx+7])<<56, nil
+ return binary.LittleEndian.Uint64(vr.d[idx:]), nil
}
diff --git a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_writer.go b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_writer.go
index 311518a80..501c6d7f9 100644
--- a/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_writer.go
+++ b/vendor/go.mongodb.org/mongo-driver/bson/bsonrw/value_writer.go
@@ -598,7 +598,7 @@ func (vw *valueWriter) writeLength() error {
return errMaxDocumentSizeExceeded{size: int64(len(vw.buf))}
}
frame := &vw.stack[vw.frame]
- length = length - int(frame.start)
+ length -= int(frame.start)
start := frame.start
_ = vw.buf[start+3] // BCE