pkg/bson

Name: bson

Owner: pkg

Description: Package bson implements encoding and decoding of BSON objects defined at http://bsonspec.org/spec.html.

Created: 2014-06-18 11:14:54.0

Updated: 2017-12-19 21:44:54.0

Pushed: 2016-11-21 04:38:23.0

Homepage: null

Size: 3688

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

bson

import "github.com/pkg/bson"

Package bson implements encoding and decoding of BSON objects as defined at http://bsonspec.org/spec.html. The mapping between BSON objects and Go values is described in the documentation for the Marshal and Unmarshal functions.

Variables
ErrTooShort = errors.New("bson document too short")
func Marshal
 Marshal(v interface{}) ([]byte, error)

Marshal returns the BSON encoding of v.

Struct values encode as JSON objects. Each exported struct field becomes a member of the object unless

- the field's tag is "-", or
- the field is empty and its tag specifies the "omitempty" option.

Map values encode as JSON objects. The map's key type must be string; the object keys are used directly as map keys.

func Unmarshal
 Unmarshal(data []byte, v interface{}) error

Unmarshal parses the BSON-encoded data and stores the result in the value pointed to by v.

Unmarshal uses the inverse of the encodings that Marshal uses, allocating maps, slices, and pointers as necessary.

Portions of data may be retained by the decoded result in v. Data should not be reused.

type Decoder
 Decoder struct {
// contains filtered or unexported fields

A Decoder reads and decodes BSON objects from an input stream.

func NewDecoder
 NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode
 (d *Decoder) Decode(v interface{}) error

Decode reads the next BSON-encoded value from its input and stores it in the value pointed to by v.

See the documentation for Unmarshal for details about the conversion of BSON into a Go value.

type Encoder
 Encoder struct {
// contains filtered or unexported fields

An Encoder writes BSON objects to an output stream.

func NewEncoder
 NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode
 (e *Encoder) Encode(v interface{}) error

Encode writes the BSON encoding of v to the stream, followed by a newline character.

See the documentation for Marshal for details about the conversion of Go values to BSON.

type InvalidBSONTypeError
 InvalidBSONTypeError struct {
Type byte

An InvalidBSONTypeError describes an unhandled BSON document element type.

func (*InvalidBSONTypeError) Error
 (e *InvalidBSONTypeError) Error() string
type InvalidUnmarshalError
 InvalidUnmarshalError struct {
Type reflect.Type

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error
 (e *InvalidUnmarshalError) Error() string
type MarshalerError
 MarshalerError struct {
Type reflect.Type
Err  error

func (*MarshalerError) Error
 (e *MarshalerError) Error() string
type UnsupportedTypeError
 UnsupportedTypeError struct {
Type reflect.Type

An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.

func (*UnsupportedTypeError) Error
 (e *UnsupportedTypeError) Error() string

Generated by godoc2md


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.