elements

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package elements holds the logic to encode and decode the BSON element types from native Go to BSON binary and vice versa.

These are low level helper methods, so they do not encode or decode BSON elements, only the specific types, e.g. these methods do not encode, decode, or identify a BSON element, so they won't read the identifier byte and they won't parse out the key string. There are encoder and decoder helper methods for the CString BSON element type, so this package can be used to parse keys.

Index

Constants

This section is empty.

Variables

View Source
var (
	Double        DoubleNS
	String        StringNS
	Document      DocumentNS
	Array         ArrayNS
	Binary        BinNS
	ObjectID      ObjectIDNS
	Boolean       BooleanNS
	DateTime      DatetimeNS
	Regex         RegexNS
	DBPointer     DBPointerNS
	JavaScript    JavaScriptNS
	Symbol        SymbolNS
	CodeWithScope CodeWithScopeNS
	Int32         Int32NS
	Timestamp     TimestampNS
	Int64         Int64NS
	Decimal128    Decimal128NS
	CString       CStringNS
	Byte          BSONByteNS
)

These variables are used as namespaces for methods pertaining to encoding individual BSON types.

View Source
var ErrTooSmall = errors.New("element: The provided slice is too small")

ErrTooSmall indicates that slice provided to encode into is not large enough to fit the data.

Functions

This section is empty.

Types

type ArrayNS

type ArrayNS struct{}

ArrayNS is a namespace for encoding BSON Array elements.

func (ArrayNS) Element

func (ArrayNS) Element(start uint, writer []byte, key string, arr []byte) (int, error)

Element encodes an array and a key into a BSON array element and serializes the bytes to the provided writer.

func (ArrayNS) Encode

func (ArrayNS) Encode(start uint, writer []byte, arr []byte) (int, error)

Encode encodes an array into a BSON array element and serializes the bytes to the provided writer.

type BSONByteNS

type BSONByteNS struct{}

BSONByteNS is a namespace for encoding a single byte.

func (BSONByteNS) Encode

func (BSONByteNS) Encode(start uint, writer []byte, t byte) (int, error)

Encode encodes a C-style string into a BSON CString element and serializes the bytes to the provided writer.

type BinNS

type BinNS struct{}

BinNS is a namespace for encoding BSON Binary elements.

func (BinNS) Element

func (BinNS) Element(start uint, writer []byte, key string, b []byte, btype byte) (int, error)

Element encodes a []byte and a key into a BSON binary element and serializes the bytes to the provided writer.

func (BinNS) Encode

func (BinNS) Encode(start uint, writer []byte, b []byte, btype byte) (int, error)

Encode encodes a []byte into a BSON binary element and serializes the bytes to the provided writer.

type BooleanNS

type BooleanNS struct{}

BooleanNS is a namespace for encoding BSON Boolean elements.

func (BooleanNS) Element

func (BooleanNS) Element(start uint, writer []byte, key string, b bool) (int, error)

Element encodes a boolean and a key into a BSON boolean element and serializes the bytes to the provided writer.

func (BooleanNS) Encode

func (BooleanNS) Encode(start uint, writer []byte, b bool) (int, error)

Encode encodes a boolean into a BSON boolean element and serializes the bytes to the provided writer.

type CStringNS

type CStringNS struct{}

CStringNS is a namespace for encoding BSON CString elements.

func (CStringNS) Encode

func (CStringNS) Encode(start uint, writer []byte, str string) (int, error)

Encode encodes a C-style string into a BSON CString element and serializes the bytes to the provided writer.

type CodeWithScopeNS

type CodeWithScopeNS struct{}

CodeWithScopeNS is a namespace for encoding BSON CodeWithScope elements.

func (CodeWithScopeNS) Element

func (CodeWithScopeNS) Element(start uint, writer []byte, key string, code string, scope []byte) (int, error)

Element encodes a code and scope doc and a key into a BSON CodeWithScope element and serializes the bytes to the provided writer.

func (CodeWithScopeNS) Encode

func (CodeWithScopeNS) Encode(start uint, writer []byte, code string, doc []byte) (int, error)

Encode encodes a code and scope doc into a BSON CodeWithScope element and serializes the bytes to the provided writer.

type DBPointerNS

type DBPointerNS struct{}

DBPointerNS is a namespace for encoding BSON DBPointer elements.

func (DBPointerNS) Element

func (DBPointerNS) Element(start uint, writer []byte, key string, ns string, oid [12]byte) (int, error)

Element encodes a DBPointer and a key into a BSON DBPointer element and serializes the bytes to the provided writer.

func (DBPointerNS) Encode

func (DBPointerNS) Encode(start uint, writer []byte, ns string, oid [12]byte) (int, error)

Encode encodes a DBPointer into a BSON DBPointer element and serializes the bytes to the provided writer.

type DatetimeNS

type DatetimeNS struct{}

DatetimeNS is a namespace for encoding BSON Datetime elements.

func (DatetimeNS) Element

func (DatetimeNS) Element(start uint, writer []byte, key string, dt int64) (int, error)

Element encodes a Datetime and a key into a BSON Datetime element and serializes the bytes to the provided writer.

func (DatetimeNS) Encode

func (DatetimeNS) Encode(start uint, writer []byte, dt int64) (int, error)

Encode encodes a Datetime into a BSON Datetime element and serializes the bytes to the provided writer.

type Decimal128NS

type Decimal128NS struct{}

Decimal128NS is a namespace for encoding BSON Decimal128 elements.

func (Decimal128NS) Element

func (Decimal128NS) Element(start uint, writer []byte, key string, d types.Decimal128) (int, error)

