module RedisClient::RESP3

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/redis_client/ruby_connection/resp3.rbs

module RedisClient::RESP3
  def dump: (Array[String] command, ?String? buffer) -> untyped
  def dump_any: (String object, String buffer) -> untyped
  def dump_array: (Array[String] array, String buffer) -> untyped
  def dump_string: (String string, String buffer) -> untyped
  def load: (RedisClient::RubyConnection::BufferedIO io) -> untyped
  def new_buffer: () -> untyped
  def parse: (RedisClient::RubyConnection::BufferedIO io) -> untyped
  def parse_blob: (RedisClient::RubyConnection::BufferedIO io) -> untyped
  def parse_double: (RedisClient::RubyConnection::BufferedIO io) -> untyped
  def parse_integer: (RedisClient::RubyConnection::BufferedIO io) -> untyped
  def parse_null: (RedisClient::RubyConnection::BufferedIO io) -> untyped
  def parse_sequence: (RedisClient::RubyConnection::BufferedIO io, Integer size) -> untyped
end

def dump(command, buffer = nil)

Experimental RBS support (using type sampling data from the type_fusion project).

def dump: (String command, ?String? buffer) -> untyped

This signature was generated using 2 samples from 1 application.

def dump(command, buffer = nil)
  buffer ||= new_buffer
  command = command.flat_map do |element|
    case element
    when Hash
      element.flatten
    else
      element
    end
  end
  dump_array(command, buffer)
end

def dump_any(object, buffer)

Experimental RBS support (using type sampling data from the type_fusion project).

def dump_any: (String object, String buffer) -> untyped

This signature was generated using 4 samples from 1 application.

def dump_any(object, buffer)
  method = DUMP_TYPES.fetch(object.class) do |unexpected_class|
    if superclass = DUMP_TYPES.keys.find { |t| t > unexpected_class }
      DUMP_TYPES[unexpected_class] = DUMP_TYPES[superclass]
    else
      raise TypeError, "Unsupported command argument type: #{unexpected_class}"
    end
  end
  send(method, object, buffer)
end

def dump_array(array, buffer)

Experimental RBS support (using type sampling data from the type_fusion project).

def dump_array: ((String | String | String) array, String buffer) -> untyped

This signature was generated using 2 samples from 1 application.

def dump_array(array, buffer)
  buffer << '*' << array.size.to_s << EOL
  array.each do |item|
    dump_any(item, buffer)
  end
  buffer
end

def dump_hash(hash, buffer)

def dump_hash(hash, buffer)
  buffer << '%' << hash.size.to_s << EOL
  hash.each_pair do |key, value|
    dump_any(key, buffer)
    dump_any(value, buffer)
  end
  buffer
end

def dump_numeric(numeric, buffer)

def dump_numeric(numeric, buffer)
  dump_string(numeric.to_s, buffer)
end

def dump_set(set, buffer)

def dump_set(set, buffer)
  buffer << '~' << set.size.to_s << EOL
  set.each do |item|
    dump_any(item, buffer)
  end
  buffer
end

def dump_string(string, buffer)

Experimental RBS support (using type sampling data from the type_fusion project).

def dump_string: (String string, String buffer) -> untyped

This signature was generated using 1 sample from 1 application.

def dump_string(string, buffer)
  string = string.b unless string.ascii_only?
  buffer << '$' << string.bytesize.to_s << EOL << string << EOL
end

def dump_symbol(symbol, buffer)

def dump_symbol(symbol, buffer)
  dump_string(symbol.name, buffer)
end

def dump_symbol(symbol, buffer)

def dump_symbol(symbol, buffer)
  dump_string(symbol.to_s, buffer)
end

def load(io)

Experimental RBS support (using type sampling data from the type_fusion project).

def load: (RedisClient::RubyConnection::BufferedIO io) -> untyped

This signature was generated using 1 sample from 1 application.

def load(io)
  parse(io)
end

def new_buffer

Experimental RBS support (using type sampling data from the type_fusion project).

def new_buffer: () -> untyped

This signature was generated using 1 sample from 1 application.

def new_buffer
  String.new(encoding: Encoding::BINARY, capacity: 127)
end

def parse(io)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse: (RedisClient::RubyConnection::BufferedIO io) -> untyped

This signature was generated using 4 samples from 1 application.

def parse(io)
  type = io.getbyte
  method = PARSER_TYPES.fetch(type) do
    raise UnknownType, "Unknown sigil type: #{type.chr.inspect}"
  end
  send(method, io)
end

def parse_array(io)

def parse_array(io)
  parse_sequence(io, parse_integer(io))
end

def parse_blob(io)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse_blob: (RedisClient::RubyConnection::BufferedIO io) -> untyped

This signature was generated using 1 sample from 1 application.

def parse_blob(io)
  bytesize = parse_integer(io)
  return if bytesize < 0 # RESP2 nil type
  str = io.read_chomp(bytesize)
  str.force_encoding(Encoding.default_external)
  str.force_encoding(Encoding::BINARY) unless str.valid_encoding?
  str
end

def parse_boolean(io)

def parse_boolean(io)
  case value = io.gets_chomp
  when "t"
    true
  when "f"
    false
  else
    raise SyntaxError, "Expected `t` or `f` after `#`, got: #{value}"
  end
end

def parse_double(io)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse_double: (RedisClient::RubyConnection::BufferedIO io) -> untyped

This signature was generated using 1 sample from 1 application.

def parse_double(io)
  case value = io.gets_chomp
  when "inf"
    Float::INFINITY
  when "-inf"
    -Float::INFINITY
  else
    Float(value)
  end
end

def parse_error(io)

def parse_error(io)
  CommandError.parse(parse_string(io))
end

def parse_integer(io)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse_integer: (RedisClient::RubyConnection::BufferedIO io) -> untyped

This signature was generated using 5 samples from 1 application.

def parse_integer(io)
  Integer(io.gets_chomp)
end

def parse_map(io)

def parse_map(io)
  hash = {}
  parse_integer(io).times do
    hash[parse(io)] = parse(io)
  end
  hash
end

def parse_null(io)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse_null: (RedisClient::RubyConnection::BufferedIO io) -> untyped

This signature was generated using 1 sample from 1 application.

def parse_null(io)
  io.skip(EOL_SIZE)
  nil
end

def parse_push(io)

def parse_push(io)
  parse_array(io)
end

def parse_sequence(io, size)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse_sequence: (RedisClient::RubyConnection::BufferedIO io, Integer size) -> untyped

This signature was generated using 2 samples from 1 application.

def parse_sequence(io, size)
  return if size < 0 # RESP2 nil
  array = Array.new(size)
  size.times do |index|
    array[index] = parse(io)
  end
  array
end

def parse_set(io)

def parse_set(io)
  parse_sequence(io, parse_integer(io))
end

def parse_string(io)

def parse_string(io)
  str = io.gets_chomp
  str.force_encoding(Encoding.default_external)
  str.force_encoding(Encoding::BINARY) unless str.valid_encoding?
  str.freeze
end

def parse_verbatim_string(io)

def parse_verbatim_string(io)
  blob = parse_blob(io)
  blob.byteslice(4..-1)
end