From 1a7967e7d0581ab9eedd0e18862323bc6f00d029 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sat, 16 Jul 2005 13:15:42 +0000 Subject: [PATCH] Internal API update. Instead of using Chunk#serialize and Stream#serialize, rename Chunk#serialize to Chunk#to_s and just use Stream#to_s to serialize the streams. --- ChangeLog | 6 +++++- ext/ext.c | 39 +++++++-------------------------------- test/test_chunk.rb | 4 ++-- test/test_stream.rb | 4 ++-- 4 files changed, 16 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd36e69..3009fe3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,15 @@ -- -$Id: ChangeLog 71 2005-07-16 12:28:17Z tilman $ +$Id: ChangeLog 72 2005-07-16 13:15:42Z tilman $ ++ 2005-07-16 Tilman Sauerbeck (tilman at code-monkey de) * ext/ext.c, test/test_stream.rb: Don't raise BadElementError if Stream#serialize is called on a stream that includes non-Chunk elements + * ext/ext.c, test/test_{chunk,stream}.rb: Internal API update. + Instead of using Chunk#serialize and Stream#serialize, rename + Chunk#serialize to Chunk#to_s and just use Stream#to_s to + serialize the streams 2005-07-15 Tilman Sauerbeck (tilman at code-monkey de) * ext/ext.c: Code cleanup diff --git a/ext/ext.c b/ext/ext.c index bf1c4f0..4fb3f1e 100644 --- a/ext/ext.c +++ b/ext/ext.c @@ -1,5 +1,5 @@ /* - * $Id: ext.c 71 2005-07-16 12:28:17Z tilman $ + * $Id: ext.c 72 2005-07-16 13:15:42Z tilman $ * * Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) * @@ -50,7 +50,7 @@ static VALUE cStream, cChunk, eEetError, eNameError, ePropError, sym_lossy, sym_level, sym_quality, sym_char, sym_short, sym_long_long, sym_double; -static ID id_include, id_serialize, id_keys, id_pack, +static ID id_include, id_to_s, id_keys, id_pack, id_to_eet_chunks, id_to_eet_name, id_to_eet_properties, id_tag, id_data; @@ -436,30 +436,6 @@ c_write_image (int argc, VALUE *argv, VALUE self) return INT2FIX (n); } -static VALUE -stream_serialize (VALUE self) -{ - VALUE ret; - struct RArray *stream; - long i; - - stream = RARRAY (self); - if (!stream->len) - return rb_str_new2 (""); - - ret = rb_ary_new (); - - for (i = 0; i < stream->len; i++) { - VALUE str; - - str = rb_funcall (stream->ptr[i], id_serialize, 0, NULL); - - rb_ary_push (ret, str); - } - - return rb_ary_join (ret, Qnil); -} - static VALUE chunk_init (VALUE self, VALUE tag, VALUE data) { @@ -488,7 +464,7 @@ chunk_init (VALUE self, VALUE tag, VALUE data) } static VALUE -chunk_serialize (VALUE self) +chunk_to_s (VALUE self) { VALUE tmp, ret; unsigned int size, buf_len; @@ -587,13 +563,13 @@ c_to_eet (VALUE self) #endif args[0] = name; - args[1] = rb_funcall (stream, id_serialize, 0); + args[1] = rb_ary_to_s (stream); rb_ary_clear (stream); /* give the GC a hand... */ chunk = rb_class_new_instance (2, args, cChunk); - return rb_funcall (chunk, id_serialize, 0); + return rb_funcall (chunk, id_to_s, 0); } static VALUE @@ -670,11 +646,10 @@ Init_eet_ext () rb_define_method (c, "write_image", c_write_image, -1); cStream = rb_define_class_under (m, "Stream", rb_cArray); - rb_define_method (cStream, "serialize", stream_serialize, 0); cChunk = rb_define_class_under (m, "Chunk", rb_cObject); rb_define_method (cChunk, "initialize", chunk_init, 2); - rb_define_method (cChunk, "serialize", chunk_serialize, 0); + rb_define_method (cChunk, "to_s", chunk_to_s, 0); rb_define_attr (cChunk, "tag", 1, 0); rb_define_attr (cChunk, "data", 1, 0); @@ -689,7 +664,7 @@ Init_eet_ext () ePropError = rb_define_class_under (m, "PropertyError", eEetError); id_include = rb_intern ("include?"); - id_serialize = rb_intern ("serialize"); + id_to_s = rb_intern ("to_s"); id_keys = rb_intern ("keys"); id_pack = rb_intern ("pack"); id_to_eet_chunks = rb_intern ("to_eet_chunks"); diff --git a/test/test_chunk.rb b/test/test_chunk.rb index 6f73e4f..881cbca 100644 --- a/test/test_chunk.rb +++ b/test/test_chunk.rb @@ -1,11 +1,11 @@ -# $Id: test_chunk.rb 44 2005-05-25 19:51:25Z tilman $ +# $Id: test_chunk.rb 72 2005-07-16 13:15:42Z tilman $ require "eet" require "test/unit" class ChunkTest < Test::Unit::TestCase def setup - @data = Eet::Chunk.new("tag", "foo\0bar\0baz").serialize + @data = Eet::Chunk.new("tag", "foo\0bar\0baz").to_s end def test_serialize diff --git a/test/test_stream.rb b/test/test_stream.rb index ba15007..f2d52ee 100644 --- a/test/test_stream.rb +++ b/test/test_stream.rb @@ -1,4 +1,4 @@ -# $Id: test_stream.rb 71 2005-07-16 12:28:17Z tilman $ +# $Id: test_stream.rb 72 2005-07-16 13:15:42Z tilman $ require "eet" require "test/unit" @@ -10,7 +10,7 @@ class StreamTest < Test::Unit::TestCase stream << Eet::Chunk.new("tag2", "bar") stream << Eet::Chunk.new("tag23", "baz") - @data = stream.serialize + @data = stream.to_s assert_not_nil(@data) end -- 2.30.2