Sha256: 9ec1f8a5dde0bcc8d83480c66783b602da8c4901954279431919449fb68b0afd

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module Rdkafka
  class Admin
    class DescribeConfigsReport
      attr_reader :resources

      def initialize(config_entries:, entry_count:)
        @resources=[]

        return if config_entries == FFI::Pointer::NULL

        config_entries
          .read_array_of_pointer(entry_count)
          .each { |config_resource_result_ptr| validate!(config_resource_result_ptr) }
          .each do |config_resource_result_ptr|
            config_resource_result = ConfigResourceBindingResult.new(config_resource_result_ptr)

            pointer_to_size_t = FFI::MemoryPointer.new(:int32)
            configs_ptr = Bindings.rd_kafka_ConfigResource_configs(
              config_resource_result_ptr,
              pointer_to_size_t
            )

            configs_ptr
              .read_array_of_pointer(pointer_to_size_t.read_int)
              .map { |config_ptr| ConfigBindingResult.new(config_ptr) }
              .each { |config_binding| config_resource_result.configs << config_binding }

            @resources << config_resource_result
          end
      ensure
        return if config_entries == FFI::Pointer::NULL

        Bindings.rd_kafka_ConfigResource_destroy_array(config_entries, entry_count)
      end

      private

      def validate!(config_resource_result_ptr)
        code = Bindings.rd_kafka_ConfigResource_error(config_resource_result_ptr)

        return if code.zero?

        raise(
          RdkafkaError.new(
            code,
            Bindings.rd_kafka_ConfigResource_error_string(config_resource_result_ptr)
          )
        )
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rdkafka-0.20.0 lib/rdkafka/admin/describe_configs_report.rb
rdkafka-0.19.0 lib/rdkafka/admin/describe_configs_report.rb
rdkafka-0.18.0 lib/rdkafka/admin/describe_configs_report.rb
rdkafka-0.17.0 lib/rdkafka/admin/describe_configs_report.rb
rdkafka-0.16.1 lib/rdkafka/admin/describe_configs_report.rb
rdkafka-0.16.0 lib/rdkafka/admin/describe_configs_report.rb