/extra/bson/constants/constants.factor

http://github.com/abeaumont/factor · Factor · 88 lines · 67 code · 19 blank · 2 comment · 3 complexity · 9b3dd516fbacc153742513c9f12fcd4a MD5 · raw file

  1. ! Copyright (C) 2010 Sascha Matzke.
  2. ! See http://factorcode.org/license.txt for BSD license.
  3. USING: accessors assocs calendar combinators
  4. combinators.short-circuit constructors kernel linked-assocs
  5. math math.bitwise random strings uuid ;
  6. IN: bson.constants
  7. : <objid> ( -- objid )
  8. uuid1 ; inline
  9. TUPLE: oid { a initial: 0 } { b initial: 0 } ;
  10. : <oid> ( -- oid )
  11. oid new
  12. now timestamp>micros >>a
  13. 8 random-bits 16 shift 0xFF0000 mask
  14. 16 random-bits 0xFFFF mask
  15. bitor >>b ;
  16. TUPLE: dbref ref id db ;
  17. TUPLE: mongo-timestamp incr seconds ;
  18. : <mongo-timestamp> ( incr seconds -- mongo-timestamp )
  19. mongo-timestamp boa ;
  20. TUPLE: mongo-scoped-code code object ;
  21. : <mongo-scoped-code> ( code object -- mongo-scoped-code )
  22. mongo-scoped-code boa ;
  23. CONSTRUCTOR: dbref ( ref id -- dbref ) ;
  24. : dbref>assoc ( dbref -- assoc )
  25. [ <linked-hash> ] dip over
  26. {
  27. [ [ ref>> "$ref" ] [ set-at ] bi* ]
  28. [ [ id>> "$id" ] [ set-at ] bi* ]
  29. [ over db>> [
  30. [ db>> "$db" ] [ set-at ] bi*
  31. ] [ 2drop ] if ]
  32. } 2cleave ; inline
  33. : assoc>dbref ( assoc -- dbref )
  34. [ "$ref" swap at ] [ "$id" swap at ] [ "$db" swap at ] tri
  35. dbref boa ; inline
  36. : dbref-assoc? ( assoc -- ? )
  37. { [ "$ref" swap key? ] [ "$id" swap key? ] } 1&& ; inline
  38. TUPLE: mdbregexp { regexp string } { options string } ;
  39. : <mdbregexp> ( string -- mdbregexp )
  40. [ mdbregexp new ] dip >>regexp ;
  41. CONSTANT: MDB_OID_FIELD "_id"
  42. CONSTANT: MDB_META_FIELD "_mfd"
  43. CONSTANT: T_EOO 0
  44. CONSTANT: T_Double 0x1
  45. CONSTANT: T_String 0x2
  46. CONSTANT: T_Object 0x3
  47. CONSTANT: T_Array 0x4
  48. CONSTANT: T_Binary 0x5
  49. CONSTANT: T_Undefined 0x6
  50. CONSTANT: T_OID 0x7
  51. CONSTANT: T_Boolean 0x8
  52. CONSTANT: T_Date 0x9
  53. CONSTANT: T_NULL 0xA
  54. CONSTANT: T_Regexp 0xB
  55. CONSTANT: T_DBRef 0xC
  56. CONSTANT: T_Code 0xD
  57. CONSTANT: T_Symbol 0xE
  58. CONSTANT: T_ScopedCode 0xF
  59. CONSTANT: T_Integer 0x10
  60. CONSTANT: T_Timestamp 0x11
  61. CONSTANT: T_Integer64 0x12
  62. CONSTANT: T_MinKey 0xFF
  63. CONSTANT: T_MaxKey 0x7F
  64. CONSTANT: T_Binary_Default 0x0
  65. CONSTANT: T_Binary_Function 0x1
  66. CONSTANT: T_Binary_Bytes_Deprecated 0x2
  67. CONSTANT: T_Binary_UUID 0x3
  68. CONSTANT: T_Binary_MD5 0x5
  69. CONSTANT: T_Binary_Custom 0x80