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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
ErrTooShort = errors.New("bson document too short")
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.
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.
Decoder struct {
// contains filtered or unexported fields
A Decoder reads and decodes BSON objects from an input stream.
NewDecoder(r io.Reader) *Decoder
NewDecoder returns a new decoder that reads from r.
(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.
Encoder struct {
// contains filtered or unexported fields
An Encoder writes BSON objects to an output stream.
NewEncoder(w io.Writer) *Encoder
NewEncoder returns a new encoder that writes to w.
(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.
InvalidBSONTypeError struct {
Type byte
An InvalidBSONTypeError describes an unhandled BSON document element type.
(e *InvalidBSONTypeError) Error() string
InvalidUnmarshalError struct {
Type reflect.Type
An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)
(e *InvalidUnmarshalError) Error() string
MarshalerError struct {
Type reflect.Type
Err error
(e *MarshalerError) Error() string
UnsupportedTypeError struct {
Type reflect.Type
An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.
(e *UnsupportedTypeError) Error() string
Generated by godoc2md