mongo-driver: go.mongodb.org/mongo-driver/x/bsonx/bsoncore Index | Examples | Files

package bsoncore

import "go.mongodb.org/mongo-driver/x/bsonx/bsoncore"

Package bsoncore contains functions that can be used to encode and decode BSON elements and values to or from a slice of bytes. These functions are aimed at allowing low level manipulation of BSON and can be used to build a higher level BSON library.

The Read* functions within this package return the values of the element and a boolean indicating if the values are valid. A boolean was used instead of an error because any error that would be returned would be the same: not enough bytes. This library attempts to do no validation, it will only return false if there are not enough bytes for an item to be read. For example, the ReadDocument function checks the length, if that length is larger than the number of bytes availble, it will return false, if there are enough bytes, it will return those bytes and true. It is the consumers responsibility to validate those bytes.

The Append* functions within this package will append the type value to the given dst slice. If the slice has enough capacity, it will not grow the slice. The Append*Element functions within this package operate in the same way, but additionally append the BSON type and the key before the value.

Index

Examples

Package Files

bsoncore.go document.go document_sequence.go element.go tables.go value.go

Constants

const EmptyDocumentLength = 5

EmptyDocumentLength is the length of a document that has been started/ended but has no elements.

Variables

var BuildDocumentFromElements = BuildDocument

BuildDocumentFromElements is an alaias for the BuildDocument function.

var ErrCorruptedDocument = errors.New("invalid DocumentSequence: corrupted document")

ErrCorruptedDocument is returned when a full document couldn't be read from the sequence.

var ErrElementNotFound = errors.New("element not found")

ErrElementNotFound indicates that an Element matching a certain condition does not exist.

var ErrEmptyKey = errors.New("empty key provided")

ErrEmptyKey indicates that no key was provided to a Lookup method.

var ErrInvalidDocumentSequenceStyle = errors.New("invalid DocumentSequenceStyle")

ErrInvalidDocumentSequenceStyle is returned when an unknown DocumentSequenceStyle is set on a DocumentSequence.

var ErrInvalidLength = errors.New("document length is invalid")

ErrInvalidLength indicates that a length in a binary representation of a BSON document is invalid.

var ErrNilReader = errors.New("nil reader")

ErrNilReader indicates that an operation was attempted on a nil io.Reader.

var ErrNonDocument = errors.New("invalid DocumentSequence: a non-document value was found in sequence")

ErrNonDocument is returned when a DocumentSequence contains a non-document BSON value.

var ErrOutOfBounds = errors.New("out of bounds")

ErrOutOfBounds indicates that an index provided to access something was invalid.

func AppendArray Uses

func AppendArray(dst []byte, arr []byte) []byte

AppendArray will append arr to dst and return the extended buffer.

func AppendArrayElement Uses

func AppendArrayElement(dst []byte, key string, arr []byte) []byte

AppendArrayElement will append a BSON array element using key and arr to dst and return the extended buffer.

func AppendArrayElementStart Uses

func AppendArrayElementStart(dst []byte, key string) (index int32, b []byte)

AppendArrayElementStart appends an array element header and then the length bytes for an array, returning the index where the length starts.

func AppendArrayEnd Uses

func AppendArrayEnd(dst []byte, index int32) ([]byte, error)

AppendArrayEnd appends the null byte to an array and calculates the length, inserting that calculated length starting at index.

func AppendArrayStart Uses

func AppendArrayStart(dst []byte) (index int32, b []byte)

AppendArrayStart appends the length bytes to an array and then returns the index of the start of those length bytes.

func AppendBinary Uses

func AppendBinary(dst []byte, subtype byte, b []byte) []byte

AppendBinary will append subtype and b to dst and return the extended buffer.

func AppendBinaryElement Uses

func AppendBinaryElement(dst []byte, key string, subtype byte, b []byte) []byte

AppendBinaryElement will append a BSON binary element using key, subtype, and b to dst and return the extended buffer.

func AppendBoolean Uses

func AppendBoolean(dst []byte, b bool) []byte

AppendBoolean will append b to dst and return the extended buffer.

func AppendBooleanElement Uses

func AppendBooleanElement(dst []byte, key string, b bool) []byte

AppendBooleanElement will append a BSON boolean element using key and b to dst and return the extended buffer.

func AppendCodeWithScope Uses

func AppendCodeWithScope(dst []byte, code string, scope []byte) []byte

AppendCodeWithScope will append code and scope to dst and return the extended buffer.

func AppendCodeWithScopeElement Uses

