lib/avro/protocol.rb in avro-1.3.0 vs lib/avro/protocol.rb in avro-1.3.3
- old
+ new
@@ -55,15 +55,15 @@
@messages = parse_messages(messages, type_names)
@md5 = Digest::MD5.digest(to_s)
end
def to_s
- Yajl.dump to_hash
+ Yajl.dump to_avro
end
def ==(other)
- to_hash == Yajl.load(other.to_s)
+ to_avro == other.to_avro
end
private
def parse_types(types, type_names)
type_objects = []
@@ -94,17 +94,18 @@
message_objects[name] = Message.new(name, request, response, errors, names)
end
message_objects
end
- def to_hash
+ protected
+ def to_avro
hsh = {'protocol' => name}
hsh['namespace'] = namespace if namespace
- hsh['types'] = types.map{|t| Yajl.load(t.to_s) } if types
+ hsh['types'] = types.map{|t| t.to_avro } if types
if messages
- hsh['messages'] = messages.collect_hash{|k,t| [k, Yajl.load(t.to_s)] }
+ hsh['messages'] = messages.collect_hash{|k,t| [k, t.to_avro] }
end
hsh
end
@@ -117,21 +118,25 @@
@request = parse_request(request, names)
@response = parse_response(response, names)
@errors = parse_errors(errors, names) if errors
end
- def to_s
- hsh = {'request' => Yajl.load(request.to_s)}
+ def to_avro
+ hsh = {'request' => request.to_avro}
if response_from_names
hsh['response'] = response.fullname
else
- hsh['response'] = Yajl.load(response.to_s)
+ hsh['response'] = response.to_avro
end
if errors
- hsh['errors'] = Yajl.load(errors.to_s)
+ hsh['errors'] = errors.to_avro
end
- Yajl.dump hsh
+ hsh
+ end
+
+ def to_s
+ Yajl.dump to_avro
end
def parse_request(request, names)
unless request.is_a?(Array)
raise ProtocolParseError, "Request property not an Array: #{request.inspect}"