I'm trying to serialize some data for a UDP packet stream and I'm getting a huge overhead from serialization. If I encode a FileData with a 1k Byte array I get back 2312 bytes. How would I reduce this overhead without encoding and decoding everything myself?
[<Serializable>]
type Response =
| FileSize of String * int64
| FileData of int64 * byte[]
with
static member Decode(packet : byte[]) =
use ms = new MemoryStream(packet)
let bf = new BinaryFormatter()
bf.Deserialize(ms)
|> unbox<Response>
member this.Encode() =
use ms = new MemoryStream()
let bf = new BinaryFormatter()
bf.Serialize(ms, this)
ms.GetBuffer()