Class: KafkaSyrup::Protocol::Base
- Inherits:
-
Object
- Object
- KafkaSyrup::Protocol::Base
- Includes:
- Utils
- Defined in:
- lib/kafka_syrup/protocol/base.rb
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #config ⇒ Object
- #decode(io) ⇒ Object
- #defaults ⇒ Object
- #encode(&block) ⇒ Object
-
#initialize(*args, &block) ⇒ Base
constructor
A new instance of Base.
Methods included from Utils
Constructor Details
#initialize(*args, &block) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 |
# File 'lib/kafka_syrup/protocol/base.rb', line 6 def initialize(*args, &block) if(io = args.first).respond_to?(:read) decode(io, &block) else load_args(defaults) load_args(*args) end end |
Instance Method Details
#==(obj) ⇒ Object
36 37 38 |
# File 'lib/kafka_syrup/protocol/base.rb', line 36 def ==(obj) obj.encode.bytes == encode.bytes end |
#config ⇒ Object
19 20 21 |
# File 'lib/kafka_syrup/protocol/base.rb', line 19 def config @config ||= ::KafkaSyrup.config end |
#decode(io) ⇒ Object
32 33 34 |
# File 'lib/kafka_syrup/protocol/base.rb', line 32 def decode(io) E.read_int32(io) # Total length (ignored) end |
#defaults ⇒ Object
15 16 17 |
# File 'lib/kafka_syrup/protocol/base.rb', line 15 def defaults {} end |
#encode(&block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/kafka_syrup/protocol/base.rb', line 23 def encode(&block) encoded = block_given? ? yield : "" [ E.write_int32(encoded.length), encoded ].join end |