bsonwire

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package bsonwire provides bounded BSON document decoding and encoding.

The package accepts complete BSON documents only; top-level scalar values and arrays are not documents and are rejected. Duplicate keys are rejected recursively by default, including inside embedded documents and arrays. ObjectID, datetime, numeric-width, ordered document, and raw document types are aliases of the official MongoDB driver types. Structs and D values have stable field order; M map order is intentionally not deterministic. BSON is excluded from wire.DetectFormat because arbitrary binary data cannot be identified reliably.

Index

Constants

View Source
const DefaultMaxBytes int64 = 1 << 20

DefaultMaxBytes is the default maximum BSON document size.

View Source
const DefaultMaxNestedLevels = 100

DefaultMaxNestedLevels is the maximum raw-validation nesting below the root. Documents, arrays, and CodeWithScope scope documents each add one level. Encoding checks this policy after codec work, not before its allocation.

Variables

View Source
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")

ErrPayloadTooLarge identifies BSON documents over the configured byte limit.

Functions

func Decode

func Decode(payload []byte, target any, options DecodeOptions) error

Decode parses exactly one complete BSON document into target.

func DecodeReader

func DecodeReader(reader io.Reader, target any, options DecodeOptions) error

DecodeReader reads a bounded stream and parses exactly one BSON document.

func Encode

func Encode(value any, options EncodeOptions) ([]byte, error)

Encode serializes a BSON document. Struct and D ordering is stable; M map ordering follows Go map iteration and is intentionally not guaranteed.

func EncodeWriter

func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error

EncodeWriter serializes value and writes one complete BSON document.

Types

type A

type A = bson.A

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type Binary

type Binary = bson.Binary

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type CodeWithScope

type CodeWithScope = bson.CodeWithScope

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type D

type D = bson.D

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type DBPointer

type DBPointer = bson.DBPointer

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type DateTime

type DateTime = bson.DateTime

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type Decimal128

type Decimal128 = bson.Decimal128

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type DecodeOptions

type DecodeOptions struct {
	MaxBytes               int64
	AllowDuplicateKeys     bool
	ObjectIDAsHexString    bool
	AllowTruncatingDoubles bool
}

DecodeOptions controls BSON decoding and explicit interoperability choices.

type E

type E = bson.E

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type EncodeOptions

type EncodeOptions struct {
	MaxBytes             int64
	AllowDuplicateKeys   bool
	MinimizeIntegerWidth bool
	UseJSONStructTags    bool
}

EncodeOptions controls BSON document encoding.

type JavaScript

type JavaScript = bson.JavaScript

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type M

type M = bson.M

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type MaxKey

type MaxKey = bson.MaxKey

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type MinKey

type MinKey = bson.MinKey

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type ObjectID

type ObjectID = bson.ObjectID

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type Raw

type Raw = bson.Raw

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type RawArray

type RawArray = bson.RawArray

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type RawValue

type RawValue = bson.RawValue

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type Regex

type Regex = bson.Regex

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type Symbol

type Symbol = bson.Symbol

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type Timestamp

type Timestamp = bson.Timestamp

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

type Undefined

type Undefined = bson.Undefined

Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.

Jump to

Keyboard shortcuts

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