class Poseidon::Protocol::RequestBuffer
RequestBuffer
allows you to build a Binary string for API requests
API parallels the primitive types described on the wiki, with some sugar for prepending message sizes and checksums. (cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-ProtocolPrimitiveTypes)
Public Class Methods
new()
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 9 def initialize @s = ''.encode(Encoding::BINARY) end
Public Instance Methods
append(string)
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 13 def append(string) string = string.dup.force_encoding(Encoding::BINARY) @s << string nil end
bytes(string)
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 47 def bytes(string) if string.nil? int32(-1) else int32(string.bytesize) append(string) end end
int16(int16)
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 23 def int16(int16) append([int16].pack("s>")) end
int32(int32)
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 27 def int32(int32) append([int32].pack("l>")) end
int64(int64)
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 31 def int64(int64) append([int64].pack("q>")) end
int8(int8)
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 19 def int8(int8) append([int8].pack("C")) end
prepend_crc32() { || ... }
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 56 def prepend_crc32 checksum_pos = @s.bytesize @s += " " yield @s[checksum_pos] = [Zlib::crc32(@s[(checksum_pos+1)..-1])].pack("N") nil end
prepend_size() { || ... }
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 64 def prepend_size size_pos = @s.bytesize @s += " " yield @s[size_pos] = [(@s.bytesize-1) - size_pos].pack("N") nil end
string(string)
click to toggle source
Add a string
@param [String] string
# File lib/poseidon/protocol/request_buffer.rb, line 38 def string(string) if string.nil? int16(-1) else int16(string.bytesize) append(string) end end
to_s()
click to toggle source
# File lib/poseidon/protocol/request_buffer.rb, line 72 def to_s @s end