You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bsontype.go 2.1KB

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