Click or drag to resize

IWritable Interface

Interface for objects that can be serialized using the BinaryWriter and BinaryReader classes.

Namespace:  Ookii.Jumbo.IO
Assembly:  Ookii.Jumbo (in Ookii.Jumbo.dll) Version: 2.0.0
Syntax
public interface IWritable

The IWritable type exposes the following members.

Methods
  NameDescription
Public methodRead
Reads the object from the specified reader.
Public methodWrite
Writes the object to the specified writer.
Top
Remarks

The IWritable interface provides a simple, light-weight serialization protocol that is used primarily by the BinaryRecordReaderT and BinaryRecordWriterT class (but is also used in a few other instances).

Unlike the serialization provided by the BinaryFormatter class, IWritable serialization is done entirely by the class that implements the interface. There are no built-in checks to see if the type being deserialized from a stream matches the type that was serialized to it. It is up to the implementation of the Write(BinaryWriter) and Read(BinaryReader) methods to guarantee binary compatibility.

For this reason, it is recommended to use IWritable serialization only for short-time storage where the performance of serializing and deserializing is important. Its primary usage in Jumbo (intermediate data for Jumbo Jet jobs) fits these criteria.

Types that implement IWritable must be reference types (classes). To support serialization of value types, you must implement a IValueWriterT for those types and mark them with the ValueWriterAttribute.

The BinaryRecordReaderT creates new record instances by using the GetUninitializedObject(Type) method. This means the object's constructors are not invoked, so the Read(BinaryReader) implementation may not make any assumptions about the state of the class, and must guarantee the object is in a consistent state after it finishes.

When record reuse is enabled, the Read(BinaryReader) method will be called multiple times on the same instance. The Read(BinaryReader) method must replace the entire internal state of the object with that of the new record. If any of the object's internal state is stored in reference types, it's recommended to reuse object instances as much as possible.

See Also