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
24 changes: 24 additions & 0 deletions lib/rb/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ Lint/AmbiguousRegexpLiteral:
Lint/OrderedMagicComments:
Enabled: true

Lint/RedundantStringCoercion:
Enabled: true

Lint/UnreachableCode:
Enabled: true

Expand Down Expand Up @@ -306,6 +309,27 @@ Style/HashSyntax:
Style/MethodDefParentheses:
Enabled: true

Style/RedundantAssignment:
Enabled: true

Style/RedundantException:
Enabled: true

Style/RedundantFreeze:
Enabled: true

Style/RedundantInterpolation:
Enabled: true

Style/RedundantParentheses:
Enabled: true

Style/RedundantSelf:
Enabled: true

Style/RedundantStringEscape:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/bytes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Bytes
# Returns a String with BINARY encoding, filled with null characters
# if size is greater than zero
def self.empty_byte_buffer(size = nil)
if (size && size > 0)
if size && size > 0
"\0".b * size
else
"".b
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/protocol/base_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def validate_container_size(size)
end

def to_s
"#{trans.to_s}"
trans.to_s
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/rb/lib/thrift/protocol/binary_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ def read_i64

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

def read_string
Expand All @@ -271,7 +270,7 @@ def read_uuid
end

def to_s
"binary(#{super.to_s})"
"binary(#{super})"
end

private
Expand Down
5 changes: 2 additions & 3 deletions lib/rb/lib/thrift/protocol/compact_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,7 @@ def read_i64

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

def read_string
Expand All @@ -436,7 +435,7 @@ def read_uuid
end

def to_s
"compact(#{super.to_s})"
"compact(#{super})"
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/protocol/header_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def read_uuid
end

def to_s
"header(#{@protocol.to_s})"
"header(#{@protocol})"
end

private
Expand Down
47 changes: 23 additions & 24 deletions lib/rb/lib/thrift/protocol/json_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def initialize
end

def write(trans)
if (@first)
if @first
@first = false
@colon = true
else
Expand All @@ -93,7 +93,7 @@ def write(trans)
end

def read(reader)
if (@first)
if @first
@first = false
@colon = true
else
Expand All @@ -116,15 +116,15 @@ def initialize
end

def write(trans)
if (@first)
if @first
@first = false
else
trans.write(@@kJSONElemSeparator)
end
end

def read(reader)
if (@first)
if @first
@first = false
else
JsonProtocol::read_syntax_char(reader, @@kJSONElemSeparator)
Expand Down Expand Up @@ -211,7 +211,7 @@ def get_type_id_for_type_name(name)
def self.read_syntax_char(reader, ch)
ch2 = reader.read
if (ch2 != ch)
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected \'#{ch}\' got \'#{ch2}\'.")
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected '#{ch}' got '#{ch2}'.")
end
end

Expand Down Expand Up @@ -307,11 +307,11 @@ def write_json_base64(str)
def write_json_integer(num)
@context.write(trans)
escapeNum = @context.escapeNum
if (escapeNum)
if escapeNum
trans.write(@@kJSONStringDelimiter)
end
trans.write(num.to_s);
if (escapeNum)
if escapeNum
trans.write(@@kJSONStringDelimiter)
end
end
Expand All @@ -322,10 +322,10 @@ def write_json_double(num)
@context.write(trans)
# Normalize output of thrift::to_string for NaNs and Infinities
special = false;
if (num.nan?)
if num.nan?
special = true;
val = @@kThriftNan;
elsif (num.infinite?)
elsif num.infinite?
special = true;
val = @@kThriftInfinity;
if (num < 0.0)
Expand All @@ -336,11 +336,11 @@ def write_json_double(num)
end

escapeNum = special || @context.escapeNum
if (escapeNum)
if escapeNum
trans.write(@@kJSONStringDelimiter)
end
trans.write(val)
if (escapeNum)
if escapeNum
trans.write(@@kJSONStringDelimiter)
end
end
Expand Down Expand Up @@ -502,22 +502,21 @@ def read_json_escape_char
# Decodes a JSON string, including unescaping, and returns the string via str
def read_json_string(skipContext = false)
# This string's characters must match up with the elements in escape_char_vals.
# I don't have '/' on this list even though it appears on www.json.org --
# it is not in the RFC -> it is. See RFC 4627
# JSON permits the optional solidus escape "\/"; see RFC 8259, section 7.
escape_chars = "\"\\/bfnrt"

# The elements of this array must match up with the sequence of characters in
# escape_chars
escape_char_vals = [
"\"", "\\", "\/", "\b", "\f", "\n", "\r", "\t",
"\"", "\\", "/", "\b", "\f", "\n", "\r", "\t",
]
Comment thread
kpumuk marked this conversation as resolved.

