registry.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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
  7. import (
  8. "go.mongodb.org/mongo-driver/bson/bsoncodec"
  9. )
  10. // DefaultRegistry is the default bsoncodec.Registry. It contains the default codecs and the
  11. // primitive codecs.
  12. var DefaultRegistry = NewRegistry()
  13. // NewRegistryBuilder creates a new RegistryBuilder configured with the default encoders and
  14. // decoders from the bsoncodec.DefaultValueEncoders and bsoncodec.DefaultValueDecoders types and the
  15. // PrimitiveCodecs type in this package.
  16. //
  17. // Deprecated: Use NewRegistry instead.
  18. func NewRegistryBuilder() *bsoncodec.RegistryBuilder {
  19. rb := bsoncodec.NewRegistryBuilder()
  20. bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(rb)
  21. bsoncodec.DefaultValueDecoders{}.RegisterDefaultDecoders(rb)
  22. primitiveCodecs.RegisterPrimitiveCodecs(rb)
  23. return rb
  24. }
  25. // NewRegistry creates a new Registry configured with the default encoders and decoders from the
  26. // bsoncodec.DefaultValueEncoders and bsoncodec.DefaultValueDecoders types and the PrimitiveCodecs
  27. // type in this package.
  28. func NewRegistry() *bsoncodec.Registry {
  29. return NewRegistryBuilder().Build()
  30. }