Module: HTTP2::PackingExtensions

Included in:
Framer, Header::Compressor, Header::Huffman
Defined in:
lib/http/2/extensions.rb,
sig/extensions.rbs

Overview

this mixin handles backwards-compatibility for the new packing options shipping with ruby 3.3 (see https://docs.ruby-lang.org/en/3.3/packed_data_rdoc.html)

Instance Method Summary collapse

Instance Method Details

#pack(array_to_pack, template, buffer:, offset: -1)) ⇒ String

Parameters:

  • array_to_pack (Array[Integer | String])
  • template (String)
  • buffer: (String)
  • offset: (Integer) (defaults to: -1))

Returns:

  • (String)


60
61
62
63
64
65
66
67
68
69
70
# File 'lib/http/2/extensions.rb', line 60

def pack(array_to_pack, template, buffer:, offset: -1)
  packed_str = array_to_pack.pack(template)
  case offset
  when -1
    append_str(buffer, packed_str)
  when 0
    buffer.prepend(packed_str)
  else
    buffer.insert(offset, packed_str)
  end
end