Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,6 @@ Style/TrailingCommaInArrayLiteral:
Style/TrailingCommaInHashLiteral:
Enabled: true
EnforcedStyleForMultiline: comma

Style/UnpackFirst:
Enabled: true
6 changes: 3 additions & 3 deletions lib/rb/lib/thrift/protocol/binary_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def read_byte

def read_i16
trans.read_into_buffer(@rbuf, 2)
val, = @rbuf.unpack("n")
val = @rbuf.unpack1("n")
if (val > 0x7fff)
val = 0 - ((val - 1) ^ 0xffff)
end
Expand All @@ -223,7 +223,7 @@ def read_i16

def read_i32
trans.read_into_buffer(@rbuf, 4)
val, = @rbuf.unpack("N")
val = @rbuf.unpack1("N")
if (val > 0x7fffffff)
val = 0 - ((val - 1) ^ 0xffffffff)
end
Expand All @@ -244,7 +244,7 @@ def read_i64

def read_double
trans.read_into_buffer(@rbuf, 8)
val = @rbuf.unpack("G").first
val = @rbuf.unpack1("G")
val
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rb/lib/thrift/protocol/compact_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

module Thrift
class CompactProtocol < BaseProtocol
PROTOCOL_ID = [0x82].pack("c").unpack("c").first
PROTOCOL_ID = [0x82].pack("c").unpack1("c")
VERSION = 1
VERSION_MASK = 0x1f
TYPE_MASK = 0xE0
Expand Down Expand Up @@ -410,7 +410,7 @@ def read_i64

def read_double
trans.read_into_buffer(@rbuf, 8)
val = @rbuf.reverse.unpack("G").first
val = @rbuf.reverse.unpack1("G")
val
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/server/nonblocking_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def close_signal_pipes

def slice_frame!(buf)
if buf.length >= 4
size = buf.unpack("N").first
size = buf.unpack1("N")
if buf.length >= size + 4
buf.slice!(0, size + 4)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/struct_union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def inspect_field(value, field_info)
elsif value.is_a? Set
inspect_collection(value, field_info)
elsif value.is_a?(String) && field_info[:binary]
value.unpack("H*").first
value.unpack1("H*")
else
value.inspect
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/transport/framed_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def to_s
private

def read_frame
sz = @transport.read_all(4).unpack("N").first
sz = @transport.read_all(4).unpack1("N")

@index = 0
@rbuf = @transport.read_all(sz)
Expand Down
12 changes: 6 additions & 6 deletions lib/rb/lib/thrift/transport/header_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def read_frame(req_sz)
rescue EOFError
raise TransportException.new(TransportException::END_OF_FILE, "Unexpected EOF reading frame size")
end
frame_size = first_word.unpack("N").first
frame_size = first_word.unpack1("N")

# Check for unframed binary protocol
if (frame_size & BINARY_VERSION_MASK) == BINARY_VERSION_1
Expand Down Expand Up @@ -324,15 +324,15 @@ def read_frame(req_sz)
second_word = frame_buf.read(4)
frame_buf.rewind

magic = second_word.unpack("n").first
magic = second_word.unpack1("n")

if magic == HEADER_MAGIC
if frame_size < 10
raise TransportException.new(TransportException::UNKNOWN, "Header transport frame is too small")
end
set_client_type(HeaderClientType::HEADERS)
@read_buffer = parse_header_format(frame_buf)
elsif (second_word.unpack("N").first & BINARY_VERSION_MASK) == BINARY_VERSION_1
elsif (second_word.unpack1("N") & BINARY_VERSION_MASK) == BINARY_VERSION_1
set_client_type(HeaderClientType::FRAMED_BINARY)
@protocol_id = HeaderSubprotocolID::BINARY
@read_buffer = frame_buf
Expand Down Expand Up @@ -382,11 +382,11 @@ def parse_header_format(buf)
buf.read(2)

# Read flags and sequence ID
@flags = buf.read(2).unpack("n").first
@sequence_id = signed_int32(buf.read(4).unpack("N").first)
@flags = buf.read(2).unpack1("n")
@sequence_id = signed_int32(buf.read(4).unpack1("N"))

# Read header length (in 32-bit words)
header_words = buf.read(2).unpack("n").first
header_words = buf.read(2).unpack1("n")
if header_words >= 16_384
raise TransportException.new(TransportException::UNKNOWN, "Header size is unreasonable")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/uuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def self.uuid_from_bytes(bytes)
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Invalid UUID data length")
end

hex = bytes.unpack("H*").first
hex = bytes.unpack1("H*")
"#{hex[0, 8]}-#{hex[8, 4]}-#{hex[12, 4]}-#{hex[16, 4]}-#{hex[20, 12]}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/spec/header_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
@protocol.trans.flush

data = @buffer.read(@buffer.available)
expect(data[8, 4].unpack("N").first).to eq(123)
expect(data[8, 4].unpack1("N")).to eq(123)
end

it "should write and read structs" do
Expand Down
6 changes: 3 additions & 3 deletions lib/rb/spec/header_transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def read_unframed_message(protocol)
expect(data.bytesize).to be > 16

# First 4 bytes are frame length
frame_size = data[0, 4].unpack("N").first
frame_size = data[0, 4].unpack1("N")
expect(frame_size).to eq(data.bytesize - 4)

# Next 2 bytes should be header magic
magic = data[4, 2].unpack("n").first
magic = data[4, 2].unpack1("n")
expect(magic).to eq(Thrift::HeaderTransport::HEADER_MAGIC)
end

Expand All @@ -175,7 +175,7 @@ def read_unframed_message(protocol)
@trans.flush

data = @underlying.read(@underlying.available)
expect(data[8, 4].unpack("N").first).to eq(456)
expect(data[8, 4].unpack1("N")).to eq(456)
end

it "should apply ZLIB transform" do
Expand Down
Loading