avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmhod...@apache.org
Subject svn commit: r951271 - in /avro/branches/branch-1.3: ./ lang/ruby/lib/avro/io.rb
Date Fri, 04 Jun 2010 05:29:31 GMT
Author: jmhodges
Date: Fri Jun  4 05:29:31 2010
New Revision: 951271

URL: http://svn.apache.org/viewvc?rev=951271&view=rev
Log:
AVRO-491. Doing doubles and floats better in the ruby impl. merge from trunk

Modified:
    avro/branches/branch-1.3/   (props changed)
    avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb

Propchange: avro/branches/branch-1.3/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jun  4 05:29:31 2010
@@ -1,2 +1,2 @@
 /avro/trunk:944035,944049
-/hadoop/avro/trunk:930458-930459,930461,935526,938347
+/hadoop/avro/trunk:930458-930459,930461-930462,935526,938347

Modified: avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb?rev=951271&r1=951270&r2=951271&view=diff
==============================================================================
--- avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb (original)
+++ avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb Fri Jun  4 05:29:31 2010
@@ -76,12 +76,7 @@ module Avro
         # The float is converted into a 32-bit integer using a method
         # equivalent to Java's floatToIntBits and then encoded in
         # little-endian format.
-
-        bits = (byte! & 0xFF) |
-          ((byte! & 0xff) <<  8) |
-          ((byte! & 0xff) << 16) |
-          ((byte! & 0xff) << 24)
-        [bits].pack('i').unpack('e')[0]
+        @reader.read(4).unpack('e')[0]
       end
 
       def read_double
@@ -89,16 +84,7 @@ module Avro
         # The double is converted into a 64-bit integer using a method
         # equivalent to Java's doubleToLongBits and then encoded in
         # little-endian format.
-
-        bits = (byte! & 0xFF) |
-          ((byte! & 0xff) <<  8) |
-          ((byte! & 0xff) << 16) |
-          ((byte! & 0xff) << 24) |
-          ((byte! & 0xff) << 32) |
-          ((byte! & 0xff) << 40) |
-          ((byte! & 0xff) << 48) |
-          ((byte! & 0xff) << 56)
-        [bits].pack('Q').unpack('d')[0]
+        @reader.read(8).unpack('E')[0]
       end
 
       def read_bytes
@@ -202,11 +188,7 @@ module Avro
       # equivalent to Java's floatToIntBits and then encoded in
       # little-endian format.
       def write_float(datum)
-        bits = [datum].pack('e').unpack('i')[0]
-        @writer.write(((bits      ) & 0xFF).chr)
-        @writer.write(((bits >> 8 ) & 0xFF).chr)
-        @writer.write(((bits >> 16) & 0xFF).chr)
-        @writer.write(((bits >> 24) & 0xFF).chr)
+        @writer.write([datum].pack('e'))
       end
 
       # A double is written as 8 bytes.
@@ -214,15 +196,7 @@ module Avro
       # equivalent to Java's doubleToLongBits and then encoded in
       # little-endian format.
       def write_double(datum)
-        bits = [datum].pack('d').unpack('Q')[0]
-        @writer.write(((bits      ) & 0xFF).chr)
-        @writer.write(((bits >> 8 ) & 0xFF).chr)
-        @writer.write(((bits >> 16) & 0xFF).chr)
-        @writer.write(((bits >> 24) & 0xFF).chr)
-        @writer.write(((bits >> 32) & 0xFF).chr)
-        @writer.write(((bits >> 40) & 0xFF).chr)
-        @writer.write(((bits >> 48) & 0xFF).chr)
-        @writer.write(((bits >> 56) & 0xFF).chr)
+        @writer.write([datum].pack('E'))
       end
 
       # Bytes are encoded as a long followed by that many bytes of data.



Mime
View raw message