Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeBool(buf *bytes.Buffer, kind byte) bool
- func DecodeBytes(buf *bytes.Buffer, kind byte) []byte
- func DecodeFloat64(buf *bytes.Buffer, kind byte) float64
- func DecodeInt(buf *bytes.Buffer, kind byte) int
- func DecodeInt32(buf *bytes.Buffer, kind byte) int32
- func DecodeInt64(buf *bytes.Buffer, kind byte) int64
- func DecodeString(buf *bytes.Buffer, kind byte) string
- func DecodeStringArray(buf *bytes.Buffer, kind byte) []string
- func DecodeTime(buf *bytes.Buffer, kind byte) time.Time
- func DecodeUint64(buf *bytes.Buffer, kind byte) uint64
- func EncodeBinary(buf *bytes2.ChunkedWriter, val []byte)
- func EncodeBool(buf *bytes2.ChunkedWriter, val bool)
- func EncodeField(buf *bytes2.ChunkedWriter, key string, val interface{})
- func EncodeFloat64(buf *bytes2.ChunkedWriter, val float64)
- func EncodeMap(buf *bytes2.ChunkedWriter, val reflect.Value)
- func EncodePrefix(buf *bytes2.ChunkedWriter, etype byte, key string)
- func EncodeSlice(buf *bytes2.ChunkedWriter, val reflect.Value)
- func EncodeString(buf *bytes2.ChunkedWriter, val string)
- func EncodeStringArray(buf *bytes2.ChunkedWriter, name string, values []string)
- func EncodeStruct(buf *bytes2.ChunkedWriter, val reflect.Value)
- func EncodeTime(buf *bytes2.ChunkedWriter, val time.Time)
- func EncodeUint32(buf *bytes2.ChunkedWriter, val uint32)
- func EncodeUint64(buf *bytes2.ChunkedWriter, val uint64)
- func ExpectIndex(buf *bytes.Buffer, index int)
- func Itoa(i int) string
- func MapBuilder(typ reflect.Type, map_ reflect.Value, key reflect.Value) *valueBuilder
- func Marshal(val interface{}) (encoded []byte, err error)
- func MarshalToBuffer(buf *bytes2.ChunkedWriter, val interface{}) (err error)
- func MarshalToStream(writer io.Writer, val interface{}) (err error)
- func Next(buf *bytes.Buffer, n int) []byte
- func NextByte(buf *bytes.Buffer) byte
- func Parse(buf *bytes.Buffer, builder *valueBuilder)
- func ReadCString(buf *bytes.Buffer) string
- func TopLevelBuilder(val interface{}) (sb *valueBuilder, err error)
- func Unmarshal(b []byte, val interface{}) (err error)
- func UnmarshalFromBuffer(buf *bytes.Buffer, val interface{}) (err error)
- func UnmarshalFromStream(reader io.Reader, val interface{}) (err error)
- func ValueBuilder(val reflect.Value) *valueBuilder
- type BsonError
- type LenWriter
- type Marshaler
- type SimpleContainer
- type Unmarshaler
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 Pack = binary.LittleEndian
BSON documents are lttle endian
Functions ¶
func EncodeBinary ¶
func EncodeBinary(buf *bytes2.ChunkedWriter, val []byte)
func EncodeBool ¶
func EncodeBool(buf *bytes2.ChunkedWriter, val bool)
func EncodeField ¶
func EncodeField(buf *bytes2.ChunkedWriter, key string, val interface{})
func EncodeFloat64 ¶
func EncodeFloat64(buf *bytes2.ChunkedWriter, val float64)
func EncodeMap ¶
func EncodeMap(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, val reflect.Value)
func EncodeString ¶
func EncodeString(buf *bytes2.ChunkedWriter, val string)
func EncodeStringArray ¶
func EncodeStringArray(buf *bytes2.ChunkedWriter, name string, values []string)
func EncodeStruct ¶
func EncodeStruct(buf *bytes2.ChunkedWriter, val reflect.Value)
func EncodeTime ¶
func EncodeTime(buf *bytes2.ChunkedWriter, val time.Time)
func EncodeUint32 ¶
func EncodeUint32(buf *bytes2.ChunkedWriter, val uint32)
func EncodeUint64 ¶
func EncodeUint64(buf *bytes2.ChunkedWriter, val uint64)
func ExpectIndex ¶
func MapBuilder ¶
func MarshalToBuffer ¶
func MarshalToBuffer(buf *bytes2.ChunkedWriter, val interface{}) (err error)
func MarshalToStream ¶
func ReadCString ¶
func TopLevelBuilder ¶
func TopLevelBuilder(val interface{}) (sb *valueBuilder, err error)
Returns a valid unmarshalable valueBuilder or an error
func UnmarshalFromBuffer ¶
func UnmarshalFromStream ¶
func ValueBuilder ¶
Types ¶
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
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 ¶
Click to show internal directories.
Click to hide internal directories.