...

Package bsonrw

import "go.mongodb.org/mongo-driver/bson/bsonrw"
Overview
Index
Subdirectories

Overview ▾

Package bsonrw contains abstractions for reading and writing BSON and BSON like types from sources.

Index ▾

Variables
func CopyDocument(dst ValueWriter, src ValueReader) error
type ArrayReader
type ArrayWriter
type BSONValueReaderPool
    func NewBSONValueReaderPool() *BSONValueReaderPool
    func (bvrp *BSONValueReaderPool) Get(src []byte) ValueReader
    func (bvrp *BSONValueReaderPool) Put(vr ValueReader) (ok bool)
type BSONValueWriterPool
    func NewBSONValueWriterPool() *BSONValueWriterPool
    func (bvwp *BSONValueWriterPool) Get(w io.Writer) ValueWriter
    func (bvwp *BSONValueWriterPool) GetAtModeElement(w io.Writer) ValueWriterFlusher
    func (bvwp *BSONValueWriterPool) Put(vw ValueWriter) (ok bool)
type BytesReader
type BytesWriter
type Copier
    func NewCopier() Copier
    func (c Copier) AppendArrayBytes(dst []byte, src ValueReader) ([]byte, error)
    func (c Copier) AppendDocumentBytes(dst []byte, src ValueReader) ([]byte, error)
    func (c Copier) AppendValueBytes(dst []byte, src ValueReader) (bsontype.Type, []byte, error)
    func (c Copier) CopyArrayFromBytes(dst ValueWriter, src []byte) error
    func (c Copier) CopyBytesToArrayWriter(dst ArrayWriter, src []byte) error
    func (c Copier) CopyBytesToDocumentWriter(dst DocumentWriter, src []byte) error
    func (c Copier) CopyDocument(dst ValueWriter, src ValueReader) error
    func (c Copier) CopyDocumentFromBytes(dst ValueWriter, src []byte) error
    func (c Copier) CopyDocumentToBytes(src ValueReader) ([]byte, error)
    func (c Copier) CopyValue(dst ValueWriter, src ValueReader) error
    func (c Copier) CopyValueFromBytes(dst ValueWriter, t bsontype.Type, src []byte) error
    func (c Copier) CopyValueToBytes(src ValueReader) (bsontype.Type, []byte, error)
type DocumentReader
type DocumentWriter
type ExtJSONValueReaderPool
    func NewExtJSONValueReaderPool() *ExtJSONValueReaderPool
    func (bvrp *ExtJSONValueReaderPool) Get(r io.Reader, canonical bool) (ValueReader, error)
    func (bvrp *ExtJSONValueReaderPool) Put(vr ValueReader) (ok bool)
type ExtJSONValueWriterPool
    func NewExtJSONValueWriterPool() *ExtJSONValueWriterPool
    func (bvwp *ExtJSONValueWriterPool) Get(w io.Writer, canonical, escapeHTML bool) ValueWriter
    func (bvwp *ExtJSONValueWriterPool) Put(vw ValueWriter) (ok bool)
type SliceWriter
    func (sw *SliceWriter) Write(p []byte) (int, error)
type TransitionError
    func (te TransitionError) Error() string
type ValueReader
    func NewBSONDocumentReader(b []byte) ValueReader
    func NewBSONValueReader(t bsontype.Type, val []byte) ValueReader
    func NewExtJSONValueReader(r io.Reader, canonical bool) (ValueReader, error)
type ValueWriter
    func NewBSONValueWriter(w io.Writer) (ValueWriter, error)
    func NewExtJSONValueWriter(w io.Writer, canonical, escapeHTML bool) (ValueWriter, error)
type ValueWriterFlusher

Package files

copier.go doc.go extjson_parser.go extjson_reader.go extjson_tables.go extjson_wrappers.go extjson_writer.go json_scanner.go mode.go reader.go value_reader.go value_writer.go writer.go

Variables

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

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.

type ArrayReader

ArrayReader is implemented by types that allow reading values from a BSON array.

type ArrayReader interface {
    ReadValue() (ValueReader, error)
}

type ArrayWriter

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
}

type BSONValueReaderPool

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

func NewBSONValueReaderPool() *BSONValueReaderPool

NewBSONValueReaderPool instantiates a new BSONValueReaderPool.

Deprecated: BSONValueReaderPool will not be supported in Go Driver 2.0.

func (*BSONValueReaderPool) Get

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 (*BSONValueReaderPool) Put

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.

type BSONValueWriterPool

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

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 (*BSONValueWriterPool) Get

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 (*BSONValueWriterPool) GetAtModeElement

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 (*BSONValueWriterPool) Put

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.

type BytesReader

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)
}

type BytesWriter

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
}

type Copier

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

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 (Copier) AppendArrayBytes

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 (Copier) AppendDocumentBytes

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 (Copier) AppendValueBytes

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 (Copier) CopyArrayFromBytes

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 (Copier) CopyBytesToArrayWriter

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 (Copier) CopyBytesToDocumentWriter

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 (Copier) CopyDocument

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 (Copier) CopyDocumentFromBytes

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 (Copier) CopyDocumentToBytes

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 (Copier) CopyValue

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 (Copier) CopyValueFromBytes

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 (Copier) CopyValueToBytes

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.

type DocumentReader

DocumentReader is implemented by types that allow reading elements from a BSON document.

type DocumentReader interface {
    ReadElement() (string, ValueReader, error)
}

type DocumentWriter

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
}

type ExtJSONValueReaderPool

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

func NewExtJSONValueReaderPool() *ExtJSONValueReaderPool

NewExtJSONValueReaderPool instantiates a new ExtJSONValueReaderPool.

Deprecated: ExtJSONValueReaderPool will not be supported in Go Driver 2.0.

func (*ExtJSONValueReaderPool) Get

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 (*ExtJSONValueReaderPool) Put

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.

type ExtJSONValueWriterPool

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

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 (*ExtJSONValueWriterPool) Get

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 (*ExtJSONValueWriterPool) Put

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.

type SliceWriter

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 (*SliceWriter) Write

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.

type TransitionError

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 (TransitionError) Error

func (te TransitionError) Error() string

type ValueReader

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

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

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

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

type ValueWriter

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

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

func NewExtJSONValueWriter(w io.Writer, canonical, escapeHTML bool) (ValueWriter, error)

NewExtJSONValueWriter creates a ValueWriter that writes Extended JSON to w.

type ValueWriterFlusher

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
}

Subdirectories

Name Synopsis
..
bsonrwtest Package bsonrwtest provides utilities for testing the "bson/bsonrw" package.