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