From b80cacbb045361c206afb904f0aad8d96f7bd060 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Fri, 24 Jul 2015 12:05:56 +0900 Subject: use String#bytesize instead of String#size --- lib/plum/binary_string.rb | 6 +++++- lib/plum/frame.rb | 2 +- lib/plum/hpack/huffman.rb | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/plum/binary_string.rb b/lib/plum/binary_string.rb index ef7733a..8011ea6 100644 --- a/lib/plum/binary_string.rb +++ b/lib/plum/binary_string.rb @@ -37,7 +37,11 @@ module Plum alias push << def shift(count) - slice!(0, count) + enc = self.encoding + force_encoding(Encoding::BINARY) + out = slice!(0, count) + force_encoding(enc) + out end end end diff --git a/lib/plum/frame.rb b/lib/plum/frame.rb index 7a17c1b..6d5f718 100644 --- a/lib/plum/frame.rb +++ b/lib/plum/frame.rb @@ -78,7 +78,7 @@ module Plum def initialize(length: nil, type: nil, type_value: nil, flags: nil, flags_value: nil, stream_id: nil, payload: nil) @payload = (payload || "").freeze - @length = length || @payload.size + @length = length || @payload.bytesize @type_value = type_value || FRAME_TYPES[type] or raise ArgumentError.new("type_value or type is necessary") @flags_value = flags_value || (flags && flags.map {|flag| FRAME_FLAGS[type][flag] }.inject(:|)) || 0 @stream_id = stream_id or raise ArgumentError.new("stream_id is necessary") diff --git a/lib/plum/hpack/huffman.rb b/lib/plum/hpack/huffman.rb index c4d8c53..b3db49e 100644 --- a/lib/plum/hpack/huffman.rb +++ b/lib/plum/hpack/huffman.rb @@ -11,7 +11,7 @@ module Plum bytestr.bytes.each do |b| out << HUFFMAN_TABLE[b] end - out << "1" * (8 - (out.size % 8)) + out << "1" * (8 - (out.bytesize % 8)) [out].pack("B*") end @@ -20,16 +20,16 @@ module Plum bits = encoded.unpack("B*")[0] buf = "" outl = [] - while (n = bits.shift(1)).size > 0 + while (n = bits.shift(1)).bytesize > 0 if c = HUFFMAN_DECODE_TABLE[buf << n] buf = "" outl << c end end - if buf.size > 7 + if buf.bytesize > 7 raise HPACKError.new("huffman: padding is too large (> 7 bits)") - elsif buf != "1" * buf.size + elsif buf != "1" * buf.bytesize raise HPACKError.new("huffman: unknown suffix: #{buf}") else outl.pack("C*") -- cgit v1.2.3