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 bsontype is a utility package that contains types for each BSON type and the 8// a stringifier for the Type to enable easier debugging when working with BSON. 9package bsontype // import "go.mongodb.org/mongo-driver/bson/bsontype" 10 11// These constants uniquely refer to each BSON type. 12const ( 13 Double Type = 0x01 14 String Type = 0x02 15 EmbeddedDocument Type = 0x03 16 Array Type = 0x04 17 Binary Type = 0x05 18 Undefined Type = 0x06 19 ObjectID Type = 0x07 20 Boolean Type = 0x08 21 DateTime Type = 0x09 22 Null Type = 0x0A 23 Regex Type = 0x0B 24 DBPointer Type = 0x0C 25 JavaScript Type = 0x0D 26 Symbol Type = 0x0E 27 CodeWithScope Type = 0x0F 28 Int32 Type = 0x10 29 Timestamp Type = 0x11 30 Int64 Type = 0x12 31 Decimal128 Type = 0x13 32 MinKey Type = 0xFF 33 MaxKey Type = 0x7F 34 35 BinaryGeneric byte = 0x00 36 BinaryFunction byte = 0x01 37 BinaryBinaryOld byte = 0x02 38 BinaryUUIDOld byte = 0x03 39 BinaryUUID byte = 0x04 40 BinaryMD5 byte = 0x05 41 BinaryUserDefined byte = 0x80 42) 43 44// Type represents a BSON type. 45type Type byte 46 47// String returns the string representation of the BSON type's name. 48func (bt Type) String() string { 49 switch bt { 50 case '\x01': 51 return "double" 52 case '\x02': 53 return "string" 54 case '\x03': 55 return "embedded document" 56 case '\x04': 57 return "array" 58 case '\x05': 59 return "binary" 60 case '\x06': 61 return "undefined" 62 case '\x07': 63 return "objectID" 64 case '\x08': 65 return "boolean" 66 case '\x09': 67 return "UTC datetime" 68 case '\x0A': 69 return "null" 70 case '\x0B': 71 return "regex" 72 case '\x0C': 73 return "dbPointer" 74 case '\x0D': 75 return "javascript" 76 case '\x0E': 77 return "symbol" 78 case '\x0F': 79 return "code with scope" 80 case '\x10': 81 return "32-bit integer" 82 case '\x11': 83 return "timestamp" 84 case '\x12': 85 return "64-bit integer" 86 case '\x13': 87 return "128-bit decimal" 88 case '\xFF': 89 return "min key" 90 case '\x7F': 91 return "max key" 92 default: 93 return "invalid" 94 } 95} 96