byte[] data = new byte[] { 1 };
using (var stream = new MemoryStream()) {
var formatter = new BinaryFormatter();
stream.Write(data, 0, data.Length);
stream.Position = 0;
stream.Seek(0, SeekOrigin.Begin);
var endDataPacket = (byte)formatter.Deserialize(stream);
}
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace stream_to_any
{
class Program
{
static void Main(string[] args)
{
var data = new byte[] { 1, 2 };
using (var stream = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(stream, data);
stream.Seek(0, SeekOrigin.Begin);
var endDataPacket = (byte[])formatter.Deserialize(stream);
Console.WriteLine(endDataPacket.GetType().ToString());
foreach(var d in endDataPacket)
Console.WriteLine(d);
}
}
}
}