bsonlite

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

View Source
const (
	TypeString   byte = 0x02
	TypeObjectID byte = 0x07
	TypeDateTime byte = 0x09
	TypeNull     byte = 0x0A
)

BSON type tags (from the BSON specification).

View Source
const ObjectIDSize = 12

ObjectIDSize is the size of a BSON ObjectID in bytes.

Variables

This section is empty.

Functions

func DateTimeToMillis

func DateTimeToMillis(t time.Time) int64

DateTimeToMillis converts a time.Time to BSON DateTime milliseconds.

func MillisToTime

func MillisToTime(millis int64) time.Time

MillisToTime converts BSON DateTime milliseconds to time.Time.

func Replace

func Replace(c Codec)

Replace swaps the active BSON codec with the provided implementation. This is intended to be called from enable/mongodb's init().

Since Replace affects the global state of the package, it is not intended for concurrent use.

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.

Jump to

Keyboard shortcuts

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