X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=lib%2Feet.rb;h=2048bf392c5c77c33b6ae71509d60224522c567d;hb=8868bfa89df18715d5af45046770181d2d373b5d;hp=e0c7b72554bb9099713ea9256ec9ee848acf73eb;hpb=99b06a2cbaeb57e70bca75d699fcc7c5767ec5ca;p=ruby-eet.git diff --git a/lib/eet.rb b/lib/eet.rb index e0c7b72..2048bf3 100644 --- a/lib/eet.rb +++ b/lib/eet.rb @@ -1,5 +1,5 @@ #-- -# $Id: eet.rb 23 2005-04-09 17:16:58Z tilman $ +# $Id: eet.rb 37 2005-05-11 17:23:06Z tilman $ # # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) # @@ -161,15 +161,11 @@ module Eet class PropertyError < EetError; end class ChunkError < EetError; end - class Stream < Array # :nodoc: + class Stream # :nodoc: def initialize(chunk = nil) super(chunk.nil? ? 0 : 1, chunk) end - def serialize - inject("") { |a, c| a << c.serialize } - 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")