using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices;
namespace Test
{
class Program
{
static void Main(string[] args)
{
int data1 = 42;
double data2 = 2.12;
string data3 = "Hello, World!";
byte[] bytes = null;
BinaryFormatter bf = new BinaryFormatter();
using(MemoryStream ms = new MemoryStream())
{
bf.Serialize(ms, data1);
bf.Serialize(ms, data2);
bf.Serialize(ms, data3);
bytes = ms.ToArray();
}
Console.WriteLine("{0} bytes", bytes.Length);
bf = new BinaryFormatter();
using(MemoryStream ms = new MemoryStream(bytes))
{
object obj = bf.Deserialize(ms);
Console.WriteLine(data1 == (int)obj);
obj = bf.Deserialize(ms);
Console.WriteLine(data2 == (double)obj);
obj = bf.Deserialize(ms);
Console.WriteLine(data3 == (string)obj);
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5UZXh0Owp1c2luZyBTeXN0ZW0uSU87CnVzaW5nIFN5c3RlbS5SdW50aW1lLlNlcmlhbGl6YXRpb24uRm9ybWF0dGVycy5CaW5hcnk7CnVzaW5nIFN5c3RlbS5SdW50aW1lLkludGVyb3BTZXJ2aWNlczsKCm5hbWVzcGFjZSBUZXN0CnsKICAgIGNsYXNzIFByb2dyYW0KICAgIHsKICAgICAgICBzdGF0aWMgdm9pZCBNYWluKHN0cmluZ1tdIGFyZ3MpCiAgICAgICAgewogICAgICAgICAgICBpbnQgZGF0YTEgPSA0MjsKICAgICAgICAgICAgZG91YmxlIGRhdGEyID0gMi4xMjsKICAgICAgICAgICAgc3RyaW5nIGRhdGEzID0gIkhlbGxvLCBXb3JsZCEiOwogICAgICAgICAgICAKICAgICAgICAgICAgCiAgICAgICAgICAgIGJ5dGVbXSBieXRlcyA9IG51bGw7CiAgICAgICAgICAgIAogICAgICAgICAgICBCaW5hcnlGb3JtYXR0ZXIgYmYgPSBuZXcgQmluYXJ5Rm9ybWF0dGVyKCk7CiAgICAgICAgICAgIHVzaW5nKE1lbW9yeVN0cmVhbSBtcyA9IG5ldyBNZW1vcnlTdHJlYW0oKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYmYuU2VyaWFsaXplKG1zLCBkYXRhMSk7CiAgICAgICAgICAgICAgICBiZi5TZXJpYWxpemUobXMsIGRhdGEyKTsKICAgICAgICAgICAgICAgIGJmLlNlcmlhbGl6ZShtcywgZGF0YTMpOwogICAgICAgICAgICAgICAgYnl0ZXMgPSBtcy5Ub0FycmF5KCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJ7MH0gYnl0ZXMiLCBieXRlcy5MZW5ndGgpOwogICAgICAgICAgICAKICAgICAgICAgICAgCiAgICAgICAgICAgIGJmID0gbmV3IEJpbmFyeUZvcm1hdHRlcigpOwogICAgICAgICAgICB1c2luZyhNZW1vcnlTdHJlYW0gbXMgPSBuZXcgTWVtb3J5U3RyZWFtKGJ5dGVzKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgb2JqZWN0IG9iaiA9IGJmLkRlc2VyaWFsaXplKG1zKTsKICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKGRhdGExID09IChpbnQpb2JqKTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgb2JqID0gYmYuRGVzZXJpYWxpemUobXMpOwogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoZGF0YTIgPT0gKGRvdWJsZSlvYmopOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBvYmogPSBiZi5EZXNlcmlhbGl6ZShtcyk7CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZShkYXRhMyA9PSAoc3RyaW5nKW9iaik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0=