func AppendCodeWithScopeElement(dst []byte, key, code string, scope []byte) []byte

AppendCodeWithScopeElement will append a BSON code with scope element using key, code, and scope to dst and return the extended buffer.

func AppendDBPointer Uses

func AppendDBPointer(dst []byte, ns string, oid primitive.ObjectID) []byte

AppendDBPointer will append ns and oid to dst and return the extended buffer.

func AppendDBPointerElement Uses

func AppendDBPointerElement(dst []byte, key, ns string, oid primitive.ObjectID) []byte

AppendDBPointerElement will append a BSON DBPointer element using key, ns, and oid to dst and return the extended buffer.

func AppendDateTime Uses

func AppendDateTime(dst []byte, dt int64) []byte

AppendDateTime will append dt to dst and return the extended buffer.

func AppendDateTimeElement Uses

func AppendDateTimeElement(dst []byte, key string, dt int64) []byte

AppendDateTimeElement will append a BSON datetime element using key and dt to dst and return the extended buffer.

func AppendDecimal128 Uses

func AppendDecimal128(dst []byte, d128 primitive.Decimal128) []byte

AppendDecimal128 will append d128 to dst and return the extended buffer.

func AppendDecimal128Element Uses

func AppendDecimal128Element(dst []byte, key string, d128 primitive.Decimal128) []byte

AppendDecimal128Element will append a BSON primitive.28 element using key and d128 to dst and return the extended buffer.

func AppendDocument Uses

func AppendDocument(dst []byte, doc []byte) []byte

AppendDocument will append doc to dst and return the extended buffer.

func AppendDocumentElement Uses

func AppendDocumentElement(dst []byte, key string, doc []byte) []byte

AppendDocumentElement will append a BSON embeded document element using key and doc to dst and return the extended buffer.

func AppendDocumentElementStart Uses

func AppendDocumentElementStart(dst []byte, key string) (index int32, b []byte)

AppendDocumentElementStart writes a document element header and then reserves the length bytes.

func AppendDocumentEnd Uses

func AppendDocumentEnd(dst []byte, index int32) ([]byte, error)

AppendDocumentEnd writes the null byte for a document and updates the length of the document. The index should be the beginning of the document's length bytes.

func AppendDocumentStart Uses

func AppendDocumentStart(dst []byte) (index int32, b []byte)

AppendDocumentStart reserves a document's length and returns the index where the length begins. This index can later be used to write the length of the document.

TODO(skriptble): We really need AppendDocumentStart and AppendDocumentEnd. AppendDocumentStart would handle calling ReserveLength and providing the index of the start of the document. AppendDocumentEnd would handle taking that start index, adding the null byte, calculating the length, and filling in the length at the start of the document.

func AppendDocumentStartInline Uses

func AppendDocumentStartInline(dst []byte, index *int32) []byte

AppendDocumentStartInline functions the same as AppendDocumentStart but takes a pointer to the index int32 which allows this function to be used inline.

func AppendDouble Uses

func AppendDouble(dst []byte, f float64) []byte

AppendDouble will append f to dst and return the extended buffer.

func AppendDoubleElement Uses

func AppendDoubleElement(dst []byte, key string, f float64) []byte

AppendDoubleElement will append a BSON double element using key and f to dst and return the extended buffer.

func AppendHeader Uses

func AppendHeader(dst []byte, t bsontype.Type, key string) []byte

AppendHeader will append Type t and key to dst and return the extended buffer.

func AppendInt32 Uses

func AppendInt32(dst []byte, i32 int32) []byte

AppendInt32 will append i32 to dst and return the extended buffer.

func AppendInt32Element Uses

func AppendInt32Element(dst []byte, key string, i32 int32) []byte

AppendInt32Element will append a BSON int32 element using key and i32 to dst and return the extended buffer.

func AppendInt64 Uses

func AppendInt64(dst []byte, i64 int64) []byte

AppendInt64 will append i64 to dst and return the extended buffer.

func AppendInt64Element Uses

func AppendInt64Element(dst []byte, key string, i64 int64) []byte

AppendInt64Element will append a BSON int64 element using key and i64 to dst and return the extended buffer.

func AppendJavaScript Uses

func AppendJavaScript(dst []byte, js string) []byte

AppendJavaScript will append js to dst and return the extended buffer.

func AppendJavaScriptElement Uses

func AppendJavaScriptElement(dst []byte, key, js string) []byte

AppendJavaScriptElement will append a BSON JavaScript element using key and js to dst and return the extended buffer.

