bson

package
v0.0.0-...-11aee85 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2014 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EOO = iota
	Number
	String
	Object
	Array
	Binary
	Undefined // deprecated
	OID       // unsupported
	Boolean
	Datetime
	Null
	Regex         // unsupported
	Ref           // deprecated
	Code          // unsupported
	Symbol        // unsupported
	CodeWithScope // unsupported
	Int
	Timestamp // unsupported
	Long
	Ulong  = 0x3F // nonstandard extension
	MinKey = 0xFF // unsupported
	MaxKey = 0x7F // unsupported
)
View Source
const DefaultBufferSize = 1024 * 16

Variables

View Source
var (
	TimeType  = reflect.TypeOf(time.Time{})
	BytesType = reflect.TypeOf([]byte(nil))
)

BSON documents are lttle endian

Functions

func DecodeBool

func DecodeBool(buf *bytes.Buffer, kind byte) bool

func DecodeBytes

func DecodeBytes(buf *bytes.Buffer, kind byte) []byte

func DecodeFloat64

func DecodeFloat64(buf *bytes.Buffer, kind byte) float64

func DecodeInt

func DecodeInt(buf *bytes.Buffer, kind byte) int

func DecodeInt32

func DecodeInt32(buf *bytes.Buffer, kind byte) int32

func DecodeInt64

func DecodeInt64(buf *bytes.Buffer, kind byte) int64

func DecodeString

func DecodeString(buf *bytes.Buffer, kind byte) string

func DecodeStringArray

func DecodeStringArray(buf *bytes.Buffer, kind byte) []string

func DecodeTime

func DecodeTime(buf *bytes.Buffer, kind byte) time.Time

func DecodeUint64

func DecodeUint64(buf *bytes.Buffer, kind byte) uint64

func EncodeBinary

func EncodeBinary(buf *bytes2.ChunkedWriter, key string, val []byte)

func EncodeBool

func EncodeBool(buf *bytes2.ChunkedWriter, key string, val bool)

func EncodeField

func EncodeField(buf *bytes2.ChunkedWriter, key string, val interface{})

func EncodeFloat64

func EncodeFloat64(buf *bytes2.ChunkedWriter, key string, val float64)

func EncodeInt32

func EncodeInt32(buf *bytes2.ChunkedWriter, key string, val int32)

func EncodeInt64

func EncodeInt64(buf *bytes2.ChunkedWriter, key string, val int64)

func EncodeMap

func EncodeMap(buf *bytes2.ChunkedWriter, key string, val reflect.Value)

func EncodeMapContent

func EncodeMapContent(buf *bytes2.ChunkedWriter, val reflect.Value)

a map seems to lose the 'CanAddr' property. So if we want to use a custom marshaler with a struct pointer receiver, like:

func (ps *PrivateStruct) MarshalBson(buf *bytes2.ChunkedWriter) {

the map has to be using pointers, i.e:

map[string]*PrivateStruct

and not:

map[string]PrivateStruct

(see unit test)

func EncodePrefix

func EncodePrefix(buf *bytes2.ChunkedWriter, etype byte, key string)

func EncodeSlice

func EncodeSlice(buf *bytes2.ChunkedWriter, key string, val reflect.Value)

func EncodeString

func EncodeString(buf *bytes2.ChunkedWriter, key string, val string)

func EncodeStringArray

func EncodeStringArray(buf *bytes2.ChunkedWriter, name string, values []string)

func EncodeStruct

func EncodeStruct(buf *bytes2.ChunkedWriter, key string, val reflect.Value)

func EncodeStructContent

func EncodeStructContent(buf *bytes2.ChunkedWriter, val reflect.Value)

func EncodeTime

func EncodeTime(buf *bytes2.ChunkedWriter, key string, val time.Time)

func EncodeUint64

func EncodeUint64(buf *bytes2.ChunkedWriter, key string, val uint64)

func ExpectIndex

func ExpectIndex(buf *bytes.Buffer, index int)

func Itoa

func Itoa(i int) string

func MapBuilder

func MapBuilder(typ reflect.Type, map_ reflect.Value, key reflect.Value) *valueBuilder

func Marshal

func Marshal(val interface{}) (encoded []byte, err error)

func MarshalToBuffer

func MarshalToBuffer(buf *bytes2.ChunkedWriter, val interface{}) (err error)

func MarshalToStream

func MarshalToStream(writer io.Writer, val interface{}) (err error)

func Next

func Next(buf *bytes.Buffer, n int) []byte

func NextByte

func NextByte(buf *bytes.Buffer) byte

func Parse

func Parse(buf *bytes.Buffer, builder *valueBuilder)

func ReadCString

func ReadCString(buf *bytes.Buffer) string

func TopLevelBuilder

func TopLevelBuilder(val interface{}) (sb *valueBuilder, err error)

Returns a valid unmarshalable valueBuilder or an error

func Unmarshal

func Unmarshal(b []byte, val interface{}) (err error)

func UnmarshalFromBuffer

func UnmarshalFromBuffer(buf *bytes.Buffer, val interface{}) (err error)

func UnmarshalFromStream

func UnmarshalFromStream(reader io.Reader, val interface{}) (err error)

func ValueBuilder

func ValueBuilder(val reflect.Value) *valueBuilder

Types

type BsonError

type BsonError struct {
	Message string
}

func NewBsonError

func NewBsonError(format string, args ...interface{}) BsonError

func (BsonError) Error

func (err BsonError) Error() string

type LenWriter

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

LenWriter records the current write position on the buffer and can later be used to record the number of bytes written in conformance to BSON spec

func NewLenWriter

func NewLenWriter(buf *bytes2.ChunkedWriter) LenWriter

func (LenWriter) RecordLen

func (lw LenWriter) RecordLen()

type Marshaler

type Marshaler interface {
	MarshalBson(buf *bytes2.ChunkedWriter)
}

type SimpleContainer

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

func (*SimpleContainer) MarshalBson

func (sc *SimpleContainer) MarshalBson(buf *bytes2.ChunkedWriter)

type Unmarshaler

type Unmarshaler interface {
	UnmarshalBson(buf *bytes.Buffer)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL