X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=lib%2Feet.rb;h=ca2815c7bbb15b4ea2b434c734b3ff05ab43ebca;hb=acac7cddaa36d56b0d2cb89291a7d37228e2aaf0;hp=8a2893ef3b6b631cd44119684879bc0a7fa99dbb;hpb=2d2e5afec0ba994e5e06aebe32ba348570623519;p=ruby-eet.git diff --git a/lib/eet.rb b/lib/eet.rb index 8a2893e..ca2815c 100644 --- a/lib/eet.rb +++ b/lib/eet.rb @@ -1,7 +1,5 @@ #-- -# $Id: eet.rb 46 2005-05-25 20:10:37Z tilman $ -# -# Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) +# Copyright (c) 2005-2007 Tilman Sauerbeck (tilman at code-monkey de) # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -25,40 +23,6 @@ require "eet_ext" class Object - # :call-seq: - # object.to_eet -> string - # - # Serializes the receiver to EET format. - def to_eet - props = to_eet_properties - - unless props.is_a?(Hash) && !props.empty? - raise(Eet::PropertyError, "invalid EET properties") - end - - eet_name = to_eet_name - - if eet_name.to_str.length < 1 || eet_name.to_str.include?(0) - raise(Eet::NameError, "invalid EET name") - end - - stream = Eet::Stream.new - - props.each_pair do |tag, arg| - unless arg.is_a?(Array) - raise(Eet::PropertyError, "hash value is not an array") - end - - value, type = arg - next if value.nil? - - stream.push(*value.to_eet_chunks(tag, type)) - end - - chunk = Eet::Chunk.new(eet_name, stream.serialize) - Eet::Stream.new(chunk).serialize - end - def to_eet_chunks(tag, type = nil) # :nodoc: [Eet::Chunk.new(tag, to_eet)] end @@ -90,32 +54,6 @@ class Object end end -class Integer # :nodoc: - def to_eet_chunks(tag, type = nil) - fmt = case type - when :char: "c" - when :short: "v" - when :long_long: "q" - else "V" - end - - data = [self].pack(fmt) - [Eet::Chunk.new(tag, data)] - end -end - -class Float # :nodoc: - def to_eet_chunks(tag, type = nil) - fmt = case type - when :double: "%32.32f" - else "%16.16f" - end - - data = fmt % self - [Eet::Chunk.new(tag, data + "\0")] - end -end - class String # :nodoc: def to_eet_chunks(tag, type = nil) [Eet::Chunk.new(tag, self + "\0")] @@ -154,11 +92,8 @@ class Hash # :nodoc: end module Eet - VERSION = "0.1.2" + VERSION = "0.1.3" - class EetError < StandardError; end - class NameError < EetError; end - class PropertyError < EetError; end class ChunkError < EetError; end class Stream # :nodoc: @@ -186,24 +121,6 @@ module Eet end class Chunk # :nodoc: - attr_reader :tag, :data - - def initialize(tag, data) - if tag.to_str.include?(0) - raise(ArgumentError, - "tag must not contain binary zeroes") - end - - @tag = tag.to_str.dup.freeze - @data = data.to_str.dup.freeze - - # libeet uses a signed 32bit integer to store the - # chunk size, so make sure we don't overflow it - if (@tag.length + 1 + @data.length) >= (1 << 31) - raise(ArgumentError, "tag or data too long") - end - end - def Chunk.deserialize(data) if data.to_str.empty? raise(ArgumentError, "buffer is empty")