Re-implemented Stream#serialize and Chunk#serialize in C.
[ruby-eet.git] / lib / eet.rb
index ddac645d5404945b4a11379c30a2a35568aa7075..8a949845063a5baf1ef8e0c75fa3ec7b9741dcfa 100644 (file)
@@ -1,5 +1,5 @@
 #--
-# $Id: eet.rb 33 2005-04-30 11:10:16Z tilman $
+# $Id: eet.rb 34 2005-04-30 13:15:19Z tilman $
 #
 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
 #
@@ -166,10 +166,6 @@ module Eet
                        super(chunk.nil? ? 0 : 1, chunk)
                end
 
-               def serialize
-                       map { |c| c.serialize }.join
-               end
-
                def Stream.deserialize(data)
                        data = data.to_str.dup
                        s = Stream.new
@@ -194,21 +190,13 @@ module Eet
                        @tag = tag.to_str.dup.freeze
                        @data = data.to_str.dup.freeze
 
-                       @size = @tag.length + 1 + @data.length
-
                        # libeet uses a signed 32bit integer to store the
                        # chunk size, so make sure we don't overflow it
-                       if @size >= (1 << 31)
+                       if (@tag.length + 1 + @data.length) >= (1 << 31)
                                raise(ArgumentError, "tag or data too long")
                        end
                end
 
-               def serialize
-                       buf = "CHnK"
-                       buf << [@size].pack("V")
-                       buf << @tag << "\0" << @data
-               end
-
                def Chunk.deserialize(data)
                        if data.length < 8 || data[0, 4] != "CHnK"
                                raise(ChunkError, "invalid data")