summaryrefslogtreecommitdiff
path: root/vendor/go.mongodb.org/mongo-driver/bson/raw.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-03-25 11:00:36 +0000
committerLibravatar GitHub <noreply@github.com>2024-03-25 11:00:36 +0000
commit29031d1e274360f5fe8c53e56d1b0ae71628795f (patch)
tree54149ea2a80e863349e3cd8c02e6a6d1b3fcfe3f /vendor/go.mongodb.org/mongo-driver/bson/raw.go
parent[chore]: Bump github.com/coreos/go-oidc/v3 from 3.9.0 to 3.10.0 (#2779) (diff)
downloadgotosocial-29031d1e274360f5fe8c53e56d1b0ae71628795f.tar.xz
[chore]: Bump github.com/gin-contrib/sessions from 0.0.5 to 1.0.0 (#2782)
Diffstat (limited to 'vendor/go.mongodb.org/mongo-driver/bson/raw.go')
-rw-r--r--vendor/go.mongodb.org/mongo-driver/bson/raw.go34
1 files changed, 25 insertions, 9 deletions
diff --git a/vendor/go.mongodb.org/mongo-driver/bson/raw.go b/vendor/go.mongodb.org/mongo-driver/bson/raw.go
index efd705daa..130da61ba 100644
--- a/vendor/go.mongodb.org/mongo-driver/bson/raw.go
+++ b/vendor/go.mongodb.org/mongo-driver/bson/raw.go
@@ -16,18 +16,27 @@ import (
// ErrNilReader indicates that an operation was attempted on a nil bson.Reader.
var ErrNilReader = errors.New("nil reader")
-// Raw is a wrapper around a byte slice. It will interpret the slice as a
-// BSON document. This type is a wrapper around a bsoncore.Document. Errors returned from the
-// methods on this type and associated types come from the bsoncore package.
+// Raw is a raw encoded BSON document. It can be used to delay BSON document decoding or precompute
+// a BSON encoded document.
+//
+// A Raw must be a full BSON document. Use the RawValue type for individual BSON values.
type Raw []byte
-// NewFromIOReader reads in a document from the given io.Reader and constructs a Raw from
-// it.
-func NewFromIOReader(r io.Reader) (Raw, error) {
+// ReadDocument reads a BSON document from the io.Reader and returns it as a bson.Raw. If the
+// reader contains multiple BSON documents, only the first document is read.
+func ReadDocument(r io.Reader) (Raw, error) {
doc, err := bsoncore.NewDocumentFromReader(r)
return Raw(doc), err
}
+// NewFromIOReader reads a BSON document from the io.Reader and returns it as a bson.Raw. If the
+// reader contains multiple BSON documents, only the first document is read.
+//
+// Deprecated: Use ReadDocument instead.
+func NewFromIOReader(r io.Reader) (Raw, error) {
+ return ReadDocument(r)
+}
+
// Validate validates the document. This method only validates the first document in
// the slice, to validate other documents, the slice must be resliced.
func (r Raw) Validate() (err error) { return bsoncore.Document(r).Validate() }
@@ -51,12 +60,19 @@ func (r Raw) LookupErr(key ...string) (RawValue, error) {
// elements. If the document is not valid, the elements up to the invalid point will be returned
// along with an error.
func (r Raw) Elements() ([]RawElement, error) {
- elems, err := bsoncore.Document(r).Elements()
+ doc := bsoncore.Document(r)
+ if len(doc) == 0 {
+ return nil, nil
+ }
+ elems, err := doc.Elements()
+ if err != nil {
+ return nil, err
+ }
relems := make([]RawElement, 0, len(elems))
for _, elem := range elems {
relems = append(relems, RawElement(elem))
}
- return relems, err
+ return relems, nil
}
// Values returns this document as a slice of values. The returned slice will contain valid values.
@@ -81,5 +97,5 @@ func (r Raw) IndexErr(index uint) (RawElement, error) {
return RawElement(elem), err
}
-// String implements the fmt.Stringer interface.
+// String returns the BSON document encoded as Extended JSON.
func (r Raw) String() string { return bsoncore.Document(r).String() }