forked from msgpack/msgpack-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexttypes.rb
More file actions
51 lines (39 loc) · 823 Bytes
/
exttypes.rb
File metadata and controls
51 lines (39 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class DummyTimeStamp1
TYPE = 15
attr_reader :utime, :usec, :time
def initialize(utime, usec)
@utime = utime
@usec = usec
@time = Time.at(utime, usec)
end
def ==(other)
self.utime == other.utime && self.usec == other.usec
end
def self.type_id
15
end
def self.from_msgpack_ext(data)
new(*data.unpack('I*'))
end
def to_msgpack_ext
[@utime,@usec].pack('I*')
end
end
class DummyTimeStamp2
TYPE = 16
attr_reader :utime, :usec, :time
def initialize(utime, usec)
@utime = utime
@usec = usec
@time = Time.at(utime, usec)
end
def ==(other)
self.utime == other.utime && self.usec == other.usec
end
def self.deserialize(data)
new(* data.split(',', 2).map(&:to_i))
end
def serialize
[@utime,@usec].map(&:to_s).join(',')
end
end