Chunk.deserialize doesn't modify its argument any more.
authorTilman Sauerbeck <tilman@code-monkey.de>
Wed, 25 May 2005 19:51:25 +0000 (19:51 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Wed, 25 May 2005 19:51:25 +0000 (19:51 +0000)
Instead, the number of bytes consumed is now returned, too.

ChangeLog
lib/eet.rb
test/test_chunk.rb

index 6ef487287f9ed7502434ce1b4178e79eb5e8ccd1..e66350425f88e33b40b3c1c5f26c0a8c59807335 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,13 @@
 --
-$Id: ChangeLog 43 2005-05-25 19:44:06Z tilman $
+$Id: ChangeLog 44 2005-05-25 19:51:25Z tilman $
 ++
 
 2005-05-25 Tilman Sauerbeck (tilman at code-monkey de)
         * test/test_array_sub.rb: Added a test for the :sub format
           specifier
+        * lib/eet.rb, test/test_chunk.rb: Chunk.deserialize doesn't
+          modify its argument any more, instead, the number of bytes
+          consumed is now returned, too.
 
 2005-05-19 Tilman Sauerbeck (tilman at code-monkey de)
         * Rakefile: Code cleanup
index 266a9e3b86572224c9d18d5f7713b43172a00b92..fa9f090e851672f5430c6dacb2731824c5f35f78 100644 (file)
@@ -1,5 +1,5 @@
 #--
-# $Id: eet.rb 40 2005-05-18 19:04:52Z tilman $
+# $Id: eet.rb 44 2005-05-25 19:51:25Z tilman $
 #
 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
 #
@@ -169,9 +169,13 @@ module Eet
                def Stream.deserialize(data)
                        data = data.to_str.dup
                        s = Stream.new
+                       offset = 0
 
-                       while data.length > 0
-                               s << Chunk.deserialize(data)
+                       while offset < data.length
+                               c, bytes = Chunk.deserialize(data[offset..-1])
+
+                               s << c
+                               offset += bytes
                        end
 
                        s
@@ -213,9 +217,7 @@ module Eet
 
                        c = Chunk.new(*data[8, size].split("\0", 2))
 
-                       data.replace(data[8 + size..-1] || "")
-
-                       c
+                       [c, 8 + size]
                end
        end
 end
index 2891dbadcdfb871d6fd409b9839a41f6a45c9545..6f73e4f7cc4ac8c857884d34fe67bc013c450460 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: test_chunk.rb 1 2005-03-26 01:45:38Z tilman $
+# $Id: test_chunk.rb 44 2005-05-25 19:51:25Z tilman $
 
 require "eet"
 require "test/unit"
@@ -16,7 +16,7 @@ class ChunkTest < Test::Unit::TestCase
                chunk = nil
 
                assert_nothing_raised do
-                       chunk = Eet::Chunk.deserialize(@data)
+                       chunk, = Eet::Chunk.deserialize(@data)
                end
 
                assert_equal("tag", chunk.tag)