Based on documentation, I have tried following to plug in the Protobuf.Net,
using following steps.

- Implemented the interface IBinarizable for the OrderEntity

- Implemented the class, with all the relevant methods
public class CustomBinaryReaderWriter : IBinaryWriter, IBinaryReader

Now I am not sure how to use / register the CustomBinaryReaderWriter for
usage in the program, I tried like BinaryReflectiveSerializer, but that's
certainly not correct:

 <binaryTypeConfiguration typeName="OrderEntity">
          <serializer type="CustomBinaryReaderWriter, ApacheIgnite"/>
</binaryTypeConfiguration>

Entity
====

public class OrderEntity : IBinarizable
{
    [QuerySqlField(IsIndexed = true)]
    public int OrderId { get; set; }

    [QuerySqlField(IsIndexed = true)]
    public string OrderName { get; set; }

    [QuerySqlField(IsIndexed = true)]
    public DateTime OrderDateTime { get; set; }

    [QuerySqlField(IsIndexed = true)]
    public double OrderValue { get; set; }

    [QuerySqlField(IsIndexed = true)]
    public string OrderAddress { get; set; }

    public void WriteBinary(IBinaryWriter writer)
    {
        writer.WriteInt("OrderId", OrderId);
        writer.WriteString("OrderName", OrderName);
        writer.WriteObject("OrderDateTime", OrderDateTime);
        writer.WriteDouble("OrderValue", OrderValue);
        writer.WriteString("OrderAddress", OrderAddress);
    }

    public void ReadBinary(IBinaryReader reader)
    {
        // Read order does not matter, however, reading in the same order 
        // as writing improves performance
        OrderId = reader.ReadInt("OrderId");
        OrderName = reader.ReadString("OrderName");
        OrderDateTime = reader.ReadObject<DateTime>("OrderDateTime");
        OrderValue = reader.ReadDouble("OrderValue");
        OrderAddress = reader.ReadString("OrderAddress");
    }
}

Custom Binary Reader / Writer
====================

public class CustomBinaryReaderWriter : IBinaryWriter, IBinaryReader
{
    /// <summary>
    /// 
    /// </summary>
    private readonly Dictionary<string, object> _serializerDictionary;

    public CustomBinaryReaderWriter()
    {
        _serializerDictionary = new Dictionary<string, object>();
    }

    public void WriteByte(string fieldName, byte val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteByteArray(string fieldName, byte[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteChar(string fieldName, char val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteCharArray(string fieldName, char[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteShort(string fieldName, short val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteShortArray(string fieldName, short[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteInt(string fieldName, int val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteIntArray(string fieldName, int[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteLong(string fieldName, long val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteLongArray(string fieldName, long[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteBoolean(string fieldName, bool val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteBooleanArray(string fieldName, bool[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteFloat(string fieldName, float val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteFloatArray(string fieldName, float[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteDouble(string fieldName, double val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteDoubleArray(string fieldName, double[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteDecimal(string fieldName, decimal? val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteDecimalArray(string fieldName, decimal?[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteTimestamp(string fieldName, DateTime? val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteTimestampArray(string fieldName, DateTime?[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteString(string fieldName, string val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteStringArray(string fieldName, string[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteGuid(string fieldName, Guid? val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteGuidArray(string fieldName, Guid?[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteEnum<T>(string fieldName, T val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteEnumArray<T>(string fieldName, T[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteObject<T>(string fieldName, T val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteArray<T>(string fieldName, T[] val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public IBinaryRawWriter GetRawWriter()
    {
        throw new NotImplementedException();
    }

    public void WriteDictionary(string fieldName, IDictionary val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public void WriteCollection(string fieldName, ICollection val)
    {
        // Allocate the Memory Stream
        var memoryStream = new MemoryStream();

        // Serialize the Data to Stream
        Serializer.Serialize(memoryStream, val);

        _serializerDictionary.Add(fieldName, memoryStream);
    }

    public byte ReadByte(string fieldName)
    {
        return
Serializer.Deserialize<byte>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public byte[] ReadByteArray(string fieldName)
    {
        return
Serializer.Deserialize<byte[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public char ReadChar(string fieldName)
    {
        return
Serializer.Deserialize<char>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public char[] ReadCharArray(string fieldName)
    {
        return
Serializer.Deserialize<char[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public short ReadShort(string fieldName)
    {
        return
Serializer.Deserialize<short>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public short[] ReadShortArray(string fieldName)
    {
        return
Serializer.Deserialize<short[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public int ReadInt(string fieldName)
    {
        return
Serializer.Deserialize<int>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public int[] ReadIntArray(string fieldName)
    {
        return
Serializer.Deserialize<int[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public long ReadLong(string fieldName)
    {
        return
Serializer.Deserialize<long>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public long[] ReadLongArray(string fieldName)
    {
        return
Serializer.Deserialize<long[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public bool ReadBoolean(string fieldName)
    {
        return
Serializer.Deserialize<bool>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public bool[] ReadBooleanArray(string fieldName)
    {
        return
Serializer.Deserialize<bool[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public float ReadFloat(string fieldName)
    {
        return
Serializer.Deserialize<float>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public float[] ReadFloatArray(string fieldName)
    {
        return
Serializer.Deserialize<float[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public double ReadDouble(string fieldName)
    {
        return
Serializer.Deserialize<double>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public double[] ReadDoubleArray(string fieldName)
    {
        return
Serializer.Deserialize<double[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public decimal? ReadDecimal(string fieldName)
    {
        return
Serializer.Deserialize<decimal?>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public decimal?[] ReadDecimalArray(string fieldName)
    {
        return
Serializer.Deserialize<decimal?[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public DateTime? ReadTimestamp(string fieldName)
    {
        return
Serializer.Deserialize<DateTime?>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public DateTime?[] ReadTimestampArray(string fieldName)
    {
        return
Serializer.Deserialize<DateTime?[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public string ReadString(string fieldName)
    {
        return
Serializer.Deserialize<string>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public string[] ReadStringArray(string fieldName)
    {
        return
Serializer.Deserialize<string[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public Guid? ReadGuid(string fieldName)
    {
        return
Serializer.Deserialize<Guid?>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public Guid?[] ReadGuidArray(string fieldName)
    {
        return
Serializer.Deserialize<Guid?[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public T ReadEnum<T>(string fieldName)
    {
        return
Serializer.Deserialize<T>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public T[] ReadEnumArray<T>(string fieldName)
    {
        return
Serializer.Deserialize<T[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public T ReadObject<T>(string fieldName)
    {
        return
Serializer.Deserialize<T>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public T[] ReadArray<T>(string fieldName)
    {
        return
Serializer.Deserialize<T[]>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public ICollection ReadCollection(string fieldName)
    {
        return
Serializer.Deserialize<ICollection>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public ICollection ReadCollection(string fieldName, Func<int,
ICollection> factory, Action<ICollection, object> adder)
    {
        return
Serializer.Deserialize<ICollection>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public IDictionary ReadDictionary(string fieldName)
    {
        return
Serializer.Deserialize<IDictionary>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public IDictionary ReadDictionary(string fieldName, Func<int,
IDictionary> factory)
    {
        return
Serializer.Deserialize<IDictionary>((MemoryStream)_serializerDictionary[fieldName]);
    }

    public IBinaryRawReader GetRawReader()
    {
        throw new NotImplementedException();
    }
}




--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/Plug-in-custom-binary-serializer-for-Ignite-Net-tp5836.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to