func AppendKey Uses

func AppendKey(dst []byte, key string) []byte

AppendKey will append key to dst and return the extended buffer.

func AppendMaxKeyElement Uses

func AppendMaxKeyElement(dst []byte, key string) []byte

AppendMaxKeyElement will append a BSON max key element using key to dst and return the extended buffer.

func AppendMinKeyElement Uses

func AppendMinKeyElement(dst []byte, key string) []byte

AppendMinKeyElement will append a BSON min key element using key to dst and return the extended buffer.

func AppendNullElement Uses

func AppendNullElement(dst []byte, key string) []byte

AppendNullElement will append a BSON null element using key to dst and return the extended buffer.

func AppendObjectID Uses

func AppendObjectID(dst []byte, oid primitive.ObjectID) []byte

AppendObjectID will append oid to dst and return the extended buffer.

func AppendObjectIDElement Uses

func AppendObjectIDElement(dst []byte, key string, oid primitive.ObjectID) []byte

AppendObjectIDElement will append a BSON ObjectID element using key and oid to dst and return the extended buffer.

func AppendRegex Uses

func AppendRegex(dst []byte, pattern, options string) []byte

AppendRegex will append pattern and options to dst and return the extended buffer.

func AppendRegexElement Uses

func AppendRegexElement(dst []byte, key, pattern, options string) []byte

AppendRegexElement will append a BSON regex element using key, pattern, and options to dst and return the extended buffer.

func AppendString Uses

func AppendString(dst []byte, s string) []byte

AppendString will append s to dst and return the extended buffer.

func AppendStringElement Uses

func AppendStringElement(dst []byte, key, val string) []byte

AppendStringElement will append a BSON string element using key and val to dst and return the extended buffer.

func AppendSymbol Uses

func AppendSymbol(dst []byte, symbol string) []byte

AppendSymbol will append symbol to dst and return the extended buffer.

func AppendSymbolElement Uses

func AppendSymbolElement(dst []byte, key, symbol string) []byte

AppendSymbolElement will append a BSON symbol element using key and symbol to dst and return the extended buffer.

func AppendTime Uses

func AppendTime(dst []byte, t time.Time) []byte

AppendTime will append time as a BSON DateTime to dst and return the extended buffer.

func AppendTimeElement Uses

func AppendTimeElement(dst []byte, key string, t time.Time) []byte

AppendTimeElement will append a BSON datetime element using key and dt to dst and return the extended buffer.

func AppendTimestamp Uses

func AppendTimestamp(dst []byte, t, i uint32) []byte

AppendTimestamp will append t and i to dst and return the extended buffer.

func AppendTimestampElement Uses

func AppendTimestampElement(dst []byte, key string, t, i uint32) []byte

AppendTimestampElement will append a BSON timestamp element using key, t, and i to dst and return the extended buffer.

func AppendType Uses

func AppendType(dst []byte, t bsontype.Type) []byte

AppendType will append t to dst and return the extended buffer.

func AppendUndefinedElement Uses

func AppendUndefinedElement(dst []byte, key string) []byte

AppendUndefinedElement will append a BSON undefined element using key to dst and return the extended buffer.

func AppendValueElement Uses

func AppendValueElement(dst []byte, key string, value Value) []byte

AppendValueElement appends value to dst as an element using key as the element's key.

func BuildArray Uses

func BuildArray(dst []byte, values ...Value) []byte

BuildArray will append a BSON array to dst built from values.

func BuildArrayElement Uses

func BuildArrayElement(dst []byte, key string, values ...Value) []byte

BuildArrayElement will create an array element using the provided values.

func BuildDocument Uses

func BuildDocument(dst []byte, elems ...[]byte) []byte

BuildDocument will create a document with the given slice of elements and will append it to dst and return the extended buffer.

func BuildDocumentElement Uses

func BuildDocumentElement(dst []byte, key string, elems ...[]byte) []byte

BuildDocumentElement will append a BSON embedded document elemnt using key and the provided elements and return the extended buffer.

func EqualValue Uses

func EqualValue(t1, t2 bsontype.Type, v1, v2 []byte) bool

EqualValue will return true if the two values are equal.

func NewDocumentLengthError Uses

func NewDocumentLengthError(length, rem int) error

NewDocumentLengthError creates and returns an error for when the length of a document exceeds the bytes available.

func ReadBinary Uses

func ReadBinary(src []byte) (subtype byte, bin []byte, rem []byte, ok bool)

ReadBinary will read a subtype and bin from src. If there are not enough bytes it will return false.

