I have a jagged array DataMember
that returns byte[800][10000][1]
which translates to ~8MB of data. When serialized using DataContractSerializer
it turns into a file size 120MB for Binary and 300MB for Text. Looking at the text serialization, it indicates that it puts a tag around every byte value to indicate that its a base64 encoded value etc., which might be the reason for this size enlargement.
What is an efficient way to serialize a large jagged blob using DataContractSerializer
(or any other serializer for that matter)
snippet XML output when serialized using Text:
<a:ArrayOfbase64Binary><a:base64Binary>CQ==</a:base64Binary><a:base64Binary>Bw==</a:base64Binary><a:base64Binary>BQ==</a:base64Binary><a:base64Binary>AA==</a:base64Binary><a:base64Binary>AQ==</a:base64Binary><a:base64Binary>AA==</a:base64Binary><a:base64Binary>BA==</a:base64Binary><a:base64Binary>Bg==</a:base64Binary><a:base64Binary>CA==</a:base64Binary><a:base64Binary>AA==</a:base64Binary><a:base64Binary>AA==</a:base64Binary><a:base64Binary>AA==</a:base64Binary><a:base64Binary>AA==</a:base64Binary><a:base64Binary>AA==</a:base64Binary><a:base64Binary>AA==</a:base64Binary><a:base64Binary>AA==</a:base64Binary>
You could try using a BinaryFormatter
if you don't care about interoperability with other systems but only about performance:
byte[800][10000][1] foo = ... fetch it
BinaryFormatter formatter = new BinaryFormatter();
using (var stream = File.OpenWrite("foobar.dat"))
{
formatter.Serialize(stream, foo);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With