Example #1
0
        // http://svn.python.org/projects/python/tags/r32/Lib/pickle.py
        private static bool ReadPickle(ReadAheadBinaryReader reader, out long result)
        {
            if (reader.Length < 2)
            {
                result = 0;
                return(false);
            }

            if (reader.ReadByte() != 128 || reader.ReadByte() != 3)
            {
                result = 0;
                return(false);
            }

            switch (reader.ReadByte())
            {
            case (byte)'F':
                result = (long)reader.ReadSingle();
                return(true);

            case (byte)'N':
                result = 0;
                return(true);

            case (byte)'I':
            case (byte)'J':
                result = reader.ReadInt32();
                return(true);

            case (byte)'L':
                result = reader.ReadInt64();
                return(true);

            case (byte)'M':
                result = reader.ReadUInt16();
                return(true);

            case (byte)'K':
                result = reader.ReadByte();
                return(true);
            }

            result = 0;
            return(false);
        }