Internal API update.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sat, 16 Jul 2005 13:15:42 +0000 (13:15 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sat, 16 Jul 2005 13:15:42 +0000 (13:15 +0000)
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
ext/ext.c
test/test_chunk.rb
test/test_stream.rb

index bd36e6980ecd3b68137e33a2d9ded6ad29acddac..3009fe33501cb49dbc6fb0b0855e6d78593f3ba1 100644 (file)
--- 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
index bf1c4f03572c08089f1df51d823fcaf4efbabedd..4fb3f1e45895a2873f0ed3ee115fa320a6448eef 100644 (file)
--- 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");
index 6f73e4f7cc4ac8c857884d34fe67bc013c450460..881cbcade08cd578c99f04e44adb14b3e0643f91 100644 (file)
@@ -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
index ba15007bf47a4f1b3994364418f1d67a5d6c9c62..f2d52ee64547ae882ed8191b52d1fb32bbb686b6 100644 (file)
@@ -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