-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregistry.go
43 lines (40 loc) · 2.1 KB
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package protobson
import (
"go.mongodb.org/mongo-driver/bson"
"go.vallahaye.net/protobson/protobsoncodec"
googleapiscodec "go.vallahaye.net/protobson/protobsoncodec/googleapis"
knowncodec "go.vallahaye.net/protobson/protobsoncodec/known"
)
var (
defaultBoolValueCodec = knowncodec.NewBoolValueCodec()
defaultBytesValueCodec = knowncodec.NewBytesValueCodec()
defaultDoubleValueCodec = knowncodec.NewDoubleValueCodec()
defaultDurationCodec = knowncodec.NewDurationCodec()
defaultFloatValueCodec = knowncodec.NewFloatValueCodec()
defaultInt32ValueCodec = knowncodec.NewInt32ValueCodec()
defaultInt64ValueCodec = knowncodec.NewInt64ValueCodec()
defaultMessageCodec = protobsoncodec.NewMessageCodec()
defaultStringValueCodec = knowncodec.NewStringValueCodec()
defaultTimestampCodec = knowncodec.NewTimestampCodec()
defaultUInt32ValueCodec = knowncodec.NewUInt32ValueCodec()
defaultUInt64ValueCodec = knowncodec.NewUInt64ValueCodec()
defaultGAPIDateTimeCodec = googleapiscodec.NewDateTimeCodec()
)
// DefaultRegistry is the default bsoncodec.Registry with all default protobson
// codecs registered.
var DefaultRegistry = bson.NewRegistryBuilder().
RegisterCodec(knowncodec.TypeBoolValue, defaultBoolValueCodec).
RegisterCodec(knowncodec.TypeBytesValue, defaultBytesValueCodec).
RegisterCodec(knowncodec.TypeDoubleValue, defaultDoubleValueCodec).
RegisterCodec(knowncodec.TypeDuration, defaultDurationCodec).
RegisterCodec(knowncodec.TypeFloatValue, defaultFloatValueCodec).
RegisterCodec(knowncodec.TypeInt32Value, defaultInt32ValueCodec).
RegisterCodec(knowncodec.TypeInt64Value, defaultInt64ValueCodec).
RegisterHookEncoder(protobsoncodec.TypeMessage, defaultMessageCodec).
RegisterHookDecoder(protobsoncodec.TypeMessage, defaultMessageCodec).
RegisterCodec(knowncodec.TypeStringValue, defaultStringValueCodec).
RegisterCodec(knowncodec.TypeTimestamp, defaultTimestampCodec).
RegisterCodec(knowncodec.TypeUInt32Value, defaultUInt32ValueCodec).
RegisterCodec(knowncodec.TypeUInt64Value, defaultUInt64ValueCodec).
RegisterCodec(googleapiscodec.TypeDateTime, defaultGAPIDateTimeCodec).
Build()