Documentation ¶
Overview ¶
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 ¶
- func AppendArray(dst []byte, arr []byte) []byte
- func AppendArrayElement(dst []byte, key string, arr []byte) []byte
- func AppendArrayElementStart(dst []byte, key string) (index int32, b []byte)
- func AppendArrayEnd(dst []byte, index int32) ([]byte, error)
- func AppendArrayStart(dst []byte) (index int32, b []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 AppendDocumentElementStart(dst []byte, key string) (index int32, b []byte)
- func AppendDocumentEnd(dst []byte, index int32) ([]byte, error)
- func AppendDocumentStart(dst []byte) (index int32, b []byte)
- func AppendDocumentStartInline(dst []byte, index *int32) []byte
- func AppendDouble(dst []byte, f float64) []byte
- func AppendDoubleElement(dst []byte, key string, f float64) []byte
- func AppendHeader(dst []byte, t bsontype.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 bsontype.Type) []byte
- func AppendUndefinedElement(dst []byte, key string) []byte
- func EqualValue(t1, t2 bsontype.Type, v1, v2 []byte) bool
- func ReadArray(src []byte) (arr []byte, rem []byte, ok bool)
- func ReadBinary(src []byte) (subtype byte, bin []byte, rem []byte, ok bool)
- func ReadBoolean(src []byte) (bool, []byte, bool)
- func ReadCodeWithScope(src []byte) (code string, scope []byte, rem []byte, ok bool)
- func ReadDBPointer(src []byte) (ns string, oid objectid.ObjectID, rem []byte, ok bool)
- func ReadDateTime(src []byte) (int64, []byte, bool)
- func ReadDecimal128(src []byte) (decimal.Decimal128, []byte, bool)
- func ReadDocument(src []byte) (doc []byte, rem []byte, ok bool)
- func ReadDouble(src []byte) (float64, []byte, bool)
- func ReadHeader(src []byte) (t bsontype.Type, key string, rem []byte, ok bool)
- func ReadInt32(src []byte) (int32, []byte, bool)
- func ReadInt64(src []byte) (int64, []byte, bool)
- func ReadJavaScript(src []byte) (js string, rem []byte, ok bool)
- func ReadKey(src []byte) (string, []byte, bool)
- func ReadLength(src []byte) (int32, []byte, bool)
- func ReadObjectID(src []byte) (objectid.ObjectID, []byte, bool)
- func ReadRegex(src []byte) (pattern, options string, rem []byte, ok bool)
- func ReadString(src []byte) (string, []byte, bool)
- func ReadSymbol(src []byte) (symbol string, rem []byte, ok bool)
- func ReadTimestamp(src []byte) (t, i uint32, rem []byte, ok bool)
- func ReadType(src []byte) (bsontype.Type, []byte, bool)
- func ReserveLength(dst []byte) (int32, []byte)
- func UpdateLength(dst []byte, index, length int32) []byte
- type Document
- type Element
- type Value
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 AppendArrayElementStart ¶
AppendArrayElementStart appends an array element header and then the length bytes for an array, returning the index where the length starts.
func AppendArrayEnd ¶
AppendArrayEnd appends the null byte to an array and calculates the length, inserting that calculated length starting at index.
func AppendArrayStart ¶
AppendArrayStart appends the length bytes to an array and then returns the index of the start of those length bytes.
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 AppendDocumentElementStart ¶
AppendDocumentElementStart writes a document element header and then reserves the length bytes.
func AppendDocumentEnd ¶
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 ¶
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 ¶
AppendDocumentStartInline functions the same as AppendDocumentStart but takes a pointer to the index int32 which allows this function to be used inline.
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 ¶
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, []byte, 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 ReadHeader ¶
ReadHeader will return the type byte and the key in src. If both of these values cannot be read, false is returned.
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 ReadLength ¶
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 ¶
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.
func ReadType ¶
ReadType will return the first byte of the provided []byte as a type. If there is no availble byte, false is returned.
func ReserveLength ¶
ReserveLength reserves the space required for length and returns the index where to write the length and the []byte with reserved space.
func UpdateLength ¶
UpdateLength updates the length at index with length and returns the []byte.