Class SlimSerializer
Implements Slim serialization algorithm that relies on an injectable SlimFormat-derivative (through .ctor) paremeter.
This class was designed for highly-efficient serialization of types without versioning.
SlimSerializer supports a concept of "known types" that save space by not emitting their names into stream.
Performance note:
This serializer yields on average 1/4 serialization and 1/2 deserialization times while compared to BinaryFormatter.
Serialization of Record-instances usually takes 1/6 of BinaryFormatter time.
Format takes 1/10 space for records and 1/2 for general object graphs.
Such performance is achieved because of dynamic compilation of type-specific serialization/deserialization methods.
This type is thread-safe for serializations/deserializations when TypeMode is set to "PerCall"
Inheritance
System.Object
SlimSerializer
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: Azos.dll
Syntax
[SlimSerializationProhibited]
public class SlimSerializer : ISlimSerializer, ISerializer
Constructors
SlimSerializer()
Declaration
Declaration
public SlimSerializer(SlimFormat format)
Parameters
Declaration
public SlimSerializer(SlimFormat format, params IEnumerable<Type>[] globalTypes)
Parameters
Type |
Name |
Description |
SlimFormat |
format |
|
System.Collections.Generic.IEnumerable<System.Type>[] |
globalTypes |
|
SlimSerializer(IEnumerable<Type>[])
Declaration
public SlimSerializer(params IEnumerable<Type>[] globalTypes)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<System.Type>[] |
globalTypes |
|
Fields
Declaration
public const ushort HEADER = 51966
Field Value
Type |
Description |
System.UInt16 |
|
Owner
Associates arbitrary owner object with this instance. Slim serializer does not use this field internally for any purpose
Declaration
Field Value
Type |
Description |
System.Object |
|
Properties
BatchTypeRegistry
ADVANCED FEATURE! Developers do not use.
Returns type registry used in batch.
This call is only valid in TypeMode = "Batch" and is inherently not thread-safe.
Be careful not to mutate the returned object
Declaration
public TypeRegistry BatchTypeRegistry { get; }
Property Value
BatchTypesAdded
Returns true if last call to Serialize or Deserialize in batch mode added more types to type registry.
This call is only valid in TypeMode = "Batch" and is inherently not thread-safe
Declaration
public bool BatchTypesAdded { get; }
Property Value
Type |
Description |
System.Boolean |
|
Declaration
public SlimFormat Format { get; }
Property Value
IsThreadSafe
Returns true when TypeMode is "PerCall"
Declaration
public bool IsThreadSafe { get; }
Property Value
Type |
Description |
System.Boolean |
|
TypeMode
Gets/sets how serializer handles type information between calls to Serialize/Deserialize.
Setting this to "Batch" makes this serializer instance not thread-safe for calling Serialize/Deserialize.
This property itself is not thread-safe, that is - it should be only set once by control/initiating thread
Declaration
public TypeRegistryMode TypeMode { get; set; }
Property Value
Methods
Deserialize(Stream)
Declaration
public object Deserialize(Stream stream)
Parameters
Type |
Name |
Description |
System.IO.Stream |
stream |
|
Returns
Type |
Description |
System.Object |
|
ResetCallBatch()
Resets type registry to initial state (which is based on global types) for TypeMode = "Batch",
otherwise does nothing. This method is not thread-safe
Declaration
public void ResetCallBatch()
Serialize(Stream, Object)
Declaration
public void Serialize(Stream stream, object root)
Parameters
Type |
Name |
Description |
System.IO.Stream |
stream |
|
System.Object |
root |
|
Implements
Extension Methods