Ejemplo n.º 1
0
        public override object Deserialize(BytePacker packer)
        {
            object data;

            int length = packer.ReadInt();

            if (length < 0)
            {
                return(null);
            }
            else if (length > 0)
            {
                byte[] strData;
                packer.ReadByteArray(out strData, 0, length);

                string text = System.Text.Encoding.UTF8.GetString(strData);

                data = (string)text;
            }
            else
            {
                data = "";
            }
            return(data);
        }
Ejemplo n.º 2
0
        public override object Deserialize(BytePacker packer)
        {
            int length = packer.ReadInt();

            if (length < 0)
            {
                return(null);
            }
            else
            {
                byte[] array;

                packer.ReadByteArray(out array, 0, length);

                return(array);
            }
        }
Ejemplo n.º 3
0
        private static ulong ToTarget(BytePacker packer, int sizeBites, out int size)
        {
            size = 0;

            int   shift  = 0;
            ulong result = 0;
            int   pos    = 0;

            byte[] byteval;
            ulong  byteValue = 0;
            ulong  tmp       = 0;

            while (true)
            {
                packer.ReadByteArray(out byteval, 0, 1);
                pos++;
                byteValue = (ulong)byteval[0];

                tmp     = byteValue & 0x7f;
                result |= tmp << shift;
                size++;

                if (shift > sizeBites)
                {
                    throw new ArgumentOutOfRangeException("stream", "too large.");
                }

                if ((byteValue & 0x80) != 0x80)
                {
                    return(result);
                }

                shift += 7;
            }

            throw new ArgumentException("Cannot decode varint.", "stream");
        }