Is it possible to serialize a tuple of memory streams created by a binarywriter using Protobuf.net? If I try that, the Protobuf says that it cannot serialize a stream.
What I am after is to serialize a tuple of jagged arrays. I do not want to convert them into 1D arrays because I believe it is not necessary. So I thought that I would serialize the jagged arrays to the memory stream on my own, but I want the Protobuf.net to serialize the tuple for me. I need to have the overall serialization / deserialization as fast as possible.
EDIT:
My overall goal is to send the following jagged array tuple through WCF as fast as possible no matter how. The overall time from jagged array to jagged array counts.
// F# interactive code
#time "on"
#r @"d:\Protobuf\protobuf-net.dll"
let getJaggedArray () =
let size = 100
let rnd = System.Random 1
Array.init size (fun i ->
Array.init size (fun j ->
Array.init size (fun k ->
rnd.NextDouble() )))
let wcfData = (getJaggedArray (), getJaggedArray ()), getJaggedArray ()
let file = new System.IO.FileStream ("test.bin", System.IO.FileMode.Create)
ProtoBuf.Serializer.Serialize (file, wcfData)
file.Close()
// === Future use ===
//[<ServiceContract>]
//type IWCF =
//
// [<OperationContract>]
// [<ProtoBehavior>]
// abstract Send: wcfData -> unit
Protobuf-net does not current have any specific handling of streams (although it will handle
byte[]), although I guess it could simply consume theStream(serialize) and reproduce aMemoryStream(deserialize). If you didn’t want to change your model, it should be possible to register a “surrogate” forStreamthat does exactly that in only a few lines of code (let me know if that is of interest).It has automatic support for most common “tuple” patterns, but jagged data is again an issue – although again, this could be handled if we really needed (more commonly, having an outer- list of objects that themselves have an inner-list is a pragmatic workaround to “jagged”, and works currently).
If you can post a more complete (ideally runnable) example, I may be able to offer more guidance.