X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=lib%2Feet.rb;h=578dea6a63a18238ec24e2a35332120f94024513;hb=49ccc7e172fd87e88a15fa05d9284307adcd1dec;hp=8a949845063a5baf1ef8e0c75fa3ec7b9741dcfa;hpb=49e6c8f56d89681f20836a14480959fa89d24e26;p=ruby-eet.git diff --git a/lib/eet.rb b/lib/eet.rb index 8a94984..578dea6 100644 --- a/lib/eet.rb +++ b/lib/eet.rb @@ -1,5 +1,5 @@ #-- -# $Id: eet.rb 34 2005-04-30 13:15:19Z tilman $ +# $Id: eet.rb 45 2005-05-25 20:08:35Z tilman $ # # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) # @@ -46,7 +46,7 @@ class Object props.each_pair do |tag, arg| unless arg.is_a?(Array) - raise(Eet::PropertyError, "hash value not an array") + raise(Eet::PropertyError, "hash value is not an array") end value, type = arg @@ -124,13 +124,13 @@ end class TrueClass # :nodoc: def to_eet_chunks(tag, type = nil) - [Eet::Chunk.new(tag, [1].pack("c"))] + [Eet::Chunk.new(tag, "\1")] end end class FalseClass # :nodoc: def to_eet_chunks(tag, type = nil) - [Eet::Chunk.new(tag, [0].pack("c"))] + [Eet::Chunk.new(tag, "\0")] end end @@ -161,17 +161,24 @@ 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 Stream.deserialize(data) - data = data.to_str.dup + if data.to_str.empty? + raise(ArgumentError, "buffer is empty") + end + 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 +220,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