func ReadBoolean Uses

func ReadBoolean(src []byte) (bool, []byte, bool)

ReadBoolean will read a bool from src. If there are not enough bytes it will return false.

func ReadCodeWithScope Uses

func ReadCodeWithScope(src []byte) (code string, scope []byte, rem []byte, ok bool)

ReadCodeWithScope will read code and scope from src. If there are not enough bytes it will return false.

func ReadDBPointer Uses

func ReadDBPointer(src []byte) (ns string, oid primitive.ObjectID, rem []byte, ok bool)

ReadDBPointer will read a ns and oid from src. If there are not enough bytes it will return false.

func ReadDateTime Uses

func ReadDateTime(src []byte) (int64, []byte, bool)

ReadDateTime will read an int64 datetime from src. If there are not enough bytes it will return false.

func ReadDecimal128 Uses

func ReadDecimal128(src []byte) (primitive.Decimal128, []byte, bool)

ReadDecimal128 will read a primitive.Decimal128 from src. If there are not enough bytes it will return false.

func ReadDouble Uses

func ReadDouble(src []byte) (float64, []byte, bool)

ReadDouble will read a float64 from src. If there are not enough bytes it will return false.

func ReadHeader Uses

func ReadHeader(src []byte) (t bsontype.Type, key string, rem []byte, ok bool)

ReadHeader will read a type byte and a key from src. If both of these values cannot be read, false is returned.

func ReadHeaderBytes Uses

func ReadHeaderBytes(src []byte) (header []byte, rem []byte, ok bool)

ReadHeaderBytes will read a type and a key from src and the remainder of the bytes are returned as rem. If either the type or key cannot be red, ok will be false.

func ReadInt32 Uses

func ReadInt32(src []byte) (int32, []byte, bool)

ReadInt32 will read an int32 from src. If there are not enough bytes it will return false.

func ReadInt64 Uses

func ReadInt64(src []byte) (int64, []byte, bool)

ReadInt64 will read an int64 from src. If there are not enough bytes it will return false.

func ReadJavaScript Uses

func ReadJavaScript(src []byte) (js string, rem []byte, ok bool)

ReadJavaScript will read a js string from src. If there are not enough bytes it will return false.

func ReadKey Uses

func ReadKey(src []byte) (string, []byte, bool)

ReadKey will read a key from src. The 0x00 byte will not be present in the returned string. If there are not enough bytes available, false is returned.

func ReadKeyBytes Uses

func ReadKeyBytes(src []byte) ([]byte, []byte, bool)

ReadKeyBytes will read a key from src as bytes. The 0x00 byte will not be present in the returned string. If there are not enough bytes available, false is returned.

func ReadLength Uses

func ReadLength(src []byte) (int32, []byte, bool)

ReadLength reads an int32 length from src and returns the length and the remaining bytes. If there aren't enough bytes to read a valid length, src is returned unomdified and the returned bool will be false.

func ReadObjectID Uses

func ReadObjectID(src []byte) (primitive.ObjectID, []byte, bool)

ReadObjectID will read an ObjectID from src. If there are not enough bytes it will return false.

func ReadRegex Uses

func ReadRegex(src []byte) (pattern, options string, rem []byte, ok bool)

ReadRegex will read a pattern and options from src. If there are not enough bytes it will return false.

func ReadString Uses

func ReadString(src []byte) (string, []byte, bool)

ReadString will read a string from src. If there are not enough bytes it will return false.

func ReadSymbol Uses

func ReadSymbol(src []byte) (symbol string, rem []byte, ok bool)

ReadSymbol will read a symbol string from src. If there are not enough bytes it will return false.

func ReadTime Uses

func ReadTime(src []byte) (time.Time, []byte, bool)

ReadTime will read an time.Time datetime from src. If there are not enough bytes it will return false.

func ReadTimestamp Uses

func ReadTimestamp(src []byte) (t, i uint32, rem []byte, ok bool)

ReadTimestamp will read t and i from src. If there are not enough bytes it will return false.

func ReadType Uses

func ReadType(src []byte) (bsontype.Type, []byte, bool)

ReadType will return the first byte of the provided []byte as a type. If there is no availble byte, false is returned.

func ReserveLength Uses

func ReserveLength(dst []byte) (int32, []byte)

ReserveLength reserves the space required for length and returns the index where to write the length and the []byte with reserved space.

func UpdateLength Uses

func UpdateLength(dst []byte, index, length int32) []byte

UpdateLength updates the length at index with length and returns the []byte.

type Array Uses

