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 ¶
- func AppendArray(dst []byte, arr []byte) []byte
- func AppendArrayElement(dst []byte, key string, arr []byte) []byte
- func AppendBinary(dst []byte, subtype byte, b []byte) []byte
- func AppendBinaryElement(dst []byte, key string, subtype byte, b []byte) []byte
- func AppendBoolean(dst []byte, b bool) []byte
- func AppendBooleanElement(dst []byte, key string, b bool) []byte
- func AppendCodeWithScope(dst []byte, code string, scope []byte) []byte
- func AppendCodeWithScopeElement(dst []byte, key, code string, scope []byte) []byte
- func AppendDBPointer(dst []byte, ns string, oid objectid.ObjectID) []byte
- func AppendDBPointerElement(dst []byte, key, ns string, oid objectid.ObjectID) []byte
- func AppendDateTime(dst []byte, dt int64) []byte
- func AppendDateTimeElement(dst []byte, key string, dt int64) []byte
- func AppendDecimal128(dst []byte, d128 decimal.Decimal128) []byte
- func AppendDecimal128Element(dst []byte, key string, d128 decimal.Decimal128) []byte
- func AppendDocument(dst []byte, doc []byte) []byte
- func AppendDocumentElement(dst []byte, key string, doc []byte) []byte
- func AppendDouble(dst []byte, f float64) []byte
- func AppendDoubleElement(dst []byte, key string, f float64) []byte
- func AppendHeader(dst []byte, t Type, key string) []byte
- func AppendInt32(dst []byte, i32 int32) []byte
- func AppendInt32Element(dst []byte, key string, i32 int32) []byte
- func AppendInt64(dst []byte, i64 int64) []byte
- func AppendInt64Element(dst []byte, key string, i64 int64) []byte
- func AppendJavaScript(dst []byte, js string) []byte
- func AppendJavaScriptElement(dst []byte, key, js string) []byte
- func AppendKey(dst []byte, key string) []byte
- func AppendMaxKeyElement(dst []byte, key string) []byte
- func AppendMinKeyElement(dst []byte, key string) []byte
- func AppendNullElement(dst []byte, key string) []byte
- func AppendObjectID(dst []byte, oid objectid.ObjectID) []byte
- func AppendObjectIDElement(dst []byte, key string, oid objectid.ObjectID) []byte
- func AppendRegex(dst []byte, pattern, options string) []byte
- func AppendRegexElement(dst []byte, key, pattern, options string) []byte
- func AppendString(dst []byte, s string) []byte
- func AppendStringElement(dst []byte, key, val string) []byte
- func AppendSymbol(dst []byte, symbol string) []byte
- func AppendSymbolElement(dst []byte, key, symbol string) []byte
- func AppendTimestamp(dst []byte, t, i uint32) []byte
- func AppendTimestampElement(dst []byte, key string, t, i uint32) []byte
- func AppendType(dst []byte, t Type) []byte
- func AppendUndefinedElement(dst []byte, key string) []byte
- func EqualValue(t1, t2 Type, v1, v2 []byte) bool
- func ReadArray(src []byte) ([]byte, bool)
- func ReadBinary(src []byte) (subtype byte, bin []byte, ok bool)
- func ReadBoolean(src []byte) (bool, bool)
- func ReadCodeWithScope(src []byte) (code string, scope []byte, ok bool)
- func ReadDBPointer(src []byte) (ns string, oid objectid.ObjectID, ok bool)
- func ReadDateTime(src []byte) (int64, bool)
- func ReadDecimal128(src []byte) (decimal.Decimal128, bool)
- func ReadDocument(src []byte) ([]byte, bool)
- func ReadDouble(src []byte) (float64, bool)
- func ReadInt32(src []byte) (int32, bool)
- func ReadInt64(src []byte) (int64, bool)
- func ReadJavaScript(src []byte) (js string, ok bool)
- func ReadKey(src []byte) (string, bool)
- func ReadObjectID(src []byte) (objectid.ObjectID, bool)
- func ReadRegex(src []byte) (pattern, options string, ok bool)
- func ReadString(src []byte) (string, bool)
- func ReadSymbol(src []byte) (symbol string, ok bool)
- func ReadTimestamp(src []byte) (t, i uint32, ok bool)
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendArray ¶
AppendArray will append arr to dst and return the extended buffer.
func AppendArrayElement ¶
AppendArrayElement will append a BSON array element using key and arr to dst and return the extended buffer.
func AppendBinary ¶
AppendBinary will append subtype and b to dst and return the extended buffer.
func AppendBinaryElement ¶
AppendBinaryElement will append a BSON binary element using key, subtype, and b to dst and return the extended buffer.
func AppendBoolean ¶
AppendBoolean will append b to dst and return the extended buffer.
func AppendBooleanElement ¶
AppendBooleanElement will append a BSON boolean element using key and b to dst and return the extended buffer.
func AppendCodeWithScope ¶
AppendCodeWithScope will append code and scope to dst and return the extended buffer.
func AppendCodeWithScopeElement ¶
AppendCodeWithScopeElement will append a BSON code with scope element using key, code, and scope to dst and return the extended buffer.
func AppendDBPointer ¶
AppendDBPointer will append ns and oid to dst and return the extended buffer.
func AppendDBPointerElement ¶
AppendDBPointerElement will append a BSON DBPointer element using key, ns, and oid to dst and return the extended buffer.
func AppendDateTime ¶
AppendDateTime will append dt to dst and return the extended buffer.
func AppendDateTimeElement ¶
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 ¶
AppendDocument will append doc to dst and return the extended buffer.
func AppendDocumentElement ¶
AppendDocumentElement will append a BSON embeded document element using key and doc to dst and return the extended buffer.
func AppendDouble ¶
AppendDouble will append f to dst and return the extended buffer.
func AppendDoubleElement ¶
AppendDoubleElement will append a BSON double element using key and f to dst and return the extended buffer.
func AppendHeader ¶
AppendHeader will append Type t and key to dst and return the extended buffer.
func AppendInt32 ¶
AppendInt32 will append i32 to dst and return the extended buffer.
func AppendInt32Element ¶
AppendInt32Element will append a BSON int32 element using key and i32 to dst and return the extended buffer.
func AppendInt64 ¶
AppendInt64 will append i64 to dst and return the extended buffer.
func AppendInt64Element ¶
AppendInt64Element will append a BSON int64 element using key and i64 to dst and return the extended buffer.
func AppendJavaScript ¶
AppendJavaScript will append js to dst and return the extended buffer.
func AppendJavaScriptElement ¶
AppendJavaScriptElement will append a BSON JavaScript element using key and js to dst and return the extended buffer.
func AppendMaxKeyElement ¶
AppendMaxKeyElement will append a BSON max key element using key to dst and return the extended buffer.
func AppendMinKeyElement ¶
AppendMinKeyElement will append a BSON min key element using key to dst and return the extended buffer.
func AppendNullElement ¶
AppendNullElement will append a BSON null element using key to dst and return the extended buffer.
func AppendObjectID ¶
AppendObjectID will append oid to dst and return the extended buffer.
func AppendObjectIDElement ¶
AppendObjectIDElement will append a BSON ObjectID element using key and oid to dst and return the extended buffer.
func AppendRegex ¶
AppendRegex will append pattern and options to dst and return the extended buffer.
func AppendRegexElement ¶
AppendRegexElement will append a BSON regex element using key, pattern, and options to dst and return the extended buffer.
func AppendString ¶
AppendString will append s to dst and return the extended buffer.
func AppendStringElement ¶
AppendStringElement will append a BSON string element using key and val to dst and return the extended buffer.
func AppendSymbol ¶
AppendSymbol will append symbol to dst and return the extended buffer.
func AppendSymbolElement ¶
AppendSymbolElement will append a BSON symbol element using key and symbol to dst and return the extended buffer.
func AppendTimestamp ¶
AppendTimestamp will append t and i to dst and return the extended buffer.
func AppendTimestampElement ¶
AppendTimestampElement will append a BSON timestamp element using key, t, and i to dst and return the extended buffer.
func AppendType ¶
AppendType will append t to dst and return the extended buffer.
func AppendUndefinedElement ¶
AppendUndefinedElement will append a BSON undefined element using key to dst and return the extended buffer.
func EqualValue ¶ added in v0.0.15
EqualValue will return true if the two values are equal.
func ReadArray ¶
ReadArray will read an array from src. If there are not enough bytes it will return false.
func ReadBinary ¶
ReadBinary will read a subtype and bin from src. If there are not enough bytes it will return false.
func ReadBoolean ¶
ReadBoolean will read a bool from src. If there are not enough bytes it will return false.
func ReadCodeWithScope ¶
ReadCodeWithScope will read code and scope from src. If there are not enough bytes it will return false.
func ReadDBPointer ¶
ReadDBPointer will read a ns and oid from src. If there are not enough bytes it will return false.
func ReadDateTime ¶
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 ¶
ReadDocument will read a document from src. If there are not enough bytes it will return false.
func ReadDouble ¶
ReadDouble will read a float64 from src. If there are not enough bytes it will return false.
func ReadInt32 ¶
ReadInt32 will read an int32 from src. If there are not enough bytes it will return false.
func ReadInt64 ¶
ReadInt64 will read an int64 from src. If there are not enough bytes it will return false.
func ReadJavaScript ¶
ReadJavaScript will read a js string from src. If there are not enough bytes it will return false.
func ReadKey ¶
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 ¶
ReadObjectID will read an ObjectID from src. If there are not enough bytes it will return false.
func ReadRegex ¶
ReadRegex will read a pattern and options from src. If there are not enough bytes it will return false.
func ReadString ¶
ReadString will read a string from src. If there are not enough bytes it will return false.
func ReadSymbol ¶
ReadSymbol will read a symbol string from src. If there are not enough bytes it will return false.
func ReadTimestamp ¶
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 ¶
ReadHeader will return the type byte and the key in src. If both of these values cannot be read, false is returned.