Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | // Package bson is a library for reading, writing, and manipulating BSON. The |
| 8 | // library has two families of types for representing BSON. |
| 9 | // |
| 10 | // The Raw family of types is used to validate and retrieve elements from a slice of bytes. This |
| 11 | // type is most useful when you want do lookups on BSON bytes without unmarshaling it into another |
| 12 | // type. |
| 13 | // |
| 14 | // Example: |
| 15 | // var raw bson.Raw = ... // bytes from somewhere |
| 16 | // err := raw.Validate() |
| 17 | // if err != nil { return err } |
| 18 | // val := raw.Lookup("foo") |
| 19 | // i32, ok := val.Int32OK() |
| 20 | // // do something with i32... |
| 21 | // |
| 22 | // The D family of types is used to build concise representations of BSON using native Go types. |
| 23 | // These types do not support automatic lookup. |
| 24 | // |
| 25 | // Example: |
| 26 | // bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}} |
| 27 | // |
| 28 | // |
| 29 | // Marshaling and Unmarshaling are handled with the Marshal and Unmarshal family of functions. If |
| 30 | // you need to write or read BSON from a non-slice source, an Encoder or Decoder can be used with a |
| 31 | // bsonrw.ValueWriter or bsonrw.ValueReader. |
| 32 | // |
| 33 | // Example: |
| 34 | // b, err := bson.Marshal(bson.D{{"foo", "bar"}}) |
| 35 | // if err != nil { return err } |
| 36 | // var fooer struct { |
| 37 | // Foo string |
| 38 | // } |
| 39 | // err = bson.Unmarshal(b, &fooer) |
| 40 | // if err != nil { return err } |
| 41 | // // do something with fooer... |
| 42 | package bson |