bson

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package bson provides converters from/to BSON.

JSON mapping for storage

Double:    {"$f": JSON number} or {"$f": "Infinity|-Infinity|NaN"}
String:    JSON string
Document:  {"$k": ["<key 1>", "<key 2>", ...], "<key 1>": <value 1>, "<key 2>": <value 2>, ...}
Array:     JSON array
Binary:    {"$b": "<base 64 string>", "s": <subtype number>}
ObjectID:  {"$o": "<ObjectID as 24 character hex string"}
Bool:      JSON true / false values
DateTime:  {"$d": "milliseconds since epoch as string"}
Regex:     {"$r": "<string without terminating 0x0>", "o": "<string without terminating 0x0>"}
Int32:     JSON number
Timestamp: {"$t": "<number as string>"}
Int64:     {"$l": "<number as string>"}
CString:   {"$c": "<string without terminating 0x0>"}

Index

Constants

View Source
const (
	MaxDocumentLen = 16777216
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array []interface{}

Array represents BSON Array data type.

func (Array) MarshalBinary

func (arr Array) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Array) MarshalJSON

func (arr Array) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Array) ReadFrom

func (arr *Array) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Array) UnmarshalJSON

func (arr *Array) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Array) WriteTo

func (arr Array) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type Binary

type Binary struct {
	Subtype types.BinarySubtype
	B       []byte
}

Binary represents BSON Binary data type.

func (Binary) MarshalBinary

func (bin Binary) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Binary) MarshalJSON

func (bin Binary) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Binary) ReadFrom

func (bin *Binary) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Binary) UnmarshalJSON

func (bin *Binary) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Binary) WriteTo

func (bin Binary) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type Bool

type Bool bool

Bool represents BSON Bool data type.

func (Bool) MarshalBinary

func (b Bool) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Bool) ReadFrom

func (b *Bool) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Bool) WriteTo

func (b Bool) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type CString

type CString string

CString represents BSON CString data type.

func (CString) MarshalBinary

func (cstr CString) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (CString) MarshalJSON

func (cstr CString) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*CString) ReadFrom

func (cstr *CString) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*CString) UnmarshalJSON

func (cstr *CString) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (CString) WriteTo

func (cstr CString) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type DateTime

type DateTime time.Time

DateTime represents BSON DateTime data type.

func (DateTime) MarshalBinary

func (dt DateTime) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (DateTime) MarshalJSON

func (dt DateTime) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*DateTime) ReadFrom

func (dt *DateTime) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (DateTime) String

func (dt DateTime) String() string

func (*DateTime) UnmarshalJSON

func (dt *DateTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (DateTime) WriteTo

func (dt DateTime) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document represents BSON Document data type.

func ConvertDocument

func ConvertDocument(d document) (*Document, error)

ConvertDocument converts types.Document to bson.Document and validates it. It references the same data without copying it.

func MustConvertDocument

func MustConvertDocument(d document) *Document

MustConvertDocument is a ConvertDocument that panics in case of error.

func (*Document) Keys

func (doc *Document) Keys() []string

Keys returns the keys associated with the document.

func (*Document) Map

func (doc *Document) Map() map[string]interface{}

Returns the map of key values associated with the Document.

func (Document) MarshalBinary

func (doc Document) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Document) MarshalJSON

func (doc Document) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Document) ReadFrom

func (doc *Document) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Document) UnmarshalJSON

func (doc *Document) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Document) WriteTo

func (doc Document) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type Double

type Double float64

Double represents BSON Double data type.

func (Double) MarshalBinary

func (d Double) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Double) MarshalJSON

func (d Double) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Double) ReadFrom

func (d *Double) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Double) UnmarshalJSON

func (d *Double) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Double) WriteTo

func (d Double) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type Int32

type Int32 int32

Int32 represents BSON Int32 data type.

func (Int32) MarshalBinary

func (i Int32) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Int32) MarshalJSON

func (i Int32) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Int32) ReadFrom

func (i *Int32) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Int32) UnmarshalJSON

func (i *Int32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Int32) WriteTo

func (i Int32) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type Int64

type Int64 int64

Int64 represents BSON Int64 data type.

func (Int64) MarshalBinary

func (i Int64) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Int64) MarshalJSON

func (i Int64) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Int64) ReadFrom

func (i *Int64) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Int64) UnmarshalJSON

func (i *Int64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Int64) WriteTo

func (i Int64) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type ObjectID

type ObjectID [12]byte

ObjectID represents BSON ObjectID data type.

func (ObjectID) MarshalBinary

func (obj ObjectID) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (ObjectID) MarshalJSON

func (obj ObjectID) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*ObjectID) ReadFrom

func (obj *ObjectID) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*ObjectID) UnmarshalJSON

func (obj *ObjectID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (ObjectID) WriteTo

func (obj ObjectID) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type Regex

type Regex struct {
	Pattern string
	Options string
}

Regex represents BSON Regex data type.

func (Regex) MarshalBinary

func (regex Regex) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Regex) MarshalJSON

func (regex Regex) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Regex) ReadFrom

func (regex *Regex) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Regex) UnmarshalJSON

func (regex *Regex) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Regex) WriteTo

func (regex Regex) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type String

type String string

String represents BSON String data type.

func (String) MarshalBinary

func (str String) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (String) MarshalJSON

func (str String) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*String) ReadFrom

func (str *String) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*String) UnmarshalJSON

func (str *String) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (String) WriteTo

func (str String) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

type Timestamp

type Timestamp uint64

Timestamp represents BSON Timestamp data type.

func (Timestamp) MarshalBinary

func (ts Timestamp) MarshalBinary() ([]byte, error)

MarshalBinary implements bsontype interface.

func (Timestamp) MarshalJSON

func (ts Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements bsontype interface.

func (*Timestamp) ReadFrom

func (ts *Timestamp) ReadFrom(r *bufio.Reader) error

ReadFrom implements bsontype interface.

func (*Timestamp) UnmarshalJSON

func (ts *Timestamp) UnmarshalJSON(data []byte) error

UnmarshalJSON implements bsontype interface.

func (Timestamp) WriteTo

func (ts Timestamp) WriteTo(w *bufio.Writer) error

WriteTo implements bsontype interface.

Jump to

Keyboard shortcuts

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