File: exttypes.rb

package info (click to toggle)
ruby-msgpack 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 844 kB
  • ctags: 1,033
  • sloc: ansic: 4,022; ruby: 3,378; java: 1,727; sh: 45; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 823 bytes parent folder | download | duplicates (6)
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