MessagePack for C#でシリアライズしたデータをバイト配列に変換

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using SUtils.Serialization;
using SUtils.Serialization.MsgPack;

namespace CsCosnole
{
    class Data
    {
        public int value;
        public string str;

        public Data(int n, string s)
        {
            value = n;
            str = s;
        }
    }

    class Program
    {
        static void Deserialize(byte[] serializedValue)
        {
            MemoryStream stream = new MemoryStream(serializedValue);
        
            ISerializationProvider serializer = new MsgPackSerializationProvider();
            SerializableValue obj = serializer.Deserialize(stream);

            foreach (SerializableValue i in obj.ArrayItems)
            {
                int value = (int)i[0];
                string name = (string)i[1];

                Console.WriteLine("{0}, {1}", value, name);
            }
        }

        static IEnumerable<SerializableValue> DataToList(Data data)
        {
            yield return (SerializableValue)data.value;
            yield return (SerializableValue)data.str;
        }

        static byte[] Serialize()
        {
            ISerializationProvider serializer = new MsgPackSerializationProvider();

            List<Data> ls = new List<Data>() { new Data(1, "a"), new Data(2, "b"), new Data(3, "c") };

            IEnumerable<SerializableValue> datas = ls.Select(x => new SerializableValue(DataToList(x)));

            MemoryStream stream = new MemoryStream();
            serializer.Serialize(stream, new SerializableValue(datas));

            return stream.ToArray();
        }

        static void Main(string[] args)
        {
            byte[] serializedValue = Serialize();
            Deserialize(serializedValue);
        }
    }
}

これをHttpResponse.BinaryWrite()とかでクライアントに送る。