Sha256: 22c13c204f0f331487150ec1b1d3171649d0796e28a57869737f1ea13d5ab146
Contents?: true
Size: 1.1 KB
Versions: 6
Compression:
Stored size: 1.1 KB
Contents
require "stringio" require "zlib" module Kafka module Protocol # ## API Specification # # Message => Crc MagicByte Attributes Key Value # Crc => int32 # MagicByte => int8 # Attributes => int8 # Key => bytes # Value => bytes # class Message MAGIC_BYTE = 0 attr_reader :key, :value, :attributes def initialize(key:, value:, attributes: 0) @key = key @value = value @attributes = attributes end def encode(encoder) data = encode_without_crc crc = Zlib.crc32(data) encoder.write_int32(crc) encoder.write(data) end def ==(other) @key == other.key && @value == other.value && @attributes == other.attributes end private def encode_without_crc buffer = StringIO.new encoder = Encoder.new(buffer) encoder.write_int8(MAGIC_BYTE) encoder.write_int8(@attributes) encoder.write_bytes(@key) encoder.write_bytes(@value) buffer.string end end end end
Version data entries
6 entries across 6 versions & 1 rubygems