Method: MessagePack::Timestamp.from_msgpack_ext
- Defined in:
- lib/msgpack/timestamp.rb
.from_msgpack_ext(data) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/msgpack/timestamp.rb', line 29 def self.from_msgpack_ext(data) case data.length when 4 # timestamp32 (sec: uint32be) sec, = data.unpack('L>') new(sec, 0) when 8 # timestamp64 (nsec: uint30be, sec: uint34be) n, s = data.unpack('L>2') sec = ((n & 0b11) << 32) | s nsec = n >> 2 new(sec, nsec) when 12 # timestam96 (nsec: uint32be, sec: int64be) nsec, sec = data.unpack('L>q>') new(sec, nsec) else raise MalformedFormatError, "Invalid timestamp data size: #{data.length}" end end |