ErrEOA is the error returned when the end of a BSON array has been reached.
var ErrEOA = errors.New("end of array")
ErrEOD is the error returned when the end of a BSON document has been reached.
var ErrEOD = errors.New("end of document")
ErrInvalidJSON indicates the JSON input is invalid
var ErrInvalidJSON = errors.New("invalid JSON input")
func CopyDocument(dst ValueWriter, src ValueReader) error
CopyDocument handles copying a document from src to dst.
Deprecated: Copying BSON documents using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
ArrayReader is implemented by types that allow reading values from a BSON array.
type ArrayReader interface { ReadValue() (ValueReader, error) }
ArrayWriter is the interface used to create a BSON or BSON adjacent array. Callers must ensure they call WriteArrayEnd when they have finished creating the array.
type ArrayWriter interface { WriteArrayElement() (ValueWriter, error) WriteArrayEnd() error }
BSONValueReaderPool is a pool for ValueReaders that read BSON.
Deprecated: BSONValueReaderPool will not be supported in Go Driver 2.0.
type BSONValueReaderPool struct {
// contains filtered or unexported fields
}
func NewBSONValueReaderPool() *BSONValueReaderPool
NewBSONValueReaderPool instantiates a new BSONValueReaderPool.
Deprecated: BSONValueReaderPool will not be supported in Go Driver 2.0.
func (bvrp *BSONValueReaderPool) Get(src []byte) ValueReader
Get retrieves a ValueReader from the pool and uses src as the underlying BSON.
Deprecated: BSONValueReaderPool will not be supported in Go Driver 2.0.
func (bvrp *BSONValueReaderPool) Put(vr ValueReader) (ok bool)
Put inserts a ValueReader into the pool. If the ValueReader is not a BSON ValueReader nothing is inserted into the pool and ok will be false.
Deprecated: BSONValueReaderPool will not be supported in Go Driver 2.0.
BSONValueWriterPool is a pool for BSON ValueWriters.
Deprecated: BSONValueWriterPool will not be supported in Go Driver 2.0.
type BSONValueWriterPool struct {
// contains filtered or unexported fields
}
func NewBSONValueWriterPool() *BSONValueWriterPool
NewBSONValueWriterPool creates a new pool for ValueWriter instances that write to BSON.
Deprecated: BSONValueWriterPool will not be supported in Go Driver 2.0.
func (bvwp *BSONValueWriterPool) Get(w io.Writer) ValueWriter
Get retrieves a BSON ValueWriter from the pool and resets it to use w as the destination.
Deprecated: BSONValueWriterPool will not be supported in Go Driver 2.0.
func (bvwp *BSONValueWriterPool) GetAtModeElement(w io.Writer) ValueWriterFlusher
GetAtModeElement retrieves a ValueWriterFlusher from the pool and resets it to use w as the destination.
Deprecated: BSONValueWriterPool will not be supported in Go Driver 2.0.
func (bvwp *BSONValueWriterPool) Put(vw ValueWriter) (ok bool)
Put inserts a ValueWriter into the pool. If the ValueWriter is not a BSON ValueWriter, nothing happens and ok will be false.
Deprecated: BSONValueWriterPool will not be supported in Go Driver 2.0.
BytesReader is a generic interface used to read BSON bytes from a ValueReader. This imterface is meant to be a superset of ValueReader, so that types that implement ValueReader may also implement this interface.
The bytes of the value will be appended to dst.
Deprecated: BytesReader will not be supported in Go Driver 2.0.
type BytesReader interface { ReadValueBytes(dst []byte) (bsontype.Type, []byte, error) }
BytesWriter is the interface used to write BSON bytes to a ValueWriter. This interface is meant to be a superset of ValueWriter, so that types that implement ValueWriter may also implement this interface.
Deprecated: BytesWriter will not be supported in Go Driver 2.0.
type BytesWriter interface { WriteValueBytes(t bsontype.Type, b []byte) error }
Copier is a type that allows copying between ValueReaders, ValueWriters, and []byte values.
Deprecated: Copying BSON documents using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
type Copier struct{}
func NewCopier() Copier
NewCopier creates a new copier with the given registry. If a nil registry is provided a default registry is used.
Deprecated: Copying BSON documents using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) AppendArrayBytes(dst []byte, src ValueReader) ([]byte, error)
AppendArrayBytes copies an array from the ValueReader to dst.
Deprecated: Copying BSON arrays using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) AppendDocumentBytes(dst []byte, src ValueReader) ([]byte, error)
AppendDocumentBytes functions the same as CopyDocumentToBytes, but will append the result to dst.
Deprecated: Copying BSON documents using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) AppendValueBytes(dst []byte, src ValueReader) (bsontype.Type, []byte, error)
AppendValueBytes functions the same as CopyValueToBytes, but will append the result to dst.
Deprecated: Appending individual BSON elements to an existing slice will not be supported in Go Driver 2.0.
func (c Copier) CopyArrayFromBytes(dst ValueWriter, src []byte) error
CopyArrayFromBytes copies the values from a BSON array represented as a []byte to a ValueWriter.
Deprecated: Copying BSON arrays using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) CopyBytesToArrayWriter(dst ArrayWriter, src []byte) error
CopyBytesToArrayWriter copies the values from a BSON Array represented as a []byte to an ArrayWriter.
Deprecated: Copying BSON arrays using the ArrayWriter interface will not be supported in Go Driver 2.0.
func (c Copier) CopyBytesToDocumentWriter(dst DocumentWriter, src []byte) error
CopyBytesToDocumentWriter copies the values from a BSON document represented as a []byte to a DocumentWriter.
Deprecated: Copying BSON documents using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) CopyDocument(dst ValueWriter, src ValueReader) error
CopyDocument handles copying one document from the src to the dst.
Deprecated: Copying BSON documents using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) CopyDocumentFromBytes(dst ValueWriter, src []byte) error
CopyDocumentFromBytes copies the values from a BSON document represented as a []byte to a ValueWriter.
Deprecated: Copying BSON documents using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) CopyDocumentToBytes(src ValueReader) ([]byte, error)
CopyDocumentToBytes copies an entire document from the ValueReader and returns it as bytes.
Deprecated: Copying BSON documents using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) CopyValue(dst ValueWriter, src ValueReader) error
CopyValue will copy a single value from src to dst.
Deprecated: Copying BSON values using the ValueWriter and ValueReader interfaces will not be supported in Go Driver 2.0.
func (c Copier) CopyValueFromBytes(dst ValueWriter, t bsontype.Type, src []byte) error
CopyValueFromBytes will write the value represtend by t and src to dst.
Deprecated: Use go.mongodb.org/mongo-driver/bson.UnmarshalValue instead.
func (c Copier) CopyValueToBytes(src ValueReader) (bsontype.Type, []byte, error)
CopyValueToBytes copies a value from src and returns it as a bsontype.Type and a []byte.
Deprecated: Use go.mongodb.org/mongo-driver/bson.MarshalValue instead.
DocumentReader is implemented by types that allow reading elements from a BSON document.
type DocumentReader interface { ReadElement() (string, ValueReader, error) }
DocumentWriter is the interface used to create a BSON or BSON adjacent document. Callers must ensure they call WriteDocumentEnd when they have finished creating the document.
type DocumentWriter interface { WriteDocumentElement(string) (ValueWriter, error) WriteDocumentEnd() error }
ExtJSONValueReaderPool is a pool for ValueReaders that read ExtJSON.
Deprecated: ExtJSONValueReaderPool will not be supported in Go Driver 2.0.
type ExtJSONValueReaderPool struct {
// contains filtered or unexported fields
}
func NewExtJSONValueReaderPool() *ExtJSONValueReaderPool
NewExtJSONValueReaderPool instantiates a new ExtJSONValueReaderPool.
Deprecated: ExtJSONValueReaderPool will not be supported in Go Driver 2.0.
func (bvrp *ExtJSONValueReaderPool) Get(r io.Reader, canonical bool) (ValueReader, error)
Get retrieves a ValueReader from the pool and uses src as the underlying ExtJSON.
Deprecated: ExtJSONValueReaderPool will not be supported in Go Driver 2.0.
func (bvrp *ExtJSONValueReaderPool) Put(vr ValueReader) (ok bool)
Put inserts a ValueReader into the pool. If the ValueReader is not a ExtJSON ValueReader nothing is inserted into the pool and ok will be false.
Deprecated: ExtJSONValueReaderPool will not be supported in Go Driver 2.0.
ExtJSONValueWriterPool is a pool for ExtJSON ValueWriters.
Deprecated: ExtJSONValueWriterPool will not be supported in Go Driver 2.0.
type ExtJSONValueWriterPool struct {
// contains filtered or unexported fields
}
func NewExtJSONValueWriterPool() *ExtJSONValueWriterPool
NewExtJSONValueWriterPool creates a new pool for ValueWriter instances that write to ExtJSON.
Deprecated: ExtJSONValueWriterPool will not be supported in Go Driver 2.0.
func (bvwp *ExtJSONValueWriterPool) Get(w io.Writer, canonical, escapeHTML bool) ValueWriter
Get retrieves a ExtJSON ValueWriter from the pool and resets it to use w as the destination.
Deprecated: ExtJSONValueWriterPool will not be supported in Go Driver 2.0.
func (bvwp *ExtJSONValueWriterPool) Put(vw ValueWriter) (ok bool)
Put inserts a ValueWriter into the pool. If the ValueWriter is not a ExtJSON ValueWriter, nothing happens and ok will be false.
Deprecated: ExtJSONValueWriterPool will not be supported in Go Driver 2.0.
SliceWriter allows a pointer to a slice of bytes to be used as an io.Writer.
Deprecated: SliceWriter will not be supported in Go Driver 2.0.
type SliceWriter []byte
func (sw *SliceWriter) Write(p []byte) (int, error)
Write writes the bytes to the underlying slice.
Deprecated: SliceWriter will not be supported in Go Driver 2.0.
TransitionError is an error returned when an invalid progressing a ValueReader or ValueWriter state machine occurs. If read is false, the error is for writing
type TransitionError struct {
// contains filtered or unexported fields
}
func (te TransitionError) Error() string
ValueReader is a generic interface used to read values from BSON. This type is implemented by several types with different underlying representations of BSON, such as a bson.Document, raw BSON bytes, or extended JSON.
type ValueReader interface { Type() bsontype.Type Skip() error ReadArray() (ArrayReader, error) ReadBinary() (b []byte, btype byte, err error) ReadBoolean() (bool, error) ReadDocument() (DocumentReader, error) ReadCodeWithScope() (code string, dr DocumentReader, err error) ReadDBPointer() (ns string, oid primitive.ObjectID, err error) ReadDateTime() (int64, error) ReadDecimal128() (primitive.Decimal128, error) ReadDouble() (float64, error) ReadInt32() (int32, error) ReadInt64() (int64, error) ReadJavascript() (code string, err error) ReadMaxKey() error ReadMinKey() error ReadNull() error ReadObjectID() (primitive.ObjectID, error) ReadRegex() (pattern, options string, err error) ReadString() (string, error) ReadSymbol() (symbol string, err error) ReadTimestamp() (t, i uint32, err error) ReadUndefined() error }
func NewBSONDocumentReader(b []byte) ValueReader
NewBSONDocumentReader returns a ValueReader using b for the underlying BSON representation. Parameter b must be a BSON Document.
func NewBSONValueReader(t bsontype.Type, val []byte) ValueReader
NewBSONValueReader returns a ValueReader that starts in the Value mode instead of in top level document mode. This enables the creation of a ValueReader for a single BSON value.
func NewExtJSONValueReader(r io.Reader, canonical bool) (ValueReader, error)
NewExtJSONValueReader creates a new ValueReader from a given io.Reader It will interpret the JSON of r as canonical or relaxed according to the given canonical flag
ValueWriter is the interface used to write BSON values. Implementations of this interface handle creating BSON or BSON adjacent representations of the values.
type ValueWriter interface { WriteArray() (ArrayWriter, error) WriteBinary(b []byte) error WriteBinaryWithSubtype(b []byte, btype byte) error WriteBoolean(bool) error WriteCodeWithScope(code string) (DocumentWriter, error) WriteDBPointer(ns string, oid primitive.ObjectID) error WriteDateTime(dt int64) error WriteDecimal128(primitive.Decimal128) error WriteDouble(float64) error WriteInt32(int32) error WriteInt64(int64) error WriteJavascript(code string) error WriteMaxKey() error WriteMinKey() error WriteNull() error WriteObjectID(primitive.ObjectID) error WriteRegex(pattern, options string) error WriteString(string) error WriteDocument() (DocumentWriter, error) WriteSymbol(symbol string) error WriteTimestamp(t, i uint32) error WriteUndefined() error }
func NewBSONValueWriter(w io.Writer) (ValueWriter, error)
NewBSONValueWriter creates a ValueWriter that writes BSON to w.
This ValueWriter will only write entire documents to the io.Writer and it will buffer the document as it is built.
func NewExtJSONValueWriter(w io.Writer, canonical, escapeHTML bool) (ValueWriter, error)
NewExtJSONValueWriter creates a ValueWriter that writes Extended JSON to w.
ValueWriterFlusher is a superset of ValueWriter that exposes functionality to flush to the underlying buffer.
Deprecated: ValueWriterFlusher will not be supported in Go Driver 2.0.
type ValueWriterFlusher interface { ValueWriter Flush() error }
Name | Synopsis |
---|---|
.. | |
bsonrwtest | Package bsonrwtest provides utilities for testing the "bson/bsonrw" package. |