Documentation ¶
Overview ¶
package bsony ...
Index ¶
- type Array
- func (a *Array) Add(xs ...interface{}) *Array
- func (a *Array) AddArray(v *Array) *Array
- func (a *Array) AddBinary(v *primitive.Binary) *Array
- func (a *Array) AddBool(v bool) *Array
- func (a *Array) AddCodeScope(v CodeWithScope) *Array
- func (a *Array) AddDBPointer(v primitive.DBPointer) *Array
- func (a *Array) AddDateTime(v primitive.DateTime) *Array
- func (a *Array) AddDateTimeFromTime(v time.Time) *Array
- func (a *Array) AddDecimal128(v primitive.Decimal128) *Array
- func (a *Array) AddDoc(v *Doc) *Array
- func (a *Array) AddDouble(v float64) *Array
- func (a *Array) AddInt32(v int32) *Array
- func (a *Array) AddInt64(v int64) *Array
- func (a *Array) AddJavaScript(v primitive.JavaScript) *Array
- func (a *Array) AddMaxKey() *Array
- func (a *Array) AddMinKey() *Array
- func (a *Array) AddNull() *Array
- func (a *Array) AddOID(v primitive.ObjectID) *Array
- func (a *Array) AddRegex(v primitive.Regex) *Array
- func (a *Array) AddString(v string) *Array
- func (a *Array) AddSymbol(v primitive.Symbol) *Array
- func (a *Array) AddTimestamp(v primitive.Timestamp) *Array
- func (a *Array) AddUndefined() *Array
- func (a *Array) Clone() *Array
- func (a *Array) Concat(src *Array) *Array
- func (a *Array) CopyTo(dst []byte) int
- func (a *Array) Err() error
- func (a *Array) Iter() *ArrayIter
- func (a *Array) Len() int
- func (a *Array) Reader() (io.Reader, error)
- func (a *Array) Release()
- func (a *Array) Valid() bool
- type ArrayIter
- type BytePool
- type ByteSlicePool
- type CodeWithScope
- type Doc
- func (d *Doc) Add(k string, v interface{}) *Doc
- func (d *Doc) AddArray(k string, v *Array) *Doc
- func (d *Doc) AddBinary(k string, v *primitive.Binary) *Doc
- func (d *Doc) AddBool(k string, v bool) *Doc
- func (d *Doc) AddCodeScope(k string, v CodeWithScope) *Doc
- func (d *Doc) AddDBPointer(k string, v primitive.DBPointer) *Doc
- func (d *Doc) AddDateTime(k string, v primitive.DateTime) *Doc
- func (d *Doc) AddDateTimeFromTime(k string, v time.Time) *Doc
- func (d *Doc) AddDecimal128(k string, v primitive.Decimal128) *Doc
- func (d *Doc) AddDoc(k string, v *Doc) *Doc
- func (d *Doc) AddDouble(k string, v float64) *Doc
- func (d *Doc) AddInt32(k string, v int32) *Doc
- func (d *Doc) AddInt64(k string, v int64) *Doc
- func (d *Doc) AddJavaScript(k string, v primitive.JavaScript) *Doc
- func (d *Doc) AddMaxKey(k string) *Doc
- func (d *Doc) AddMinKey(k string) *Doc
- func (d *Doc) AddNull(k string) *Doc
- func (d *Doc) AddOID(k string, v primitive.ObjectID) *Doc
- func (d *Doc) AddRegex(k string, v primitive.Regex) *Doc
- func (d *Doc) AddString(k string, v string) *Doc
- func (d *Doc) AddSymbol(k string, v primitive.Symbol) *Doc
- func (d *Doc) AddTimestamp(k string, v primitive.Timestamp) *Doc
- func (d *Doc) AddUndefined(k string) *Doc
- func (d *Doc) Clone() *Doc
- func (d *Doc) Concat(src *Doc) *Doc
- func (d *Doc) CopyTo(dst []byte) int
- func (d *Doc) Err() error
- func (d *Doc) Iter() *DocIter
- func (d *Doc) Len() int
- func (d *Doc) Reader() (io.Reader, error)
- func (d *Doc) Release()
- func (d *Doc) Valid() bool
- type DocIter
- type Factory
- type Type
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
An Array ...
func (*Array) AddDBPointer ¶
AddDBPointer ...
func (*Array) AddDateTime ¶
AddDateTime ...
func (*Array) AddDateTimeFromTime ¶
AddDateTimeFromTime ...
func (*Array) AddDecimal128 ¶
func (a *Array) AddDecimal128(v primitive.Decimal128) *Array
AddDecimal128 ...
func (*Array) AddJavaScript ¶
func (a *Array) AddJavaScript(v primitive.JavaScript) *Array
AddJavaScript ...
func (*Array) AddTimestamp ¶
AddTimestamp ...
type ArrayIter ¶
type ArrayIter struct {
// contains filtered or unexported fields
}
An ArrayIter ...
WARNING: the ArrayIter directly references the underlying data; because buffers may be reused, you MUST NOT keep an ArrayIter beyond the lifetime of the source array.
func (*ArrayIter) Get ¶
func (a *ArrayIter) Get() interface{}
Get returns the value of the current value of the iterator or nil if the end of the document has been reached or if the value could not be parsed. The Get is always a copy of any underlying data; it is safe to keep the result of a Get and release the source document.
func (*ArrayIter) Index ¶
Index returns a zero-based index for the current value of the iterator. If Next has not been called, or if the end of the array has been reached, or if the value could not be parsed, this method returns -1.
func (*ArrayIter) Type ¶
Type returns the type for the current value of the iterator or TypeInvalid if the end of the array has reached or the array is corrupted.
func (*ArrayIter) ValueUnsafe ¶
ValueUnsafe returns an object with raw type and byte slice of data for the current value of the iterator. The Type field will be zero and the Data slice nil if the end of the array is reached. The Err field will be non-nil if an error occured parsing the ValueUnsafe.
WARNING: the ValueUnsafe directly references the underlying data: (1) you MUST NOT modify the bytes of a ValueUnsafe; (2) because buffers may be reused, you MUST NOT keep a ValueUnsafe beyond the lifetime of the source array.
type BytePool ¶
type BytePool struct {
// contains filtered or unexported fields
}
A BytePool wraps a sync.Pool of byte slices, but constrains byte slices created/returned to be between a minimum and maximum capacity.
func NewBytePool ¶
NewBytePool constructs a byte slice pool with minimum and maximum capacities for byte slices in the pool. If minCap is negative, new slices will have zero capacity. If maxCap is negative, no maximum will be applied.
func (*BytePool) Get ¶
Get gives the caller a byte slice from the pool or a new byte slice with the pool's configured minimum slice capacity. The byte slice returned will have its storage zeroed and have length zero.
func (*BytePool) Put ¶
Put returns a byte slice to the pool if the capacity is less than or equal to the pool's configured maximum slice capacity.
func (*BytePool) Resize ¶
Resize returns a slice of the desired length. If the underlying capacity is insufficient, a copy of the slice with doubled capacity is returned. This is an intentional leaky pool abstraction, which minimizes amortized allocations by avoiding recyling small slices back to the pool.
type ByteSlicePool ¶
A ByteSlicePool provides an abstraction for a pool of []byte objects. It provides Get, Put, and Resize methods. The Resize method allows for more control over allocations than relying on the native `append` function to grow slices.
type CodeWithScope ¶
A CodeWithScope represents Javascript code with an associated scope. Unlike the MongoDB Go Driver's `primitive.CodeWithScope`, the CodeWithScope must be a `Doc` from this package.
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
A Doc object represents a BSON document
func (*Doc) AddCodeScope ¶
func (d *Doc) AddCodeScope(k string, v CodeWithScope) *Doc
AddCodeScope ...
func (*Doc) AddDBPointer ¶
AddDBPointer ...
func (*Doc) AddDateTime ¶
AddDateTime ...
func (*Doc) AddDateTimeFromTime ¶
AddDateTimeFromTime ...
func (*Doc) AddDecimal128 ¶
func (d *Doc) AddDecimal128(k string, v primitive.Decimal128) *Doc
AddDecimal128 ...
func (*Doc) AddJavaScript ¶
func (d *Doc) AddJavaScript(k string, v primitive.JavaScript) *Doc
AddJavaScript ...
func (*Doc) AddTimestamp ¶
AddTimestamp ...
type DocIter ¶
type DocIter struct {
// contains filtered or unexported fields
}
A DocIter ...
An initial call to Next() is required to initialize the first value.
WARNING: the DocIter directly references the underlying data; because buffers may be reused, you MUST NOT keep a DocIter beyond the lifetime of the source document.
func (*DocIter) Get ¶
func (i *DocIter) Get() interface{}
Get returns the value of the current value of the iterator or nil if the end of the document has been reached or if the value could not be parsed. The Get is always a copy of any underlying data; it is safe to keep the result of a Get and release the source document.
func (*DocIter) Key ¶
Key returns the key for the current value of the iterator. If the the end of the document has been reached, the empty string will be returned.
func (*DocIter) Next ¶
Next advances the iterator, if possible. It returns true if a value is available.
func (*DocIter) Type ¶
Type returns the type for the current value of the iterator or TypeInvalid if the end of the document has reached or the document is corrupted.
func (*DocIter) Value ¶
Value returns a copy of the current value of the iterator or nil if the end of the document has been reached or if the value could not be parsed. It is safe to keep the value copy and release the source document.
func (*DocIter) ValueUnsafe ¶
ValueUnsafe returns an object with raw type and byte slice of data for the current value of the iterator. The Type field will be zero and the Data slice nil if the end of the document is reached. The Err field will be non-nil if an error occured parsing the ValueUnsafe.
WARNING: the ValueUnsafe directly references the underlying data: (1) you MUST NOT modify the bytes of a ValueUnsafe; (2) because buffers may be reused, you MUST NOT keep a ValueUnsafe beyond the lifetime of the source document.
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
A Factory object is a factory for generating BSON documents and arrays. If Pool is nil, byte slices will be created as needed and not recycled.
func New ¶
func New() *Factory
New returns a new Factory based on a byte slice pool with minimum slice capacity of 256 bytes and no maximum slice capacity.
func NewFromPool ¶
func NewFromPool(pool ByteSlicePool) *Factory
NewFromPool returns a new Factory from a provided ByteSlicePool capacity of 256 bytes and no maximum slice capacity.
type Type ¶
type Type byte
Type represents a BSON type.
const ( TypeInvalid Type = 0x00 TypeDouble Type = 0x01 TypeString Type = 0x02 TypeEmbeddedDocument Type = 0x03 TypeArray Type = 0x04 TypeBinary Type = 0x05 TypeUndefined Type = 0x06 TypeObjectID Type = 0x07 TypeBoolean Type = 0x08 TypeDateTime Type = 0x09 TypeNull Type = 0x0A TypeRegex Type = 0x0B TypeDBPointer Type = 0x0C TypeJavaScript Type = 0x0D TypeSymbol Type = 0x0E TypeCodeWithScope Type = 0x0F TypeInt32 Type = 0x10 TypeTimestamp Type = 0x11 TypeInt64 Type = 0x12 TypeDecimal128 Type = 0x13 TypeMinKey Type = 0xFF TypeMaxKey Type = 0x7F )
These constants uniquely refer to each BSON type.