...
1
2
3
4
5
6
7
8
9 package bsontype
10
11
12
13
14 const (
15 Double Type = 0x01
16 String Type = 0x02
17 EmbeddedDocument Type = 0x03
18 Array Type = 0x04
19 Binary Type = 0x05
20 Undefined Type = 0x06
21 ObjectID Type = 0x07
22 Boolean Type = 0x08
23 DateTime Type = 0x09
24 Null Type = 0x0A
25 Regex Type = 0x0B
26 DBPointer Type = 0x0C
27 JavaScript Type = 0x0D
28 Symbol Type = 0x0E
29 CodeWithScope Type = 0x0F
30 Int32 Type = 0x10
31 Timestamp Type = 0x11
32 Int64 Type = 0x12
33 Decimal128 Type = 0x13
34 MinKey Type = 0xFF
35 MaxKey Type = 0x7F
36 )
37
38
39
40
41 const (
42 BinaryGeneric byte = 0x00
43 BinaryFunction byte = 0x01
44 BinaryBinaryOld byte = 0x02
45 BinaryUUIDOld byte = 0x03
46 BinaryUUID byte = 0x04
47 BinaryMD5 byte = 0x05
48 BinaryEncrypted byte = 0x06
49 BinaryColumn byte = 0x07
50 BinarySensitive byte = 0x08
51 BinaryUserDefined byte = 0x80
52 )
53
54
55 type Type byte
56
57
58 func (bt Type) String() string {
59 switch bt {
60 case '\x01':
61 return "double"
62 case '\x02':
63 return "string"
64 case '\x03':
65 return "embedded document"
66 case '\x04':
67 return "array"
68 case '\x05':
69 return "binary"
70 case '\x06':
71 return "undefined"
72 case '\x07':
73 return "objectID"
74 case '\x08':
75 return "boolean"
76 case '\x09':
77 return "UTC datetime"
78 case '\x0A':
79 return "null"
80 case '\x0B':
81 return "regex"
82 case '\x0C':
83 return "dbPointer"
84 case '\x0D':
85 return "javascript"
86 case '\x0E':
87 return "symbol"
88 case '\x0F':
89 return "code with scope"
90 case '\x10':
91 return "32-bit integer"
92 case '\x11':
93 return "timestamp"
94 case '\x12':
95 return "64-bit integer"
96 case '\x13':
97 return "128-bit decimal"
98 case '\xFF':
99 return "min key"
100 case '\x7F':
101 return "max key"
102 default:
103 return "invalid"
104 }
105 }
106
107
108 func (bt Type) IsValid() bool {
109 switch bt {
110 case Double, String, EmbeddedDocument, Array, Binary, Undefined, ObjectID, Boolean, DateTime, Null, Regex,
111 DBPointer, JavaScript, Symbol, CodeWithScope, Int32, Timestamp, Int64, Decimal128, MinKey, MaxKey:
112 return true
113 default:
114 return false
115 }
116 }
117
View as plain text