bson

package
v0.0.0-...-bb56650 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package bson provides converters from/to BSON for built-in and `types` types.

See contributing guidelines and documentation for package `types` for details.

Mapping

Composite types

Alias      types package    bson package

object     *types.Document  *bson.Document
array      *types.Array     *bson.arrayType

Scalar types

Alias      types package    bson package

double     float64          *bson.doubleType
string     string           *bson.stringType
binData    types.Binary     *bson.binaryType
objectId   types.ObjectID   *bson.objectIDType
bool       bool             *bson.boolType
date       time.Time        *bson.dateTimeType
null       types.NullType   *bson.nullType
regex      types.Regex      *bson.regexType
int        int32            *bson.int32Type
timestamp  types.Timestamp  *bson.timestampType
long       int64            *bson.int64Type

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CString

type CString string

CString represents BSON zero-terminated UTF-8 string type.

It is not a "real" BSON data type but used by some of them and also by the wire protocol.

func (CString) MarshalBinary

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

MarshalBinary implements bsontype interface.

func (*CString) ReadFrom

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

ReadFrom implements bsontype interface.

func (CString) WriteTo

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

WriteTo implements bsontype interface.

type Document

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

Document represents BSON Document 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.

Remove it. TODO https://github.com/FerretDB/FerretDB/issues/260

func (*Document) Keys

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

Keys returns a copy of document's keys.

If there are duplicate keys in the document, the result will have duplicate keys too.

If document or document's fields are not set (nil), it returns nil.

func (Document) MarshalBinary

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

MarshalBinary implements bsontype interface.

func (*Document) ReadFrom

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

ReadFrom implements bsontype interface.

func (*Document) Values

func (doc *Document) Values() []any

Values returns a copy of document's values in the same order as Keys().

If document or document's fields are not set (nil), it returns nil.

func (Document) WriteTo

func (doc Document) 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