type Array = Document

Array is a raw bytes representation of a BSON array.

type Document Uses

type Document []byte

Document is a raw bytes representation of a BSON document.

func NewDocumentFromReader Uses

func NewDocumentFromReader(r io.Reader) (Document, error)

NewDocumentFromReader reads a document from r. This function will only validate the length is correct and that the document ends with a null byte.

func ReadArray Uses

func ReadArray(src []byte) (arr Document, rem []byte, ok bool)

ReadArray will read an array from src. If there are not enough bytes it will return false.

func ReadDocument Uses

func ReadDocument(src []byte) (doc Document, rem []byte, ok bool)

ReadDocument will read a document from src. If there are not enough bytes it will return false.

func (Document) DebugString Uses

func (d Document) DebugString() string

DebugString outputs a human readable version of Document. It will attempt to stringify the valid components of the document even if the entire document is not valid.

func (Document) Elements Uses

func (d Document) Elements() ([]Element, error)

Elements returns this document as a slice of elements. The returned slice will contain valid elements. If the document is not valid, the elements up to the invalid point will be returned along with an error.

func (Document) Index Uses

func (d Document) Index(index uint) Element

Index searches for and retrieves the element at the given index. This method will panic if the document is invalid or if the index is out of bounds.

func (Document) IndexErr Uses

func (d Document) IndexErr(index uint) (Element, error)

IndexErr searches for and retrieves the element at the given index.

func (Document) Lookup Uses

func (d Document) Lookup(key ...string) Value

Lookup searches the document, potentially recursively, for the given key. If there are multiple keys provided, this method will recurse down, as long as the top and intermediate nodes are either documents or arrays. If an error occurs or if the value doesn't exist, an empty Value is returned.

func (Document) LookupErr Uses

func (d Document) LookupErr(key ...string) (Value, error)

LookupErr is the same as Lookup, except it returns an error in addition to an empty Value.

func (Document) String Uses

func (d Document) String() string

String outputs an ExtendedJSON version of Document. If the document is not valid, this method returns an empty string.

func (Document) Validate Uses

func (d Document) Validate() error

Validate validates the document and ensures the elements contained within are valid.

Code:

doc := make(Document, 500)
doc[250], doc[251], doc[252], doc[253], doc[254] = 0x05, 0x00, 0x00, 0x00, 0x00
err := doc[250:].Validate()
fmt.Println(err)

Output:

<nil>

func (Document) Values Uses

func (d Document) Values() ([]Value, error)

Values returns this document as a slice of values. The returned slice will contain valid values. If the document is not valid, the values up to the invalid point will be returned along with an error.

type DocumentSequence Uses

type DocumentSequence struct {
    Style DocumentSequenceStyle
    Data  []byte
    Pos   int
}

DocumentSequence represents a sequence of documents. The Style field indicates how the documents are laid out inside of the Data field.

func (*DocumentSequence) DocumentCount Uses

func (ds *DocumentSequence) DocumentCount() int

DocumentCount returns the number of documents in the sequence.

func (*DocumentSequence) Documents Uses

func (ds *DocumentSequence) Documents() ([]Document, error)

Documents returns a slice of the documents. If nil either the Data field is also nil or could not be properly read.

func (*DocumentSequence) Empty Uses

func (ds *DocumentSequence) Empty() bool

Empty returns true if the sequence is empty. It always returns true for unknown sequence styles.

func (*DocumentSequence) Next Uses

func (ds *DocumentSequence) Next() (Document, error)

Next retrieves the next document from this sequence and returns it. This method will return io.EOF when it has reached the end of the sequence.

func (*DocumentSequence) ResetIterator Uses

func (ds *DocumentSequence) ResetIterator()

ResetIterator resets the iteration point for the Next method to the beginning of the document sequence.

type DocumentSequenceStyle Uses

type DocumentSequenceStyle uint32

DocumentSequenceStyle is used to represent how a document sequence is laid out in a slice of bytes.

const (
    SequenceStyle DocumentSequenceStyle
    ArrayStyle
)

These constants are the valid styles for a DocumentSequence.

type DocumentValidationError Uses

type DocumentValidationError string

DocumentValidationError is an error type returned when attempting to validate a document.

const ErrMissingNull DocumentValidationError = "document end is missing null byte"

ErrMissingNull is returned when a document's last byte is not null.

func (DocumentValidationError) Error Uses

func (dve DocumentValidationError) Error() string

type Element Uses

type Element []byte

Element is a raw bytes representation of a BSON element.

