Beispiel #1
0
        public static void Serialize(object item, Stream target)
        {
            MsgPackItem packed = SerializeObject(item);

            byte[] buffer = packed.ToBytes();
            target.Write(buffer, 0, buffer.Length);
            return;
        }
Beispiel #2
0
        public override byte[] ToBytes()
        {
            ArrayList     bytes  = new ArrayList();// cannot estimate this one
            MsgPackTypeId typeId = GetTypeId(value.Length);

            if (typeId == MsgPackTypeId.MpArray4)
            {
                bytes.Add(GetLengthBytes(typeId, value.Length));
            }
            else
            {
                bytes.Add((byte)typeId);
                bytes.AddRange(GetLengthBytes(value.Length, SupportedLengths.FromShortUpward));
            }
            for (int t = 0; t < value.Length; t++)
            {
                MsgPackItem item = MsgPackItem.Pack(value[t]);
                bytes.AddRange(item.ToBytes());
            }
            return((byte[])bytes.ToArray(typeof(byte)));
        }