Code Monkey home page Code Monkey logo

bson's Introduction

bson

import "github.com/pkg/bson"

Package bson implements encoding and decoding of BSON objects as defined at a href="http://bsonspec.org/spec.html">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

var ErrTooShort = errors.New("bson document too short")

func Marshal

func 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

func 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

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

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

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode

func (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

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

An Encoder writes BSON objects to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (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

type InvalidBSONTypeError struct {
    Type byte
}

An InvalidBSONTypeError describes an unhandled BSON document element type.

func (*InvalidBSONTypeError) Error

func (e *InvalidBSONTypeError) Error() string

type InvalidUnmarshalError

type 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

func (e *InvalidUnmarshalError) Error() string

type MarshalerError

type MarshalerError struct {
    Type reflect.Type
    Err  error
}

func (*MarshalerError) Error

func (e *MarshalerError) Error() string

type UnsupportedTypeError

type UnsupportedTypeError struct {
    Type reflect.Type
}

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

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

Generated by godoc2md

bson's People

Contributors

davecheney avatar

Watchers

 avatar

Forkers

alash3al bewt85

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.