Documentation
¶
Overview ¶
Package bsonlite provides a minimal BSON codec for strfmt types.
This codec produces BSON output compatible with go.mongodb.org/mongo-driver/v2 (v2.5.0). It handles only the exact BSON patterns used by strfmt: single-key {"data": value} documents with string, DateTime, or ObjectID values.
This package is intended to provide a backward-compatible API to users of go-openapi/strfmt. It is not intended to be maintained or to follow the evolutions of the official MongoDB drivers. For up-to-date MongoDB support, import "github.com/go-openapi/strfmt/enable/mongodb" to replace this codec with one backed by the real driver.
Index ¶
Constants ¶
const ( TypeString byte = 0x02 TypeObjectID byte = 0x07 TypeDateTime byte = 0x09 TypeNull byte = 0x0A )
BSON type tags (from the BSON specification).
const ObjectIDSize = 12
ObjectIDSize is the size of a BSON ObjectID in bytes.
Variables ¶
This section is empty.
Functions ¶
func DateTimeToMillis ¶
DateTimeToMillis converts a time.Time to BSON DateTime milliseconds.
func MillisToTime ¶
MillisToTime converts BSON DateTime milliseconds to time.Time.
Types ¶
type Codec ¶
type Codec interface {
MarshalDoc(value any) ([]byte, error)
UnmarshalDoc(data []byte) (any, error)
}
Codec provides BSON document marshal/unmarshal for strfmt types.
MarshalDoc encodes a single-key BSON document {"data": value}. The value must be one of: string, time.Time, or [12]byte (ObjectID).
UnmarshalDoc decodes a BSON document and returns the "data" field's value. Returns one of: string, time.Time, or [12]byte depending on the BSON type.
var C Codec = liteCodec{}
C is the active BSON codec.