func ReadElement Uses

func ReadElement(src []byte) (Element, []byte, bool)

ReadElement reads the next full element from src. It returns the element, the remaining bytes in the slice, and a boolean indicating if the read was successful.

func (Element) CompareKey Uses

func (e Element) CompareKey(key []byte) bool

CompareKey will compare this element's key to key. This method makes it easy to compare keys without needing to allocate a string. The key may be null terminated. If a valid key cannot be read this method will return false.

func (Element) DebugString Uses

func (e Element) DebugString() string

DebugString outputs a human readable version of RawElement. It will attempt to stringify the valid components of the element even if the entire element is not valid.

func (Element) Key Uses

func (e Element) Key() string

Key returns the key for this element. If the element is not valid, this method returns an empty string. If knowing if the element is valid is important, use KeyErr.

func (Element) KeyBytes Uses

func (e Element) KeyBytes() []byte

KeyBytes returns the key for this element as a []byte. If the element is not valid, this method returns an empty string. If knowing if the element is valid is important, use KeyErr. This method will not include the null byte at the end of the key in the slice of bytes.

func (Element) KeyBytesErr Uses

func (e Element) KeyBytesErr() ([]byte, error)

KeyBytesErr returns the key for this element as a []byte, returning an error if the element is not valid.

func (Element) KeyErr Uses

func (e Element) KeyErr() (string, error)

KeyErr returns the key for this element, returning an error if the element is not valid.

func (Element) String Uses

func (e Element) String() string

String implements the fmt.String interface. The output will be in extended JSON format.

func (Element) Validate Uses

func (e Element) Validate() error

Validate ensures the element is a valid BSON element.

func (Element) Value Uses

func (e Element) Value() Value

Value returns the value of this element. If the element is not valid, this method returns an empty Value. If knowing if the element is valid is important, use ValueErr.

func (Element) ValueErr Uses

func (e Element) ValueErr() (Value, error)

ValueErr returns the value for this element, returning an error if the element is not valid.

type ElementTypeError Uses

type ElementTypeError struct {
    Method string
    Type   bsontype.Type
}

ElementTypeError specifies that a method to obtain a BSON value an incorrect type was called on a bson.Value.

func (ElementTypeError) Error Uses

func (ete ElementTypeError) Error() string

Error implements the error interface.

type InsufficientBytesError Uses

type InsufficientBytesError struct {
    Source    []byte
    Remaining []byte
    Stack     stack.CallStack
}

InsufficientBytesError indicates that there were not enough bytes to read the next component.

func NewInsufficientBytesError Uses

func NewInsufficientBytesError(src, rem []byte) InsufficientBytesError

NewInsufficientBytesError creates a new InsufficientBytesError with the given Document, remaining bytes, and the current stack.

func (InsufficientBytesError) Equal Uses

func (ibe InsufficientBytesError) Equal(err2 error) bool

Equal checks that err2 also is an ErrTooSmall.

func (InsufficientBytesError) Error Uses

func (ibe InsufficientBytesError) Error() string

Error implements the error interface.

func (InsufficientBytesError) ErrorStack Uses

func (ibe InsufficientBytesError) ErrorStack() string

ErrorStack returns a string representing the stack at the point where the error occurred.

type InvalidDepthTraversalError Uses

type InvalidDepthTraversalError struct {
    Key  string
    Type bsontype.Type
}

InvalidDepthTraversalError is returned when attempting a recursive Lookup when one component of the path is neither an embedded document nor an array.

func (InvalidDepthTraversalError) Error Uses

func (idte InvalidDepthTraversalError) Error() string

type MalformedElementError Uses

type MalformedElementError string

MalformedElementError represents a class of errors that RawElement methods return.

const ErrElementMissingKey MalformedElementError = "element is missing key"

ErrElementMissingKey is returned when a RawElement is missing a key.

const ErrElementMissingType MalformedElementError = "element is missing type"

ErrElementMissingType is returned when a RawElement is missing a type.

func (MalformedElementError) Error Uses

func (mee MalformedElementError) Error() string

type Value Uses

type Value struct {
    Type bsontype.Type
    Data []byte
}

Value represents a BSON value with a type and raw bytes.

func BuildDocumentValue Uses

func BuildDocumentValue(elems ...[]byte) Value

BuildDocumentValue creates an Embedded Document value from the given elements.

func ReadValue Uses

func ReadValue(src []byte, t bsontype.Type) (Value, []byte, bool)

ReadValue reads the next value as the provided types and returns a Value, the remaining bytes, and a boolean indicating if the read was successful.

