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
- Variables
- func Decode(payload []byte, target any, options DecodeOptions) error
- func DecodeReader(reader io.Reader, target any, options DecodeOptions) error
- func Encode(value any, options EncodeOptions) ([]byte, error)
- func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error
- type A
- type Binary
- type CodeWithScope
- type D
- type DBPointer
- type DateTime
- type Decimal128
- type DecodeOptions
- type E
- type EncodeOptions
- type JavaScript
- type M
- type MaxKey
- type MinKey
- type ObjectID
- type Raw
- type RawArray
- type RawValue
- type Regex
- type Symbol
- type Timestamp
- type Undefined
Constants ¶
const DefaultMaxBytes int64 = 1 << 20
DefaultMaxBytes is the default maximum BSON document size.
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 ¶
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 ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type 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 ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type DBPointer ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type 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 ¶
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 ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type MaxKey ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type MinKey ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type ObjectID ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type Raw ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type RawArray ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type RawValue ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type Regex ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.
type Symbol ¶
Official BSON data types are re-exported for complete interoperability without a second, subtly different local type system.