Class: KafkaSyrup::Protocol::FetchResponse::Partition

Inherits:
Struct
  • Object
show all
Defined in:
lib/kafka_syrup/protocol/fetch_response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



50
51
52
# File 'lib/kafka_syrup/protocol/fetch_response.rb', line 50

def code
  @code
end

#highwater_offsetObject

Returns the value of attribute highwater_offset

Returns:

  • (Object)

    the current value of highwater_offset



50
51
52
# File 'lib/kafka_syrup/protocol/fetch_response.rb', line 50

def highwater_offset
  @highwater_offset
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



50
51
52
# File 'lib/kafka_syrup/protocol/fetch_response.rb', line 50

def id
  @id
end

#message_setObject

Returns the value of attribute message_set

Returns:

  • (Object)

    the current value of message_set



50
51
52
# File 'lib/kafka_syrup/protocol/fetch_response.rb', line 50

def message_set
  @message_set
end

Class Method Details

.decode(io, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/kafka_syrup/protocol/fetch_response.rb', line 72

def self.decode(io, &block)
  partition = new
  partition.id = E.read_int32(io)
  partition.code = E.read_int16(io)
  partition.highwater_offset = E.read_int64(io)
  length = E.read_int32(io)
  partition.message_set = MessageSet.new(io, length, &block)
  partition
end

Instance Method Details

#add_message(value = nil, opts = {}) ⇒ Object



55
56
57
58
59
# File 'lib/kafka_syrup/protocol/fetch_response.rb', line 55

def add_message(value = nil, opts = {})
  m = Message.new(opts.merge(value: value))
  message_set.messages << m
  m
end

#encodeObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/kafka_syrup/protocol/fetch_response.rb', line 61

def encode
  encoded = message_set.encode
  [
    E.write_int32(id),
    E.write_int16(code),
    E.write_int64(highwater_offset),
    E.write_int32(encoded.length),
    encoded
  ].join
end

#messagesObject



51
52
53
# File 'lib/kafka_syrup/protocol/fetch_response.rb', line 51

def messages
  message_set.messages
end