Sha256: a8b5b85fd43abef4595073907d93feffde92549c53af0c3f445c1429b8040265

Contents?: true

Size: 909 Bytes

Versions: 2

Compression:

Stored size: 909 Bytes

Contents

require_relative 'handler'

module MaxCube
  module Messages
    module Parser
      include Handler

      def read(count = 0, unpack = false)
        str = if count.zero?
                @io.read
              else
                raise IOError if @io.size - @io.pos < count
                @io.read(count)
              end
        return str unless unpack
        str = "\x00".b + str if count == 3
        unpack = PACK_FORMAT[count] unless unpack.is_a?(String)
        str.unpack1(unpack)
      end

      def parse_msg_body(body, hash, parser_type_str)
        method_str = "parse_#{parser_type_str}_#{@msg_type.downcase}"
        if respond_to?(method_str, true)
          return hash.merge!(send(method_str, body))
        end
        hash[:data] = body
        nil
      rescue IOError
        raise InvalidMessageBody
          .new(@msg_type, 'unexpected EOF reached')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
maxcube-client-0.4.1 lib/maxcube/messages/parser.rb
maxcube-client-0.4.0 lib/maxcube/messages/parser.rb