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 |
| 8 | |
| 9 | import ( |
| 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. |
| 18 | const ( |
| 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 | |
| 42 | var tBinary = reflect.TypeOf(primitive.Binary{}) |
| 43 | var tBool = reflect.TypeOf(false) |
| 44 | var tCodeWithScope = reflect.TypeOf(primitive.CodeWithScope{}) |
| 45 | var tDBPointer = reflect.TypeOf(primitive.DBPointer{}) |
| 46 | var tDecimal = reflect.TypeOf(primitive.Decimal128{}) |
| 47 | var tD = reflect.TypeOf(D{}) |
| 48 | var tA = reflect.TypeOf(A{}) |
| 49 | var tDateTime = reflect.TypeOf(primitive.DateTime(0)) |
| 50 | var tUndefined = reflect.TypeOf(primitive.Undefined{}) |
| 51 | var tNull = reflect.TypeOf(primitive.Null{}) |
| 52 | var tRawValue = reflect.TypeOf(RawValue{}) |
| 53 | var tFloat32 = reflect.TypeOf(float32(0)) |
| 54 | var tFloat64 = reflect.TypeOf(float64(0)) |
| 55 | var tInt = reflect.TypeOf(int(0)) |
| 56 | var tInt8 = reflect.TypeOf(int8(0)) |
| 57 | var tInt16 = reflect.TypeOf(int16(0)) |
| 58 | var tInt32 = reflect.TypeOf(int32(0)) |
| 59 | var tInt64 = reflect.TypeOf(int64(0)) |
| 60 | var tJavaScript = reflect.TypeOf(primitive.JavaScript("")) |
| 61 | var tOID = reflect.TypeOf(primitive.ObjectID{}) |
| 62 | var tRaw = reflect.TypeOf(Raw(nil)) |
| 63 | var tRegex = reflect.TypeOf(primitive.Regex{}) |
| 64 | var tString = reflect.TypeOf("") |
| 65 | var tSymbol = reflect.TypeOf(primitive.Symbol("")) |
| 66 | var tTime = reflect.TypeOf(time.Time{}) |
| 67 | var tTimestamp = reflect.TypeOf(primitive.Timestamp{}) |
| 68 | var tUint = reflect.TypeOf(uint(0)) |
| 69 | var tUint8 = reflect.TypeOf(uint8(0)) |
| 70 | var tUint16 = reflect.TypeOf(uint16(0)) |
| 71 | var tUint32 = reflect.TypeOf(uint32(0)) |
| 72 | var tUint64 = reflect.TypeOf(uint64(0)) |
| 73 | var tMinKey = reflect.TypeOf(primitive.MinKey{}) |
| 74 | var tMaxKey = reflect.TypeOf(primitive.MaxKey{}) |
| 75 | |
| 76 | var tEmpty = reflect.TypeOf((*interface{})(nil)).Elem() |
| 77 | var tEmptySlice = reflect.TypeOf([]interface{}(nil)) |
| 78 | |
| 79 | var 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. |
| 85 | const zeroEpochMs = int64(62135596800000) |