@@ -40,14 +40,15 @@ require "crystal/spin_lock"
40
40
# ```
41
41
#
42
42
struct CSUUID
43
- VERSION = " 0.3.0 "
43
+ VERSION = " 0.3.1 "
44
44
45
45
@@mutex = Crystal ::SpinLock .new
46
46
@@prng = Random ::ISAAC .new
47
47
@@unique_identifier : Slice (UInt8 ) = Slice (UInt8 ).new(6 , 0 )
48
48
@@unique_seconds_and_nanoseconds : Tuple (Int64 , Int32 ) = {0 _i64 , 0 _i32 }
49
49
50
- @bytes : Slice (UInt8 ) = Slice (UInt8 ).new(16 )
50
+ # A getter to allow access to the raw byte buffer for the CSUUID.
51
+ getter bytes : Slice (UInt8 ) = Slice (UInt8 ).new(16 )
51
52
@seconds_and_nanoseconds : Tuple (Int64 , Int32 )?
52
53
@timestamp : Time ?
53
54
@utc : Time ?
@@ -74,7 +75,7 @@ struct CSUUID
74
75
75
76
def self.generate (count )
76
77
result = [] of CSUUID
77
- count.times {result << unique}
78
+ count.times { result << unique }
78
79
79
80
result
80
81
end
@@ -113,13 +114,13 @@ struct CSUUID
113
114
114
115
private def initialize_impl (seconds : Int64 , nanoseconds : Int32 , identifier : Slice (UInt8 ) | String | Nil )
115
116
id = if identifier.is_a?(String )
116
- buf = Slice (UInt8 ).new(6 )
117
- number_of_bytes = identifier.size < 6 ? identifier.size : 6
118
- buf[0 , number_of_bytes].copy_from(identifier.hexbytes[0 , number_of_bytes])
119
- buf
120
- else
121
- identifier
122
- end
117
+ buf = Slice (UInt8 ).new(6 )
118
+ number_of_bytes = identifier.size < 6 ? identifier.size : 6
119
+ buf[0 , number_of_bytes].copy_from(identifier.hexbytes[0 , number_of_bytes])
120
+ buf
121
+ else
122
+ identifier
123
+ end
123
124
124
125
IO ::ByteFormat ::BigEndian .encode(seconds, @bytes [2 , 8 ])
125
126
IO ::ByteFormat ::BigEndian .encode(nanoseconds, @bytes [0 , 4 ])
0 commit comments