Element encodes a decimal128 and a key into a BSON decimal128 element and serializes the bytes to the provided writer.

func (Decimal128NS) Encode

func (Decimal128NS) Encode(start uint, writer []byte, d types.Decimal128) (int, error)

Encode encodes a decimal128 into a BSON decimal128 element and serializes the bytes to the provided writer.

type DocumentNS

type DocumentNS struct{}

DocumentNS is a namespace for encoding BSON Document elements.

func (DocumentNS) Element

func (DocumentNS) Element(start uint, writer []byte, key string, doc []byte) (int, error)

Element encodes a Document and a key into a BSON document element and serializes the bytes to the provided writer.

func (DocumentNS) Encode

func (DocumentNS) Encode(start uint, writer []byte, doc []byte) (int, error)

Encode encodes a Document into a BSON document element and serializes the bytes to the provided writer.

type DoubleNS

type DoubleNS struct{}

DoubleNS is a namespace for encoding BSON Double elements.

func (DoubleNS) Element

func (DoubleNS) Element(start uint, writer []byte, key string, f float64) (int, error)

Element encodes a float64 and a key into a BSON double element and serializes the bytes to the provided writer.

func (DoubleNS) Encode

func (DoubleNS) Encode(start uint, writer []byte, f float64) (int, error)

Encode encodes a float64 into a BSON double element and serializes the bytes to the provided writer.

type Int32NS

type Int32NS struct{}

Int32NS is a namespace for encoding BSON Int32 elements.

func (Int32NS) Element

func (Int32NS) Element(start uint, writer []byte, key string, i int32) (int, error)

Element encodes an int32 and a key into a BSON int32 element and serializes the bytes to the provided writer.

func (Int32NS) Encode

func (Int32NS) Encode(start uint, writer []byte, i int32) (int, error)

Encode encodes an int32 into a BSON int32 element and serializes the bytes to the provided writer.

type Int64NS

type Int64NS struct{}

Int64NS is a namespace for encoding BSON Int64 elements.

func (Int64NS) Element

func (Int64NS) Element(start uint, writer []byte, key string, i int64) (int, error)

Element encodes a int64 and a key into a BSON int64 element and serializes the bytes to the provided writer.

func (Int64NS) Encode

func (Int64NS) Encode(start uint, writer []byte, i int64) (int, error)

Encode encodes a int64 into a BSON int64 element and serializes the bytes to the provided writer.

type JavaScriptNS

type JavaScriptNS struct{}

JavaScriptNS is a namespace for encoding BSON JavaScript elements.

func (JavaScriptNS) Element

func (JavaScriptNS) Element(start uint, writer []byte, key string, code string) (int, error)

Element encodes a JavaScript string and a key into a BSON JavaScript element and serializes the bytes to the provided writer.

func (JavaScriptNS) Encode

func (JavaScriptNS) Encode(start uint, writer []byte, code string) (int, error)

Encode encodes a JavaScript string into a BSON JavaScript element and serializes the bytes to the provided writer.

type ObjectIDNS

type ObjectIDNS struct{}

ObjectIDNS is a namespace for encoding BSON ObjectID elements.

func (ObjectIDNS) Element

func (ObjectIDNS) Element(start uint, writer []byte, key string, oid [12]byte) (int, error)

Element encodes a ObjectID and a key into a BSON ObjectID element and serializes the bytes to the provided writer.

func (ObjectIDNS) Encode

func (ObjectIDNS) Encode(start uint, writer []byte, oid [12]byte) (int, error)

Encode encodes an ObjectID into a BSON ObjectID element and serializes the bytes to the provided writer.

type RegexNS

type RegexNS struct{}

RegexNS is a namespace for encoding BSON Regex elements.

func (RegexNS) Element

func (RegexNS) Element(start uint, writer []byte, key string, pattern, options string) (int, error)

Element encodes a regex and a key into a BSON regex element and serializes the bytes to the provided writer.

func (RegexNS) Encode

func (RegexNS) Encode(start uint, writer []byte, pattern, options string) (int, error)

Encode encodes a regex into a BSON regex element and serializes the bytes to the provided writer.

type StringNS

type StringNS struct{}

StringNS is a namespace for encoding BSON String elements.

func (StringNS) Element

func (StringNS) Element(start uint, writer []byte, key string, s string) (int, error)

Element encodes a string and a key into a BSON string element and serializes the bytes to the provided writer.

func (StringNS) Encode

func (StringNS) Encode(start uint, writer []byte, s string) (int, error)

Encode encodes a string into a BSON string element and serializes the bytes to the provided writer.

type SymbolNS

type SymbolNS struct{}

SymbolNS is a namespace for encoding BSON Symbol elements.

func (SymbolNS) Element

func (SymbolNS) Element(start uint, writer []byte, key string, symbol string) (int, error)

Element encodes a symbol and a key into a BSON symbol element and serializes the bytes to the provided writer.

func (SymbolNS) Encode

func (SymbolNS) Encode(start uint, writer []byte, symbol string) (int, error)

Encode encodes a symbol into a BSON symbol element and serializes the bytes to the provided writer.

type TimestampNS

type TimestampNS struct{}

TimestampNS is a namespace for encoding Timestamp Double elements.

func (TimestampNS) Element

func (TimestampNS) Element(start uint, writer []byte, key string, t uint32, i uint32) (int, error)

Element encodes a timestamp and a key into a BSON timestamp element and serializes the bytes to the provided writer.

func (TimestampNS) Encode

func (TimestampNS) Encode(start uint, writer []byte, t uint32, i uint32) (int, error)

Encode encodes a timestamp into a BSON timestamp element and serializes the bytes to the provided writer.

Jump to

Keyboard shortcuts

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