Class: Kafka::Protocol::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/protocol/message.rb

Overview

API Specification

Message => Crc MagicByte Attributes Key Value
    Crc => int32
    MagicByte => int8
    Attributes => int8
    Key => bytes
    Value => bytes

Constant Summary collapse

MAGIC_BYTE =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, value:, attributes: 0) ⇒ Message

Returns a new instance of Message.



21
22
23
24
25
# File 'lib/kafka/protocol/message.rb', line 21

def initialize(key:, value:, attributes: 0)
  @key = key
  @value = value
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



19
20
21
# File 'lib/kafka/protocol/message.rb', line 19

def attributes
  @attributes
end

#keyObject (readonly)

Returns the value of attribute key.



19
20
21
# File 'lib/kafka/protocol/message.rb', line 19

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



19
20
21
# File 'lib/kafka/protocol/message.rb', line 19

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
# File 'lib/kafka/protocol/message.rb', line 35

def ==(other)
  @key == other.key && @value == other.value && @attributes == other.attributes
end

#encode(encoder) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/kafka/protocol/message.rb', line 27

def encode(encoder)
  data = encode_without_crc
  crc = Zlib.crc32(data)

  encoder.write_int32(crc)
  encoder.write(data)
end