Class: Avro::Protocol::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/avro/protocol.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, request, response, errors = nil, names = nil, default_namespace = nil, doc = nil) ⇒ Message

Returns a new instance of Message.



119
120
121
122
123
124
125
126
# File 'lib/avro/protocol.rb', line 119

def initialize(name, request, response, errors=nil, names=nil, default_namespace=nil, doc=nil)
  @name = name
  @default_namespace = default_namespace
  @request = parse_request(request, names)
  @response = parse_response(response, names)
  @errors = parse_errors(errors, names) if errors
  @doc = doc
end

Instance Attribute Details

#default_namespaceObject (readonly)

Returns the value of attribute default_namespace.



117
118
119
# File 'lib/avro/protocol.rb', line 117

def default_namespace
  @default_namespace
end

#docObject (readonly)

Returns the value of attribute doc.



117
118
119
# File 'lib/avro/protocol.rb', line 117

def doc
  @doc
end

#errorsObject (readonly)

Returns the value of attribute errors.



117
118
119
# File 'lib/avro/protocol.rb', line 117

def errors
  @errors
end

#nameObject (readonly)

Returns the value of attribute name.



117
118
119
# File 'lib/avro/protocol.rb', line 117

def name
  @name
end

#requestObject (readonly)

Returns the value of attribute request.



117
118
119
# File 'lib/avro/protocol.rb', line 117

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



117
118
119
# File 'lib/avro/protocol.rb', line 117

def response
  @response
end

Instance Method Details

#parse_errors(errors, names) ⇒ Object



158
159
160
161
162
163
# File 'lib/avro/protocol.rb', line 158

def parse_errors(errors, names)
  unless errors.is_a?(Array)
    raise ProtocolParseError, "Errors property not an Array: #{errors}"
  end
  Schema.real_parse(errors, names, default_namespace)
end

#parse_request(request, names) ⇒ Object



142
143
144
145
146
147
# File 'lib/avro/protocol.rb', line 142

def parse_request(request, names)
  unless request.is_a?(Array)
    raise ProtocolParseError, "Request property not an Array: #{request.inspect}"
  end
  Schema::RecordSchema.new(nil, default_namespace, request, names, :request)
end

#parse_response(response, names) ⇒ Object



149
150
151
152
153
154
155
156
# File 'lib/avro/protocol.rb', line 149

def parse_response(response, names)
  if response.is_a?(String) && names
    fullname = Name.make_fullname(response, default_namespace)
    return names[fullname] if names.include?(fullname)
  end

  Schema.real_parse(response, names, default_namespace)
end

#to_avro(names = Set.new) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'lib/avro/protocol.rb', line 128

def to_avro(names=Set.new)
  {
    'request' => request.to_avro(names),
    'response' => response.to_avro(names)
  }.tap do |hash|
    hash['errors'] = errors.to_avro(names) if errors
    hash['doc'] = @doc if @doc
  end
end

#to_sObject



138
139
140
# File 'lib/avro/protocol.rb', line 138

def to_s
  Yajl.dump to_avro
end