Class: Avro::Protocol
- Inherits:
-
Object
- Object
- Avro::Protocol
- Defined in:
- lib/avro/protocol.rb
Defined Under Namespace
Classes: Message, ProtocolParseError
Constant Summary collapse
- VALID_TYPE_SCHEMA_TYPES =
Set.new(%w[enum record error fixed])
- VALID_TYPE_SCHEMA_TYPES_SYM =
Set.new(VALID_TYPE_SCHEMA_TYPES.map(&:to_sym))
Instance Attribute Summary collapse
-
#md5 ⇒ Object
readonly
Returns the value of attribute md5.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, namespace = nil, types = nil, messages = nil) ⇒ Protocol
constructor
A new instance of Protocol.
- #to_s ⇒ Object
Constructor Details
#initialize(name, namespace = nil, types = nil, messages = nil) ⇒ Protocol
Returns a new instance of Protocol.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/avro/protocol.rb', line 38 def initialize(name, namespace=nil, types=nil, =nil) # Ensure valid ctor args if !name raise ProtocolParseError, 'Protocols must have a non-empty name.' elsif !name.is_a?(String) raise ProtocolParseError, 'The name property must be a string.' elsif !namespace.is_a?(String) raise ProtocolParseError, 'The namespace property must be a string.' elsif !types.is_a?(Array) raise ProtocolParseError, 'The types property must be a list.' elsif !.is_a?(Hash) raise ProtocolParseError, 'The messages property must be a JSON object.' end @name = name @namespace = namespace type_names = {} @types = parse_types(types, type_names) @messages = (, type_names) @md5 = Digest::MD5.digest(to_s) end |
Instance Attribute Details
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
23 24 25 |
# File 'lib/avro/protocol.rb', line 23 def md5 @md5 end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
23 24 25 |
# File 'lib/avro/protocol.rb', line 23 def @messages end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/avro/protocol.rb', line 23 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
23 24 25 |
# File 'lib/avro/protocol.rb', line 23 def namespace @namespace end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
23 24 25 |
# File 'lib/avro/protocol.rb', line 23 def types @types end |
Class Method Details
.parse(protocol_string) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/avro/protocol.rb', line 24 def self.parse(protocol_string) json_data = MultiJson.load(protocol_string) if json_data.is_a? Hash name = json_data['protocol'] namespace = json_data['namespace'] types = json_data['types'] = json_data['messages'] Protocol.new(name, namespace, types, ) else raise ProtocolParseError, "Not a JSON object: #{json_data}" end end |
Instance Method Details
#==(other) ⇒ Object
64 65 66 |
# File 'lib/avro/protocol.rb', line 64 def ==(other) to_avro == other.to_avro end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/avro/protocol.rb', line 60 def to_s MultiJson.dump to_avro end |