Exemplo n.º 1
0
        public static WriteTaskItem UnPack(System.IO.Stream stream)
        {
            WriteTaskItem item = new WriteTaskItem();

            item.op = (WriteTaskOP)(byte)stream.ReadByte();
            byte lenID  = (byte)stream.ReadByte();
            byte lenKey = (byte)stream.ReadByte();

            byte[] bufLenValue = new byte[4];
            stream.Read(bufLenValue, 0, 4);
            UInt32 lenvalue = BitConverter.ToUInt32(bufLenValue, 0);

            item.tableID = new byte[lenID];
            item.key     = new byte[lenKey];
            item.value   = new byte[lenvalue];
            if (lenID > 0)
            {
                stream.Read(item.tableID, 0, lenID);
            }
            if (lenKey > 0)
            {
                stream.Read(item.key, 0, lenKey);
            }
            if (lenvalue > 0)
            {
                stream.Read(item.value, 0, (int)lenvalue);
            }
            return(item);
        }
Exemplo n.º 2
0
        public static WriteTask UnPack(System.IO.Stream stream)
        {
            var task     = new WriteTask();
            var extcount = stream.ReadByte();

            if (extcount > 0)
            {
                task.extData = new Dictionary <string, byte[]>();
            }
            for (var i = 0; i < extcount; i++)
            {
                var    numkey   = stream.ReadByte();
                byte[] bufnum   = new byte[4];
                var    numv     = stream.Read(bufnum, 0, 4);
                UInt32 numValue = BitConverter.ToUInt32(bufnum, 0);
                byte[] bufv     = new byte[Math.Max(numkey, numValue)];
                stream.Read(bufv, 0, numkey);
                var strkey = System.Text.Encoding.UTF8.GetString(bufv, 0, numkey);
                stream.Read(bufv, 0, (int)numValue);
                task.extData[strkey] = bufv;
            }
            byte[] bufnumitem = new byte[2];
            stream.Read(bufnumitem, 0, 2);
            var numitem = BitConverter.ToUInt16(bufnumitem, 0);

            for (var i = 0; i < numitem; i++)
            {
                task.items.Add(WriteTaskItem.UnPack(stream));
            }
            return(task);
        }