Exemple #1
0
            object YieldSimple()
            {
                object res;

                switch ((char)myBytes[curIndex++])
                {
                // simple ops to be read in
                case 'i': res = ReadInt(); break;

                case 'l': res = ReadBigInteger(); break;

                case 'T': res = Ops.TRUE; break;

                case 'F': res = Ops.FALSE; break;

                case 'f': res = ReadFloat(); break;

                case 't': res = ReadAsciiString(); break;

                case 'u': res = ReadUnicodeString(); break;

                case 'S': res = ExceptionConverter.GetPythonExceptionByName("StopIteration"); break;

                case 'N': res = null; break;

                case 'x': res = ReadComplex(); break;

                case 's': res = ReadBuffer(); break;

                case 'I': res = ReadLong(); break;

                default: throw Ops.ValueError("bad marshal data");
                }
                return(res);
            }
Exemple #2
0
            public void WriteObject(object o)
            {
                ArrayList infinite = Ops.GetReprInfinite();

                if (infinite.Contains(o))
                {
                    throw Ops.ValueError("Marshaled data contains infinite cycle");
                }

                int index = infinite.Add(o);

                try {
                    if (o == null)
                    {
                        bytes.Add((byte)'N');
                    }
                    else if (o == Ops.TRUE)
                    {
                        bytes.Add((byte)'T');
                    }
                    else if (o == Ops.FALSE)
                    {
                        bytes.Add((byte)'F');
                    }
                    else if (o is string)
                    {
                        WriteString(o as string);
                    }
                    else if (o is int)
                    {
                        WriteInt((int)o);
                    }
                    else if (o is float)
                    {
                        WriteFloat((float)o);
                    }
                    else if (o is double)
                    {
                        WriteFloat((double)o);
                    }
                    else if (o is long)
                    {
                        WriteLong((long)o);
                    }
                    else if (o is List)
                    {
                        WriteList(o);
                    }
                    else if (o is Dict)
                    {
                        WriteDict(o);
                    }
                    else if (o is Tuple)
                    {
                        WriteTuple(o);
                    }
                    else if (o is BigInteger)
                    {
                        WriteInteger((BigInteger)o);
                    }
                    else if (o is Complex64)
                    {
                        WriteComplex((Complex64)o);
                    }
                    else if (o is PythonBuffer)
                    {
                        WriteBuffer((PythonBuffer)o);
                    }
                    else if (o == ExceptionConverter.GetPythonExceptionByName("StopIteration"))
                    {
                        WriteStopIteration();
                    }
                    else
                    {
                        throw Ops.ValueError("unmarshallable object");
                    }
                } finally {
                    infinite.RemoveAt(index);
                }
            }