blob: a17e5f5198a07ef8e94a90c4560bef3697fc3d3d [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
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
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
36// Type represents a BSON type.
37type Type byte
38
39// String returns the string representation of the BSON type's name.
40func (bt Type) String() string {
41 switch bt {
42 case '\x01':
43 return "double"
44 case '\x02':
45 return "string"
46 case '\x03':
47 return "embedded document"
48 case '\x04':
49 return "array"
50 case '\x05':
51 return "binary"
52 case '\x06':
53 return "undefined"
54 case '\x07':
55 return "objectID"
56 case '\x08':
57 return "boolean"
58 case '\x09':
59 return "UTC datetime"
60 case '\x0A':
61 return "null"
62 case '\x0B':
63 return "regex"
64 case '\x0C':
65 return "dbPointer"
66 case '\x0D':
67 return "javascript"
68 case '\x0E':
69 return "symbol"
70 case '\x0F':
71 return "code with scope"
72 case '\x10':
73 return "32-bit integer"
74 case '\x11':
75 return "timestamp"
76 case '\x12':
77 return "64-bit integer"
78 case '\x13':
79 return "128-bit decimal"
80 case '\xFF':
81 return "min key"
82 case '\x7F':
83 return "max key"
84 default:
85 return "invalid"
86 }
87}