本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5KB

  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. // Package bson is a library for reading, writing, and manipulating BSON. The
  7. // library has two families of types for representing BSON.
  8. //
  9. // The Raw family of types is used to validate and retrieve elements from a slice of bytes. This
  10. // type is most useful when you want do lookups on BSON bytes without unmarshaling it into another
  11. // type.
  12. //
  13. // Example:
  14. // var raw bson.Raw = ... // bytes from somewhere
  15. // err := raw.Validate()
  16. // if err != nil { return err }
  17. // val := raw.Lookup("foo")
  18. // i32, ok := val.Int32OK()
  19. // // do something with i32...
  20. //
  21. // The D family of types is used to build concise representations of BSON using native Go types.
  22. // These types do not support automatic lookup.
  23. //
  24. // Example:
  25. // bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}}
  26. //
  27. //
  28. // Marshaling and Unmarshaling are handled with the Marshal and Unmarshal family of functions. If
  29. // you need to write or read BSON from a non-slice source, an Encoder or Decoder can be used with a
  30. // bsonrw.ValueWriter or bsonrw.ValueReader.
  31. //
  32. // Example:
  33. // b, err := bson.Marshal(bson.D{{"foo", "bar"}})
  34. // if err != nil { return err }
  35. // var fooer struct {
  36. // Foo string
  37. // }
  38. // err = bson.Unmarshal(b, &fooer)
  39. // if err != nil { return err }
  40. // // do something with fooer...
  41. package bson
上海开阖软件有限公司 沪ICP备12045867号-1