Class: Kafka::Message
- Inherits:
-
Object
- Object
- Kafka::Message
- Defined in:
- lib/kafka/message.rb
Overview
A message. The format of an N byte message is the following: 1 byte “magic” identifier to allow format changes 4 byte CRC32 of the payload N - 5 byte payload
Constant Summary collapse
- MAGIC_IDENTIFIER_DEFAULT =
0
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#magic ⇒ Object
Returns the value of attribute magic.
-
#payload ⇒ Object
Returns the value of attribute payload.
Instance Method Summary collapse
- #calculate_checksum ⇒ Object
-
#initialize(payload = nil, magic = MAGIC_IDENTIFIER_DEFAULT) ⇒ Message
constructor
A new instance of Message.
- #valid? ⇒ Boolean
Constructor Details
#initialize(payload = nil, magic = MAGIC_IDENTIFIER_DEFAULT) ⇒ Message
Returns a new instance of Message.
11 12 13 14 15 |
# File 'lib/kafka/message.rb', line 11 def initialize(payload = nil, magic = MAGIC_IDENTIFIER_DEFAULT) self.magic = magic self.payload = payload self.checksum = self.calculate_checksum end |
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum.
9 10 11 |
# File 'lib/kafka/message.rb', line 9 def checksum @checksum end |
#magic ⇒ Object
Returns the value of attribute magic.
9 10 11 |
# File 'lib/kafka/message.rb', line 9 def magic @magic end |
#payload ⇒ Object
Returns the value of attribute payload.
9 10 11 |
# File 'lib/kafka/message.rb', line 9 def payload @payload end |
Instance Method Details
#calculate_checksum ⇒ Object
17 18 19 |
# File 'lib/kafka/message.rb', line 17 def calculate_checksum Zlib.crc32(self.payload) end |
#valid? ⇒ Boolean
21 22 23 |
# File 'lib/kafka/message.rb', line 21 def valid? self.checksum == Zlib.crc32(self.payload) end |