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.
diff --git a/lib/rb/lib/thrift/protocol/json_protocol.rb b/lib/rb/lib/thrift/protocol/json_protocol.rb
index 91e74e4..d03357e 100644
--- a/lib/rb/lib/thrift/protocol/json_protocol.rb
+++ b/lib/rb/lib/thrift/protocol/json_protocol.rb
@@ -16,9 +16,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-#
-
-require 'base64'
+#
module Thrift
class LookaheadReader
@@ -311,7 +309,7 @@
def write_json_base64(str)
@context.write(trans)
trans.write(@@kJSONStringDelimiter)
- trans.write(Base64.strict_encode64(str))
+ trans.write([str].pack('m0'))
trans.write(@@kJSONStringDelimiter)
end
@@ -555,7 +553,7 @@
str += '='
end
end
- Base64.strict_decode64(str)
+ str.unpack1('m0')
end
# Reads a sequence of characters, stopping at the first one that is not
diff --git a/lib/rb/thrift.gemspec b/lib/rb/thrift.gemspec
index ba9253d..7e1bb33 100644
--- a/lib/rb/thrift.gemspec
+++ b/lib/rb/thrift.gemspec
@@ -24,13 +24,15 @@
s.require_paths = %w[lib ext]
+ s.add_dependency 'logger'
+
s.add_development_dependency 'bundler', '~> 2.2.34'
s.add_development_dependency 'pry', '~> 0.11.3'
s.add_development_dependency 'pry-byebug', '~> 3.6'
s.add_development_dependency 'pry-stack_explorer', '~> 0.4.9.2'
s.add_development_dependency 'rack', '>= 2.2.20'
s.add_development_dependency 'rack-test', '~> 0.8.3'
- s.add_development_dependency 'rake', '~> 12.3'
+ s.add_development_dependency 'rake', '~> 13.3'
s.add_development_dependency 'rspec', '~> 3.7'
s.add_development_dependency 'srv', '~> 1.0'
s.add_development_dependency 'thin', '~> 1.7'