lib/http/2/buffer.rb in http-2-0.11.0 vs lib/http/2/buffer.rb in http-2-0.12.0
- old
+ new
@@ -1,18 +1,20 @@
+# frozen_string_literal: true
+
require 'forwardable'
module HTTP2
# Binary buffer wraps String.
#
class Buffer
extend Forwardable
- def_delegators :@buffer, :ord, :encoding, :setbyte, :unpack,
+ def_delegators :@buffer, :ord, :encoding, :setbyte, :unpack, :unpack1,
:size, :each_byte, :to_str, :to_s, :length, :inspect,
:[], :[]=, :empty?, :bytesize, :include?
- UINT32 = 'N'.freeze
+ UINT32 = 'N'
private_constant :UINT32
# Forces binary encoding on the string
def initialize(str = '')
str = str.dup if str.frozen?
@@ -57,15 +59,15 @@
end
# Slice unsigned 32-bit integer from buffer.
# @return [Integer]
def read_uint32
- read(4).unpack(UINT32).first
+ read(4).unpack1(UINT32)
end
# Ensures that data that is added is binary encoded as well,
# otherwise this could lead to the Buffer instance changing its encoding.
- [:<<, :prepend].each do |mutating_method|
+ %i[<< prepend].each do |mutating_method|
define_method(mutating_method) do |string|
string = string.dup if string.frozen?
@buffer.send mutating_method, string.force_encoding(Encoding::BINARY)
self