Sha256: c70993bf004a7e289cb96da7fec503a3585a6f73e2d11ca0295e2b368ca13b8e

Contents?: true

Size: 959 Bytes

Versions: 1

Compression:

Stored size: 959 Bytes

Contents

module Kafka
  module Protocol
    class Encoder
      def initialize(io)
        @io = io
        @io.set_encoding(Encoding::BINARY)
      end

      def write(bytes)
        @io.write(bytes)
      end

      def write_int8(int)
        write([int].pack("C"))
      end

      def write_int16(int)
        write([int].pack("s>"))
      end

      def write_int32(int)
        write([int].pack("l>"))
      end

      def write_int64(int)
        write([int].pack("q>"))
      end

      def write_array(array, &block)
        write_int32(array.size)
        array.each(&block)
      end

      def write_string(string)
        if string.nil?
          write_int16(-1)
        else
          write_int16(string.bytesize)
          write(string)
        end
      end

      def write_bytes(bytes)
        if bytes.nil?
          write_int32(-1)
        else
          write_int32(bytes.bytesize)
          write(bytes)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-kafka-0.1.0.pre.alpha lib/kafka/protocol/encoder.rb