Sha256: ef2e262142656ee07d7aa486328ddff4f26b111edae1bf48299d6c4a54a183f9

Contents?: true

Size: 685 Bytes

Versions: 1

Compression:

Stored size: 685 Bytes

Contents

module Aggro
  module Message
    # Public: Get events message.
    class Events < Struct.new(:id, :events)
      TYPE_CODE = '10'.freeze

      def self.parse(string)
        new string[2..37], parse_events(string[38..-1])
      end

      def self.parse_events(string)
        Enumerator.new do |yielder|
          MarshalStream.new(StringIO.new(string)).each do |raw_event|
            yielder << EventSerializer.deserialize(raw_event)
          end
        end
      end

      def serialize_events
        events.map { |event| Marshal.dump EventSerializer.serialize event }.join
      end

      def to_s
        "#{TYPE_CODE}#{id}#{serialize_events}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aggro-0.0.4 lib/aggro/message/events.rb