func (*Value) Add Uses

func (v *Value) Add(v2 Value) error

Add will add this value to another. This is currently only implemented for strings and numbers. If either value is a string, the other type is coerced into a string and added to the other.

This method will alter v and will attempt to reuse the []byte of v. If the []byte is too small, it will be expanded.

func (Value) Array Uses

func (v Value) Array() Document

Array returns the BSON array the Value represents as an Array. It panics if the value is a BSON type other than array.

func (Value) ArrayOK Uses

func (v Value) ArrayOK() (Document, bool)

ArrayOK is the same as Array, except it returns a boolean instead of panicking.

func (Value) AsFloat64 Uses

func (v Value) AsFloat64() float64

AsFloat64 returns a BSON number as an float64. If the BSON type is not a numeric one, this method will panic.

TODO(skriptble): Add support for Decimal128.

func (Value) AsFloat64OK Uses

func (v Value) AsFloat64OK() (float64, bool)

AsFloat64OK functions the same as AsFloat64 but returns a boolean instead of panicking. False indicates an error.

TODO(skriptble): Add support for Decimal128.

func (Value) AsInt32 Uses

func (v Value) AsInt32() int32

AsInt32 returns a BSON number as an int32. If the BSON type is not a numeric one, this method will panic.

TODO(skriptble): Add support for Decimal128.

func (Value) AsInt32OK Uses

func (v Value) AsInt32OK() (int32, bool)

AsInt32OK functions the same as AsInt32 but returns a boolean instead of panicking. False indicates an error.

TODO(skriptble): Add support for Decimal128.

func (Value) AsInt64 Uses

func (v Value) AsInt64() int64

AsInt64 returns a BSON number as an int64. If the BSON type is not a numeric one, this method will panic.

TODO(skriptble): Add support for Decimal128.

func (Value) AsInt64OK Uses

func (v Value) AsInt64OK() (int64, bool)

AsInt64OK functions the same as AsInt64 but returns a boolean instead of panicking. False indicates an error.

TODO(skriptble): Add support for Decimal128.

func (Value) Binary Uses

func (v Value) Binary() (subtype byte, data []byte)

Binary returns the BSON binary value the Value represents. It panics if the value is a BSON type other than binary.

func (Value) BinaryOK Uses

func (v Value) BinaryOK() (subtype byte, data []byte, ok bool)

BinaryOK is the same as Binary, except it returns a boolean instead of panicking.

func (Value) Boolean Uses

func (v Value) Boolean() bool

Boolean returns the boolean value the Value represents. It panics if the value is a BSON type other than boolean.

func (Value) BooleanOK Uses

func (v Value) BooleanOK() (bool, bool)

BooleanOK is the same as Boolean, except it returns a boolean instead of panicking.

func (Value) CodeWithScope Uses

func (v Value) CodeWithScope() (string, Document)

CodeWithScope returns the BSON JavaScript code with scope the Value represents. It panics if the value is a BSON type other than JavaScript code with scope.

func (Value) CodeWithScopeOK Uses

func (v Value) CodeWithScopeOK() (string, Document, bool)

CodeWithScopeOK is the same as CodeWithScope, except that it returns a boolean instead of panicking.

func (Value) DBPointer Uses

func (v Value) DBPointer() (string, primitive.ObjectID)

DBPointer returns the BSON dbpointer value the Value represents. It panics if the value is a BSON type other than DBPointer.

func (Value) DBPointerOK Uses

func (v Value) DBPointerOK() (string, primitive.ObjectID, bool)

DBPointerOK is the same as DBPoitner, except that it returns a boolean instead of panicking.

func (Value) DateTime Uses

func (v Value) DateTime() int64

DateTime returns the BSON datetime value the Value represents as a unix timestamp. It panics if the value is a BSON type other than datetime.

func (Value) DateTimeOK Uses

func (v Value) DateTimeOK() (int64, bool)

DateTimeOK is the same as DateTime, except it returns a boolean instead of panicking.

func (Value) DebugString Uses

func (v Value) DebugString() string

DebugString outputs a human readable version of Document. It will attempt to stringify the valid components of the document even if the entire document is not valid.

func (Value) Decimal128 Uses

func (v Value) Decimal128() primitive.Decimal128

Decimal128 returns the decimal the Value represents. It panics if the value is a BSON type other than decimal.

func (Value) Decimal128OK Uses

func (v Value) Decimal128OK() (primitive.Decimal128, bool)

