Skip to content

Commit 63192a3

Browse files
committed
Fix stale bson package docs.
1 parent 987b3ec commit 63192a3

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

bson/doc.go

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,14 @@
44
// not use this file except in compliance with the License. You may obtain
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

7-
// Package bson is a library for reading, writing, and manipulating BSON. BSON is a binary serialization format used to
8-
// store documents and make remote procedure calls in MongoDB. The BSON specification is located at https://bsonspec.org.
9-
// The BSON library handles marshaling and unmarshaling of values through a configurable codec system. For a description
10-
// of the codec system and examples of registering custom codecs, see the bsoncodec package. For additional information
11-
// and usage examples, check out the [Work with BSON] page in the Go Driver docs site.
12-
//
13-
// # Raw BSON
14-
//
15-
// The Raw family of types is used to validate and retrieve elements from a slice of bytes. This
16-
// type is most useful when you want do lookups on BSON bytes without unmarshaling it into another
17-
// type.
18-
//
19-
// Example:
20-
//
21-
// var raw bson.Raw = ... // bytes from somewhere
22-
// err := raw.Validate()
23-
// if err != nil { return err }
24-
// val := raw.Lookup("foo")
25-
// i32, ok := val.Int32OK()
26-
// // do something with i32...
7+
// Package bson is a library for reading, writing, and manipulating BSON. BSON is a binary serialization
8+
// format used to store documents and make remote procedure calls in MongoDB. For more information about
9+
// the Go BSON library, including usage examples, check out the [Work with BSON] page in the Go Driver
10+
// docs site. For more information about BSON, see https://bsonspec.org.
2711
//
2812
// # Native Go Types
2913
//
30-
// The D and M types defined in this package can be used to build representations of BSON using native Go types. D is a
14+
// The [D] and [M] types defined in this package can be used to build representations of BSON using native Go types. D is a
3115
// slice and M is a map. For more information about the use cases for these types, see the documentation on the type
3216
// definitions.
3317
//
@@ -93,26 +77,16 @@
9377
// 5. When unmarshaling, a field of type interface{} will follow the D/M type mappings listed above. BSON documents
9478
// unmarshaled into an interface{} field will be unmarshaled as a D.
9579
//
96-
// The encoding of each struct field can be customized by the "bson" struct tag.
97-
//
98-
// This tag behavior is configurable, and different struct tag behavior can be configured by initializing a new
99-
// bsoncodec.StructCodec with the desired tag parser and registering that StructCodec onto the Registry. By default, JSON
100-
// tags are not honored, but that can be enabled by creating a StructCodec with JSONFallbackStructTagParser, like below:
101-
//
102-
// Example:
103-
//
104-
// structcodec, _ := bsoncodec.NewStructCodec(bsoncodec.JSONFallbackStructTagParser)
105-
//
106-
// The bson tag gives the name of the field, possibly followed by a comma-separated list of options.
107-
// The name may be empty in order to specify options without overriding the default field name. The following options can
108-
// be used to configure behavior:
80+
// The encoding of each struct field can be customized by the "bson" struct tag. The "bson" tag gives the name of the
81+
// field, followed by a comma-separated list of options. The name may be omitted in order to specify options without
82+
// overriding the default field name. The following options can be used to configure behavior:
10983
//
11084
// 1. omitempty: If the "omitempty" struct tag is specified on a field, the field will not be marshaled if it is set to
11185
// an "empty" value. Numbers, booleans, and strings are considered empty if their value is equal to the zero value for
11286
// the type (i.e. 0 for numbers, false for booleans, and "" for strings). Slices, maps, and arrays are considered
11387
// empty if they are of length zero. Interfaces and pointers are considered empty if their value is nil. By default,
114-
// structs are only considered empty if the struct type implements [bsoncodec.Zeroer] and the IsZero
115-
// method returns true. Struct types that do not implement [bsoncodec.Zeroer] are never considered empty and will be
88+
// structs are only considered empty if the struct type implements [Zeroer] and the "IsZero"
89+
// method returns true. Struct types that do not implement [Zeroer] are never considered empty and will be
11690
// marshaled as embedded documents. NOTE: It is recommended that this tag be used for all slice and map fields.
11791
//
11892
// 2. minsize: If the minsize struct tag is specified on a field of type int64, uint, uint32, or uint64 and the value of
@@ -134,22 +108,34 @@
134108
// error will be returned. This tag can be used with fields that are pointers to structs. If an inlined pointer field
135109
// is nil, it will not be marshaled. For fields that are not maps or structs, this tag is ignored.
136110
//
137-
// # Marshaling and Unmarshaling
111+
// # Raw BSON
138112
//
139-
// Manually marshaling and unmarshaling can be done with the Marshal and Unmarshal family of functions.
113+
// The Raw family of types is used to validate and retrieve elements from a slice of bytes. This
114+
// type is most useful when you want do lookups on BSON bytes without unmarshaling it into another
115+
// type.
140116
//
141-
// bsoncodec code provides a system for encoding values to BSON representations and decoding
142-
// values from BSON representations. This package considers both binary BSON and ExtendedJSON as
143-
// BSON representations. The types in this package enable a flexible system for handling this
144-
// encoding and decoding.
117+
// Example:
145118
//
146-
// The codec system is composed of two parts:
119+
// var raw bson.Raw = ... // bytes from somewhere
120+
// err := raw.Validate()
121+
// if err != nil { return err }
122+
// val := raw.Lookup("foo")
123+
// i32, ok := val.Int32OK()
124+
// // do something with i32...
125+
//
126+
// # Custom Registry
127+
//
128+
// The Go BSON library uses a [Registry] to define encoding and decoding behavior for different data types.
129+
// The default encoding and decoding behavior can be customized or extended by using a modified Registry.
130+
// The custom registry system is composed of two parts:
147131
//
148132
// 1) [ValueEncoder] and [ValueDecoder] that handle encoding and decoding Go values to and from BSON
149133
// representations.
150134
//
151135
// 2) A [Registry] that holds these ValueEncoders and ValueDecoders and provides methods for
152136
// retrieving them.
153137
//
138+
// To use a custom Registry, use [Encoder.SetRegistry] or [Decoder.SetRegistry].
139+
//
154140
// [Work with BSON]: https://www.mongodb.com/docs/drivers/go/current/fundamentals/bson/
155141
package bson

0 commit comments

Comments
 (0)