Documentation
¶
Overview ¶
Package bson provides converters from/to BSON.
JSON mapping for storage
Double: {"$f": JSON number} or {"$f": "Infinity|-Infinity|NaN"}
String: JSON string
Document: {"$k": ["<key 1>", "<key 2>", ...], "<key 1>": <value 1>, "<key 2>": <value 2>, ...}
Array: JSON array
Binary: {"$b": "<base 64 string>", "s": <subtype number>}
ObjectID: {"$o": "<ObjectID as 24 character hex string"}
Bool: JSON true / false values
DateTime: {"$d": "milliseconds since epoch as string"}
Regex: {"$r": "<string without terminating 0x0>", "o": "<string without terminating 0x0>"}
Int32: JSON number
Timestamp: {"$t": "<number as string>"}
Int64: {"$l": "<number as string>"}
CString: {"$c": "<string without terminating 0x0>"}
Index ¶
- Constants
- type Array
- type Binary
- type Bool
- type CString
- type DateTime
- type Document
- func (doc *Document) Keys() []string
- func (doc *Document) Map() map[string]interface{}
- func (doc Document) MarshalBinary() ([]byte, error)
- func (doc Document) MarshalJSON() ([]byte, error)
- func (doc *Document) ReadFrom(r *bufio.Reader) error
- func (doc *Document) UnmarshalJSON(data []byte) error
- func (doc Document) WriteTo(w *bufio.Writer) error
- type Double
- type Int32
- type Int64
- type ObjectID
- type Regex
- type String
- type Timestamp
Constants ¶
const (
MaxDocumentLen = 16777216
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array []interface{}
Array represents BSON Array data type.
func (Array) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Array) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Array) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type Binary ¶
type Binary struct {
Subtype types.BinarySubtype
B []byte
}
Binary represents BSON Binary data type.
func (Binary) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Binary) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Binary) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type Bool ¶
type Bool bool
Bool represents BSON Bool data type.
func (Bool) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Bool) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type CString ¶
type CString string
CString represents BSON CString data type.
func (CString) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (CString) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*CString) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type DateTime ¶
DateTime represents BSON DateTime data type.
func (DateTime) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (DateTime) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*DateTime) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document represents BSON Document data type.
func ConvertDocument ¶
ConvertDocument converts types.Document to bson.Document and validates it. It references the same data without copying it.
func MustConvertDocument ¶
func MustConvertDocument(d document) *Document
MustConvertDocument is a ConvertDocument that panics in case of error.
func (Document) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Document) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Document) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type Double ¶
type Double float64
Double represents BSON Double data type.
func (Double) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Double) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Double) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type Int32 ¶
type Int32 int32
Int32 represents BSON Int32 data type.
func (Int32) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Int32) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Int32) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type Int64 ¶
type Int64 int64
Int64 represents BSON Int64 data type.
func (Int64) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Int64) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Int64) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type ObjectID ¶
type ObjectID [12]byte
ObjectID represents BSON ObjectID data type.
func (ObjectID) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (ObjectID) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*ObjectID) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type Regex ¶
Regex represents BSON Regex data type.
func (Regex) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Regex) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Regex) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type String ¶
type String string
String represents BSON String data type.
func (String) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (String) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.
type Timestamp ¶
type Timestamp uint64
Timestamp represents BSON Timestamp data type.
func (Timestamp) MarshalBinary ¶
MarshalBinary implements bsontype interface.
func (Timestamp) MarshalJSON ¶
MarshalJSON implements bsontype interface.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON implements bsontype interface.