Class: KafkaSyrup::Protocol::Base

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/kafka_syrup/protocol/base.rb

Direct Known Subclasses

Request, Response

Instance Method Summary collapse

Methods included from Utils

#load_args, #log

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

#configObject



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

#defaultsObject



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