model_collect: collect more things
[nit.git] / lib / binary / serialization.nit
index 34de766..ddb87ad 100644 (file)
@@ -53,7 +53,7 @@ private fun kind_bool: Byte do return 0x05u8
 private fun kind_char: Byte do return 0x06u8
 private fun kind_float: Byte do return 0x07u8
 private fun kind_string: Byte do return 0x08u8
-private fun kind_native_string: Byte do return 0x09u8
+private fun kind_c_string: Byte do return 0x09u8
 private fun kind_flat_array: Byte do return 0x0Au8
 
 private fun new_object_end: Byte do return 0x00u8
@@ -70,6 +70,8 @@ class BinarySerializer
        # Target writing stream
        var stream: Writer is writable
 
+       redef var current_object = null
+
        redef fun serialize(object)
        do
                if object == null then
@@ -92,7 +94,10 @@ class BinarySerializer
                        stream.write_int64 id
                else
                        # serialize here
+                       var last_object = current_object
+                       current_object = object
                        object.serialize_to_binary self
+                       current_object = last_object
                end
        end
 
@@ -230,10 +235,10 @@ class BinaryDeserializer
                                if b == null then return '�'
                                bf[i] = b
                        end
-                       return bf.to_s_with_length(ln)[0]
+                       return bf.to_s_unsafe(ln, copy=false)[0]
                end
                if kind == kind_string then return stream.read_block
-               if kind == kind_native_string then return stream.read_block.to_cstring
+               if kind == kind_c_string then return stream.read_block.to_cstring
 
                if kind == kind_flat_array then
                        # An array
@@ -366,7 +371,7 @@ redef class Serializable
        private fun serialize_to_binary(v: BinarySerializer)
        do
                serialize_header_to_binary v
-               core_serialize_to v
+               v.serialize_core self
                v.stream.write_byte new_object_end
        end
 end
@@ -406,7 +411,7 @@ end
 redef class CString
        redef fun serialize_to_binary(v)
        do
-               v.stream.write_byte kind_native_string
+               v.stream.write_byte kind_c_string
                v.stream.write_block to_s
        end
 end
@@ -454,7 +459,7 @@ redef class Map[K, V]
        do
                serialize_header_to_binary v
 
-               core_serialize_to v
+               v.serialize_core self
 
                v.stream.write_string "keys"
                v.serialize_flat_array keys