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
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#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, doc = nil) ⇒ Protocol
constructor
A new instance of Protocol.
- #to_s ⇒ Object
Constructor Details
#initialize(name, namespace = nil, types = nil, messages = nil, doc = nil) ⇒ Protocol
Returns a new instance of Protocol.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/avro/protocol.rb', line 40 def initialize(name, namespace=nil, types=nil, =nil, doc=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) @doc = doc end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
24 25 26 |
# File 'lib/avro/protocol.rb', line 24 def doc @doc end |
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
24 25 26 |
# File 'lib/avro/protocol.rb', line 24 def md5 @md5 end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
24 25 26 |
# File 'lib/avro/protocol.rb', line 24 def @messages end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/avro/protocol.rb', line 24 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
24 25 26 |
# File 'lib/avro/protocol.rb', line 24 def namespace @namespace end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
24 25 26 |
# File 'lib/avro/protocol.rb', line 24 def types @types end |
Class Method Details
.parse(protocol_string) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/avro/protocol.rb', line 25 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'] doc = json_data['doc'] Protocol.new(name, namespace, types, , doc) else raise ProtocolParseError, "Not a JSON object: #{json_data}" end end |
Instance Method Details
#==(other) ⇒ Object
67 68 69 |
# File 'lib/avro/protocol.rb', line 67 def ==(other) to_avro == other.to_avro end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/avro/protocol.rb', line 63 def to_s MultiJson.dump to_avro end |