if !skipContext
@context.read(@reader)
end
read_json_syntax_char(@@kJSONStringDelimiter)
str = Bytes.empty_byte_buffer
while (true)
while true
ch = @reader.read
if (ch == @@kJSONStringDelimiter)
break
Expand All @@ -528,8 +527,8 @@ def read_json_string(skipContext = false)
ch = read_json_escape_char
else
pos = escape_chars.index(ch);
if (pos.nil?) # not found
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected control char, got \'#{ch}\'.")
if pos.nil? # not found
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected control char, got '#{ch}'.")
end
ch = escape_char_vals[pos]
end
Expand All @@ -556,9 +555,9 @@ def read_json_base64
# a valid JSON numeric character.
def read_json_numeric_chars
str = String.new(encoding: Encoding::UTF_8)
while (true)
while true
ch = @reader.peek
if (!is_json_numeric(ch))
if !is_json_numeric(ch)
break;
end
ch = @reader.read
Expand All @@ -571,7 +570,7 @@ def read_json_numeric_chars
# returning them via num
def read_json_integer
@context.read(@reader)
if (@context.escapeNum)
if @context.escapeNum
read_json_syntax_char(@@kJSONStringDelimiter)
end
str = read_json_numeric_chars
Expand All @@ -582,7 +581,7 @@ def read_json_integer
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected numeric value; got \"#{str}\"")
end

if (@context.escapeNum)
if @context.escapeNum
read_json_syntax_char(@@kJSONStringDelimiter)
end

Expand All @@ -603,7 +602,7 @@ def read_json_double
elsif (str == @@kThriftNegativeInfinity)
num = -1.0 / 0.0
else
if (!@context.escapeNum)
if !@context.escapeNum
# Raise exception -- we should not be in a string in this case
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Numeric data unexpectedly quoted")
end
Expand All @@ -614,7 +613,7 @@ def read_json_double
end
end
else
if (@context.escapeNum)
if @context.escapeNum
# This will throw - we should have had a quote if escapeNum == true
read_json_syntax_char(@@kJSONStringDelimiter)
end
Expand Down Expand Up @@ -781,7 +780,7 @@ def read_uuid
end

def to_s
"json(#{super.to_s})"
"json(#{super})"
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/server/base_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def serve
end

def to_s
"server(#{@protocol_factory.to_s}(#{@transport_factory.to_s}(#{@server_transport.to_s})))"
"server(#{@protocol_factory}(#{@transport_factory}(#{@server_transport})))"
end
end
end
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/server/simple_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def serve
end

def to_s
"simple(#{super.to_s})"
"simple(#{super})"
end
end
end
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/server/thread_pool_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def serve
end

def to_s
"threadpool(#{super.to_s})"
"threadpool(#{super})"
end
end
end
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/server/threaded_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def serve
end

def to_s
"threaded(#{super.to_s})"
"threaded(#{super})"
end
end
end
10 changes: 5 additions & 5 deletions lib/rb/lib/thrift/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def ==(other)
return false unless other.instance_of?(self.class)
each_field do |fid, field_info|
name = field_info[:name]
return false unless other.respond_to?(name) && self.send(name) == other.send(name)
return false unless other.respond_to?(name) && send(name) == other.send(name)
end
true
end
Expand All @@ -147,7 +147,7 @@ def hash
total = 17
each_field do |fid, field_info|
name = field_info[:name]
value = self.send(name)
value = send(name)
total = ((total * 37) + value.hash) & 0xffffffff
end
total
Expand All @@ -160,7 +160,7 @@ def differences(other)
else
each_field do |fid, field_info|
name = field_info[:name]
diffs << "#{name} differs!" unless self.instance_variable_get("@#{name}") == other.instance_variable_get("@#{name}")
diffs << "#{name} differs!" unless instance_variable_get("@#{name}") == other.instance_variable_get("@#{name}")
end
end
diffs
Expand All @@ -184,14 +184,14 @@ def self.generate_accessors(klass)

def self.qmark_isset_method(klass, field_info)
klass.send :define_method, "#{field_info[:name]}?" do
!self.send(field_info[:name].to_sym).nil?
!send(field_info[:name].to_sym).nil?
end
end

def <=>(other)
if self.class == other.class
each_field do |fid, field_info|
v1 = self.send(field_info[:name])
v1 = send(field_info[:name])
v1_set = !v1.nil?
v2 = other.send(field_info[:name])
v2_set = !v2.nil?
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 @@ -61,7 +61,7 @@ def read_field(iprot, field = {}, remaining_depth = DEFAULT_RECURSION_DEPTH)
key_type, val_type, size = iprot.read_map_begin
iprot.validate_container_size(size)
# Skip the map contents if the declared key or value types don't match the expected ones.
if (size != 0 && (key_type != field[:key][:type] || val_type != field[:value][:type]))
if size != 0 && (key_type != field[:key][:type] || val_type != field[:value][:type])
size.times do
iprot.skip(key_type)
iprot.skip(val_type)
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/transport/buffered_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def flush
end

def to_s
"buffered(#{@transport.to_s})"
"buffered(#{@transport})"
end
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 @@ -101,7 +101,7 @@ def flush
end

def to_s
"framed(#{@transport.to_s})"
"framed(#{@transport})"
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/transport/header_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def flush
end

def to_s
"header(#{@transport.to_s})"
"header(#{@transport})"
end

# Reads the next frame to detect protocol/client type before decoding.
Expand Down
Loading
Loading