llbson

package
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package llbson 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendArray

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

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

func AppendArrayElement

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 AppendBinary

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

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

func AppendBinaryElement

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

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

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

func AppendBooleanElement

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

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

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

func AppendCodeWithScopeElement

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

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

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

func AppendDBPointerElement

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

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

func AppendDateTime

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

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

func AppendDateTimeElement

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

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

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

func AppendDecimal128Element

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

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

func AppendDocument

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

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

func AppendDocumentElement

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 AppendDouble

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

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

func AppendDoubleElement

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

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

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

func AppendInt32

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

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

func AppendInt32Element

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

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

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

func AppendInt64Element

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

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

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

func AppendJavaScriptElement

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

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

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

func AppendMaxKeyElement

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

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

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

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

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

func AppendObjectIDElement

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

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

func AppendRegex

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

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

func AppendRegexElement

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

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

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

func AppendStringElement

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

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

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

func AppendSymbolElement

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 AppendTimestamp

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

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

func AppendTimestampElement

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

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

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

func AppendUndefinedElement

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

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

func EqualValue added in v0.0.15

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

EqualValue will return true if the two values are equal.

func ReadArray

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

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

func ReadBinary

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

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

func ReadBoolean

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

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

func ReadCodeWithScope

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

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

func ReadDBPointer

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

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

func ReadDateTime

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

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

func ReadDecimal128

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

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

func ReadDocument

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

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

func ReadDouble

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

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

func ReadInt32

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

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

func ReadInt64

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

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

func ReadJavaScript

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

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

func ReadKey

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

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

func ReadObjectID

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

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

func ReadRegex

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

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

func ReadString

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

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

func ReadSymbol

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

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

func ReadTimestamp

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

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

Types

type Type

type Type byte

Type represents a BSON type.

const (
	TypeDouble           Type = 0x01
	TypeString           Type = 0x02
	TypeEmbeddedDocument Type = 0x03
	TypeArray            Type = 0x04
	TypeBinary           Type = 0x05
	TypeUndefined        Type = 0x06
	TypeObjectID         Type = 0x07
	TypeBoolean          Type = 0x08
	TypeDateTime         Type = 0x09
	TypeNull             Type = 0x0A
	TypeRegex            Type = 0x0B
	TypeDBPointer        Type = 0x0C
	TypeJavaScript       Type = 0x0D
	TypeSymbol           Type = 0x0E
	TypeCodeWithScope    Type = 0x0F
	TypeInt32            Type = 0x10
	TypeTimestamp        Type = 0x11
	TypeInt64            Type = 0x12
	TypeDecimal128       Type = 0x13
	TypeMinKey           Type = 0xFF
	TypeMaxKey           Type = 0x7F
)

These constants uniquely refer to each BSON type.

func ReadHeader

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

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

func ReadType

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

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

func (Type) String

func (bt Type) String() string

String returns the string representation of the BSON type's name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL