Author: jmhodges
Date: Mon Apr 12 10:29:05 2010
New Revision: 933180

URL: http://svn.apache.org/viewvc?rev=933180&view=rev
Log:
AVRO-516. Ruby socket RPC should use big endian buffer lengths.

Added:
    hadoop/avro/trunk/lang/ruby/test/test_socket_transport.rb
Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/lang/ruby/lib/avro/ipc.rb

Modified: hadoop/avro/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=933180&r1=933179&r2=933180&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Mon Apr 12 10:29:05 2010
@@ -25,6 +25,9 @@ Avro 1.4.0 (unreleased)
 
     AVRO-516. Removing unnecessary ruby StringIO calls. (jmhodges)
 
+    AVRO-516. Ruby socket RPC should use big endian buffer lengths.
+    (jmhodges)
+
   BUG FIXES
     AVRO-461. Skipping primitives in the ruby side (jmhodges)
 

Modified: hadoop/avro/trunk/lang/ruby/lib/avro/ipc.rb
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/ruby/lib/avro/ipc.rb?rev=933180&r1=933179&r2=933180&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/ruby/lib/avro/ipc.rb (original)
+++ hadoop/avro/trunk/lang/ruby/lib/avro/ipc.rb Mon Apr 12 10:29:05 2010
@@ -421,7 +421,7 @@ module Avro::IPC
     end
 
     def write_buffer_length(n)
-      bytes_sent = sock.write([n].pack('I'))
+      bytes_sent = sock.write([n].pack('N'))
       if bytes_sent == 0
         raise ConnectionClosedException.new("socket sent 0 bytes")
       end
@@ -432,7 +432,7 @@ module Avro::IPC
       if read == '' || read == nil
         raise ConnectionClosedException.new("Socket read 0 bytes.")
       end
-      read.unpack('I')[0]
+      read.unpack('N')[0]
     end
 
     def close

Added: hadoop/avro/trunk/lang/ruby/test/test_socket_transport.rb
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/ruby/test/test_socket_transport.rb?rev=933180&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/ruby/test/test_socket_transport.rb (added)
+++ hadoop/avro/trunk/lang/ruby/test/test_socket_transport.rb Mon Apr 12 
10:29:05 2010
@@ -0,0 +1,24 @@
+require 'test_help'
+
+class TestSocketTransport < Test::Unit::TestCase
+  def test_buffer_writing
+    io = StringIO.new
+    st = Avro::IPC::SocketTransport.new(io)
+    buffer_length = "\000\000\000\006"  # 6 in big-endian
+    message = 'abcdef'
+    null_ending = "\000\000\000\000" # 0 in big-endian
+    full = buffer_length + message + null_ending
+    st.write_framed_message('abcdef')
+    assert_equal full, io.string
+  end
+
+  def test_buffer_reading
+    buffer_length = "\000\000\000\005" # 5 in big-endian
+    message = "hello"
+    null_ending = "\000\000\000\000" # 0 in big-endian
+    full = buffer_length + message + null_ending
+    io = StringIO.new(full)
+    st = Avro::IPC::SocketTransport.new(io)
+    assert_equal 'hello', st.read_framed_message
+  end
+end


Reply via email to