Class: Avro::Protocol::Message
- Inherits:
-
Object
- Object
- Avro::Protocol::Message
- Defined in:
- lib/avro/protocol.rb
Instance Attribute Summary collapse
-
#default_namespace ⇒ Object
readonly
Returns the value of attribute default_namespace.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(name, request, response, errors = nil, names = nil, default_namespace = nil, doc = nil) ⇒ Message
constructor
A new instance of Message.
- #parse_errors(errors, names) ⇒ Object
- #parse_request(request, names) ⇒ Object
- #parse_response(response, names) ⇒ Object
- #to_avro(names = Set.new) ⇒ Object
- #to_s ⇒ Object
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_namespace ⇒ Object (readonly)
Returns the value of attribute default_namespace.
117 118 119 |
# File 'lib/avro/protocol.rb', line 117 def default_namespace @default_namespace end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
117 118 119 |
# File 'lib/avro/protocol.rb', line 117 def doc @doc end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
117 118 119 |
# File 'lib/avro/protocol.rb', line 117 def errors @errors end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
117 118 119 |
# File 'lib/avro/protocol.rb', line 117 def name @name end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
117 118 119 |
# File 'lib/avro/protocol.rb', line 117 def request @request end |
#response ⇒ Object (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_s ⇒ Object
138 139 140 |
# File 'lib/avro/protocol.rb', line 138 def to_s Yajl.dump to_avro end |