Class: MessagePack::Timestamp

Inherits:
Object
  • Object
show all
Defined in:
doclib/msgpack/timestamp.rb

Overview

A utility class for MessagePack timestamp type

Constant Summary collapse

TYPE =

The timestamp extension type defined in the MessagePack spec.

See github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type for details.

-1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sec, nsec) ⇒ Timestamp

Returns a new instance of Timestamp.

Parameters:

  • sec (Integer)
  • nsec (Integer)


19
20
# File 'doclib/msgpack/timestamp.rb', line 19

def initialize(sec, nsec)
end

Instance Attribute Details

#nsecInteger (readonly)

Returns Nanosecond part of the timestamp.

Returns:

  • (Integer)

    Nanosecond part of the timestamp.



15
16
17
# File 'doclib/msgpack/timestamp.rb', line 15

def nsec
  @nsec
end

#secInteger (readonly)

Returns Second part of the timestamp.

Returns:

  • (Integer)

    Second part of the timestamp.



12
13
14
# File 'doclib/msgpack/timestamp.rb', line 12

def sec
  @sec
end

Class Method Details

.from_msgpack_ext(data) ⇒ MessagePack::Timestamp

Examples:

An unpacker implementation for the Time class

lambda do |payload|
  tv = MessagePack::Timestamp.from_msgpack_ext(payload)
  Time.at(tv.sec, tv.nsec, :nanosecond)
end

Parameters:

Returns:



30
31
# File 'doclib/msgpack/timestamp.rb', line 30

def self.from_msgpack_ext(data)
end

.to_msgpack_ext(sec, nsec) ⇒ String

Examples:

A packer implementation for the Time class

unpacker = lambda do |time|
  MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec)
end

Parameters:

  • sec (Integer)
  • nsec (Integer)

Returns:



41
42
# File 'doclib/msgpack/timestamp.rb', line 41

def self.to_msgpack_ext(sec, nsec)
end