module SubZero::Message::Parser::ClassMethods

Public Instance Methods

from_source(source) click to toggle source
# File lib/sub_zero/message/parser.rb, line 31
def from_source source
  type = source.shift

  if type.index ':'
    type, subtype = type.split(':')
  end

  rid  = source.shift
  verb = source.shift

  if verb.index ':'
    verb, status = verb.split(':')
  end

  payload = MessagePack.unpack(source.shift).with_indifferent_access

  unless source.empty?
    routing_info = MessagePack.unpack(source.shift).with_indifferent_access
  end

  new type: type, rid: rid, verb: verb, payload: payload,
      subtype: subtype, status: status, routing_info: routing_info
end
parse(source, request = nil) click to toggle source
# File lib/sub_zero/message/parser.rb, line 55
def parse source, request = nil
  from_source(source).tap do |m|
    m.validate_response!(request) if request
  end
end