I have read Protobuf-net memcache provider fails on append/set ArraySegment which says it may be supported at some point.
I have also tried the test suggested in that question, which indicates that version 2.0.0.668 does not support it.
Has anyone had success using ArraySegments with protobuf-net, or have an idea for an efficient method of sending a byte array over the wire.
I.e. I have an object like this:
[ProtoContract]
class Foo
{
[ProtoMember(1)]
public byte[] Data { get; set; }
}
And I want to serialize a different object T into a byte array, assign it to Data, and then serialize Foo into another byte[]. (Sounds inefficent, but the Foo class must be agnostic to the type, could it be generic?).
The key thing is I would prefer to minimise allocation/GC, so I want to minimise the copying of arrays or allocation of new ones each time I serialize the data.
Here is some example code which demonstrates what I am trying to achieve more efficently:
public class DataSender<T>
{
private ISerializer serializer; //Could be any kind of binary serializer
public void Send(T obj)
{
MemoryStream serializationBuffer = new MemoryStream(); // Inefficent allocation
serializer.Serialize(serializationBuffer, obj);
var sendable = new Foo(){ Data=serializationBuffer.ToArray() } // Inefficent copy
Sender.Send(sendable);
}
}
Any suggestions for replacements for my Foo object and/or sending code would be very welcome.