Sha256: da62b730ad2fc9dbc00c9a1ad7a088fbf495e0508be3ec45538de14512386718

Contents?: true

Size: 443 Bytes

Versions: 2

Compression:

Stored size: 443 Bytes

Contents

require 'msgpack'

module Miu
  class Message
    attr_accessor :tag, :time, :body

    def initialize(*args)
      @tag = args.shift
      @body = args.pop
      @time = args.shift || Time.now.to_i
    end

    def dump
      [@tag, @time, @body.to_msgpack].map(&:to_s)
    end

    def self.load(parts)
      tag = parts.shift
      time = parts.shift
      body = MessagePack.unpack(parts.shift)
      new tag, time, body
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
miu-0.0.6 lib/miu/message.rb
miu-0.0.5 lib/miu/message.rb