Skip to content

Commit e25e95e

Browse files
committed
Removed base64 and added logger as an explicit add_dependency
Starting with Ruby 3.4, base64 is no longer a bundled gem, and now Thrift does not load in modern Ruby versions: An error occurred while loading ./spec/types_spec.rb. Failure/Error: require 'base64' LoadError: cannot load such file -- base64 # ./lib/thrift/protocol/json_protocol.rb:21:in '<top (required)>' # ./lib/thrift.rb:45:in '<top (required)>' # ./spec/spec_helper.rb:30:in '<top (required)>' # ./spec/types_spec.rb:20:in '<top (required)>' Ruby already has ability to serialize and deserialize base64 without requiring the base64 gem, which is a thin wrapper for syntactic sugar. Additionally, the code throws a warning at the moment, which will become an error in Ruby 3.5: /code/lib/thrift/processor.rb:20: warning: logger was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0. You can add logger to your Gemfile or gemspec to silence this warning. Added logger as an explicit dependency to avoid this warning.
1 parent 10d5a65 commit e25e95e

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/rb/lib/thrift/protocol/json_protocol.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
# KIND, either express or implied. See the License for the
1717
# specific language governing permissions and limitations
1818
# under the License.
19-
#
20-
21-
require 'base64'
19+
#
2220

2321
module Thrift
2422
class LookaheadReader
@@ -311,7 +309,7 @@ def write_json_string(str)
311309
def write_json_base64(str)
312310
@context.write(trans)
313311
trans.write(@@kJSONStringDelimiter)
314-
trans.write(Base64.strict_encode64(str))
312+
trans.write([str].pack('m0'))
315313
trans.write(@@kJSONStringDelimiter)
316314
end
317315

@@ -555,7 +553,7 @@ def read_json_base64
555553
str += '='
556554
end
557555
end
558-
Base64.strict_decode64(str)
556+
str.unpack1('m0')
559557
end
560558

561559
# Reads a sequence of characters, stopping at the first one that is not

lib/rb/thrift.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ Gem::Specification.new do |s|
2626

2727
s.require_paths = %w[lib ext]
2828

29+
s.add_dependency 'logger'
30+
2931
s.add_development_dependency 'bundler', '>= 1.11'
3032
s.add_development_dependency 'pry', '~> 0.11.3'
3133
s.add_development_dependency 'pry-byebug', '~> 3.6'
3234
s.add_development_dependency 'pry-stack_explorer', '~> 0.4.9.2'
3335
s.add_development_dependency 'rack', '= 2.2.6.4'
3436
s.add_development_dependency 'rack-test', '~> 0.8.3'
35-
s.add_development_dependency 'rake', '~> 12.3'
37+
s.add_development_dependency 'rake', '~> 13.3'
3638
s.add_development_dependency 'rspec', '~> 3.7'
3739
s.add_development_dependency 'srv', '~> 1.0'
3840
s.add_development_dependency 'thin', '~> 1.7'
3941
end
40-

0 commit comments

Comments
 (0)