Decimal128OK is the same as Decimal128, except that it returns a boolean instead of panicking.

func (Value) Document Uses

func (v Value) Document() Document

Document returns the BSON document the Value represents as a Document. It panics if the value is a BSON type other than document.

func (Value) DocumentOK Uses

func (v Value) DocumentOK() (Document, bool)

DocumentOK is the same as Document, except it returns a boolean instead of panicking.

func (Value) Double Uses

func (v Value) Double() float64

Double returns the float64 value for this element. It panics if e's BSON type is not bsontype.Double.

func (Value) DoubleOK Uses

func (v Value) DoubleOK() (float64, bool)

DoubleOK is the same as Double, but returns a boolean instead of panicking.

func (Value) Equal Uses

func (v Value) Equal(v2 Value) bool

Equal compaes v to v2 and returns true if they are equal.

func (Value) Int32 Uses

func (v Value) Int32() int32

Int32 returns the int32 the Value represents. It panics if the value is a BSON type other than int32.

func (Value) Int32OK Uses

func (v Value) Int32OK() (int32, bool)

Int32OK is the same as Int32, except that it returns a boolean instead of panicking.

func (Value) Int64 Uses

func (v Value) Int64() int64

Int64 returns the int64 the Value represents. It panics if the value is a BSON type other than int64.

func (Value) Int64OK Uses

func (v Value) Int64OK() (int64, bool)

Int64OK is the same as Int64, except that it returns a boolean instead of panicking.

func (Value) IsNumber Uses

func (v Value) IsNumber() bool

IsNumber returns true if the type of v is a numeric BSON type.

func (Value) JavaScript Uses

func (v Value) JavaScript() string

JavaScript returns the BSON JavaScript code value the Value represents. It panics if the value is a BSON type other than JavaScript code.

func (Value) JavaScriptOK Uses

func (v Value) JavaScriptOK() (string, bool)

JavaScriptOK is the same as Javascript, excepti that it returns a boolean instead of panicking.

func (Value) ObjectID Uses

func (v Value) ObjectID() primitive.ObjectID

ObjectID returns the BSON objectid value the Value represents. It panics if the value is a BSON type other than objectid.

func (Value) ObjectIDOK Uses

func (v Value) ObjectIDOK() (primitive.ObjectID, bool)

ObjectIDOK is the same as ObjectID, except it returns a boolean instead of panicking.

func (Value) Regex Uses

func (v Value) Regex() (pattern, options string)

Regex returns the BSON regex value the Value represents. It panics if the value is a BSON type other than regex.

func (Value) RegexOK Uses

func (v Value) RegexOK() (pattern, options string, ok bool)

RegexOK is the same as Regex, except it returns a boolean instead of panicking.

func (Value) String Uses

func (v Value) String() string

String implements the fmt.String interface. This method will return values in extended JSON format. If the value is not valid, this returns an empty string

func (Value) StringValue Uses

func (v Value) StringValue() string

StringValue returns the string balue for this element. It panics if e's BSON type is not bsontype.String.

NOTE: This method is called StringValue to avoid a collision with the String method which implements the fmt.Stringer interface.

func (Value) StringValueOK Uses

func (v Value) StringValueOK() (string, bool)

StringValueOK is the same as StringValue, but returns a boolean instead of panicking.

func (Value) Symbol Uses

func (v Value) Symbol() string

Symbol returns the BSON symbol value the Value represents. It panics if the value is a BSON type other than symbol.

func (Value) SymbolOK Uses

func (v Value) SymbolOK() (string, bool)

SymbolOK is the same as Symbol, excepti that it returns a boolean instead of panicking.

func (Value) Time Uses

func (v Value) Time() time.Time

Time returns the BSON datetime value the Value represents. It panics if the value is a BSON type other than datetime.

func (Value) TimeOK Uses

func (v Value) TimeOK() (time.Time, bool)

TimeOK is the same as Time, except it returns a boolean instead of panicking.

func (Value) Timestamp Uses

func (v Value) Timestamp() (t, i uint32)

Timestamp returns the BSON timestamp value the Value represents. It panics if the value is a BSON type other than timestamp.

func (Value) TimestampOK Uses

func (v Value) TimestampOK() (t, i uint32, ok bool)

TimestampOK is the same as Timestamp, except that it returns a boolean instead of panicking.

func (Value) Validate Uses

func (v Value) Validate() error

Validate ensures the value is a valid BSON value.

Package bsoncore imports 14 packages (graph) and is imported by 22 packages. Updated 2019-07-03. Refresh now. Tools for package owners.