CustomSerializationTElement InterfaceNaiad Help

[This is preliminary documentation and is subject to change.]

Encapsulates the custom code for serializing and deserializing objects of type TElement.

Namespace: Microsoft.Research.Naiad.Serialization
Assembly: Microsoft.Research.Naiad (in Microsoft.Research.Naiad.dll) Version: 0.5.0.0 (0.5.0.0)
Syntax

C#
public interface CustomSerialization<TElement>

Type Parameters

TElement
The type of element to be serialized or deserialized.

The CustomSerializationTElement type exposes the following members.

Methods

  NameDescription
Public methodDeserialize
Deserializes into value the next element from the given buffer.
Public methodTrySerialize
Attempts to serialize the given value into the given buffer with limit bytes remaining.
Top
Remarks

Implementations of this interface should have a no-argument constructor, because the serialization code generator will attempt to instantiate serializers using the no-argument constructor. A type constraint on RegisterCustomSerializationTElement, TSerializer ensures that this is the case for all registered serializers.
Examples

public unsafe class IntSerializer : CustomSerialization<int> { public unsafe int TrySerialize(int value, byte* buffer, int limit) { if (limit < 4) return -1; *(int*)buffer = value; return 4; } public unsafe int Deserialize(out int value, byte* buffer, int limit) { value = *(int*)buffer; return 4; } } // Generated serialization code: byte* currentPosition = ...; int bytesRemaining = ...; int toSerialize = ...; IntSerializer serializer = new IntSerializer(); int bytesWritten = serializer.TrySerialize(value, currentPosition, bytesRemaining); if (bytesWritten <= 0) return false; else currentPosition += bytesWritten; // Generated deserialization code: byte* currentPosition = ...; int bytesRemaining = ...; int toDeserialize; IntSerializer deserializer = new IntSerializer(); int bytesRead = deserializer.Deserialize(out toDeserialize, currentPosition, bytesRemaining); currentPosition += bytesRead; bytesRemaining -= bytesRead;
See Also

Reference