blob: 7109254619056ea944da97b087763f9aa1b59ffb [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// 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
7package bson
8
9import (
10 "reflect"
11 "time"
12
13 "github.com/mongodb/mongo-go-driver/bson/bsontype"
14 "github.com/mongodb/mongo-go-driver/bson/primitive"
15)
16
17// These constants uniquely refer to each BSON type.
18const (
19 TypeDouble = bsontype.Double
20 TypeString = bsontype.String
21 TypeEmbeddedDocument = bsontype.EmbeddedDocument
22 TypeArray = bsontype.Array
23 TypeBinary = bsontype.Binary
24 TypeUndefined = bsontype.Undefined
25 TypeObjectID = bsontype.ObjectID
26 TypeBoolean = bsontype.Boolean
27 TypeDateTime = bsontype.DateTime
28 TypeNull = bsontype.Null
29 TypeRegex = bsontype.Regex
30 TypeDBPointer = bsontype.DBPointer
31 TypeJavaScript = bsontype.JavaScript
32 TypeSymbol = bsontype.Symbol
33 TypeCodeWithScope = bsontype.CodeWithScope
34 TypeInt32 = bsontype.Int32
35 TypeTimestamp = bsontype.Timestamp
36 TypeInt64 = bsontype.Int64
37 TypeDecimal128 = bsontype.Decimal128
38 TypeMinKey = bsontype.MinKey
39 TypeMaxKey = bsontype.MaxKey
40)
41
42var tBinary = reflect.TypeOf(primitive.Binary{})
43var tBool = reflect.TypeOf(false)
44var tCodeWithScope = reflect.TypeOf(primitive.CodeWithScope{})
45var tDBPointer = reflect.TypeOf(primitive.DBPointer{})
46var tDecimal = reflect.TypeOf(primitive.Decimal128{})
47var tD = reflect.TypeOf(D{})
48var tA = reflect.TypeOf(A{})
49var tDateTime = reflect.TypeOf(primitive.DateTime(0))
50var tUndefined = reflect.TypeOf(primitive.Undefined{})
51var tNull = reflect.TypeOf(primitive.Null{})
52var tRawValue = reflect.TypeOf(RawValue{})
53var tFloat32 = reflect.TypeOf(float32(0))
54var tFloat64 = reflect.TypeOf(float64(0))
55var tInt = reflect.TypeOf(int(0))
56var tInt8 = reflect.TypeOf(int8(0))
57var tInt16 = reflect.TypeOf(int16(0))
58var tInt32 = reflect.TypeOf(int32(0))
59var tInt64 = reflect.TypeOf(int64(0))
60var tJavaScript = reflect.TypeOf(primitive.JavaScript(""))
61var tOID = reflect.TypeOf(primitive.ObjectID{})
62var tRaw = reflect.TypeOf(Raw(nil))
63var tRegex = reflect.TypeOf(primitive.Regex{})
64var tString = reflect.TypeOf("")
65var tSymbol = reflect.TypeOf(primitive.Symbol(""))
66var tTime = reflect.TypeOf(time.Time{})
67var tTimestamp = reflect.TypeOf(primitive.Timestamp{})
68var tUint = reflect.TypeOf(uint(0))
69var tUint8 = reflect.TypeOf(uint8(0))
70var tUint16 = reflect.TypeOf(uint16(0))
71var tUint32 = reflect.TypeOf(uint32(0))
72var tUint64 = reflect.TypeOf(uint64(0))
73var tMinKey = reflect.TypeOf(primitive.MinKey{})
74var tMaxKey = reflect.TypeOf(primitive.MaxKey{})
75
76var tEmpty = reflect.TypeOf((*interface{})(nil)).Elem()
77var tEmptySlice = reflect.TypeOf([]interface{}(nil))
78
79var zeroVal reflect.Value
80
81// this references the quantity of milliseconds between zero time and
82// the unix epoch. useful for making sure that we convert time.Time
83// objects correctly to match the legacy bson library's handling of
84// time.Time values.
85const zeroEpochMs = int64(62135596800000)