lib/avro/io.rb in avro-1.10.2 vs lib/avro/io.rb in avro-1.11.0
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
@@ -74,19 +75,19 @@
def read_float
# A float is written as 4 bytes.
# The float is converted into a 32-bit integer using a method
# equivalent to Java's floatToIntBits and then encoded in
# little-endian format.
- read_and_unpack(4, 'e'.freeze)
+ read_and_unpack(4, 'e')
end
def read_double
# A double is written as 8 bytes.
# The double is converted into a 64-bit integer using a method
# equivalent to Java's doubleToLongBits and then encoded in
# little-endian format.
- read_and_unpack(8, 'E'.freeze)
+ read_and_unpack(8, 'E')
end
def read_bytes
# Bytes are encoded as a long followed by that many bytes of
# data.
@@ -95,11 +96,11 @@
def read_string
# A string is encoded as a long followed by that many bytes of
# UTF-8 encoded character data.
read_bytes.tap do |string|
- string.force_encoding('UTF-8'.freeze) if string.respond_to? :force_encoding
+ string.force_encoding('UTF-8') if string.respond_to? :force_encoding
end
end
def read(len)
# Read n bytes
@@ -203,19 +204,19 @@
# A float is written as 4 bytes.
# The float is converted into a 32-bit integer using a method
# equivalent to Java's floatToIntBits and then encoded in
# little-endian format.
def write_float(datum)
- @writer.write([datum].pack('e'.freeze))
+ @writer.write([datum].pack('e'))
end
# A double is written as 8 bytes.
# The double is converted into a 64-bit integer using a method
# equivalent to Java's doubleToLongBits and then encoded in
# little-endian format.
def write_double(datum)
- @writer.write([datum].pack('E'.freeze))
+ @writer.write([datum].pack('E'))
end
# Bytes are encoded as a long followed by that many bytes of data.
def write_bytes(datum)
write_long(datum.bytesize)
@@ -223,11 +224,11 @@
end
# A string is encoded as a long followed by that many bytes of
# UTF-8 encoded character data
def write_string(datum)
- datum = datum.encode('utf-8'.freeze) if datum.respond_to? :encode
+ datum = datum.encode('utf-8') if datum.respond_to? :encode
write_bytes(datum)
end
# Write an arbritary datum.
def write(datum)
@@ -390,16 +391,14 @@
def read_default_value(field_schema, default_value)
# Basically a JSON Decoder?
case field_schema.type_sym
when :null
return nil
- when :boolean
- return default_value
when :int, :long
return Integer(default_value)
when :float, :double
return Float(default_value)
- when :enum, :fixed, :string, :bytes
+ when :boolean, :enum, :fixed, :string, :bytes
return default_value
when :array
read_array = []
default_value.each do |json_val|
item_val = read_default_value(field_schema.items, json_val)