Inheritance: PyObject
示例#1
0
        private bool ParseRowData(Unmarshal context, BinaryReader source)
        {
            if (Descriptor == null)
            {
                return(false);
            }

            values = new PyRep[Descriptor.Columns.Count];
            var sizeList = Descriptor.Columns.OrderByDescending(c => FieldTypeHelper.GetTypeBits(c.Type));
            var sizeSum  = sizeList.Sum(c => FieldTypeHelper.GetTypeBits(c.Type));

            // align
            sizeSum = (sizeSum + 7) >> 3;
            var rawStream = new MemoryStream();

            // fill up
            rawStream.Write(RawData, 0, RawData.Length);
            for (int i = 0; i < (sizeSum - RawData.Length); i++)
            {
                rawStream.WriteByte(0);
            }
            rawStream.Seek(0, SeekOrigin.Begin);
            var reader = new BinaryReader(rawStream);

            int bitOffset = 0;

            foreach (var column in sizeList)
            {
                PyRep value = null;
                switch (column.Type)
                {
                case FieldType.I8:
                case FieldType.UI8:
                case FieldType.CY:
                case FieldType.FileTime:
                    value = new PyLongLong(reader.ReadInt64());
                    break;

                case FieldType.I4:
                case FieldType.UI4:
                    value = new PyInt(reader.ReadInt32());
                    break;

                case FieldType.I2:
                case FieldType.UI2:
                    value = new PyInt(reader.ReadInt16());
                    break;

                case FieldType.I1:
                case FieldType.UI1:
                    value = new PyInt(reader.ReadByte());
                    break;

                case FieldType.R8:
                    value = new PyFloat(reader.ReadDouble());
                    break;

                case FieldType.R4:
                    value = new PyFloat(reader.ReadSingle());
                    break;

                case FieldType.Bytes:
                case FieldType.Str:
                case FieldType.WStr:
                    value = context.ReadObject(source);
                    break;

                case FieldType.Bool:
                {
                    if (7 < bitOffset)
                    {
                        bitOffset = 0;
                        reader.ReadByte();
                    }

                    var b = reader.ReadByte();
                    reader.BaseStream.Seek(-1, SeekOrigin.Current);
                    value = new PyInt((b >> bitOffset++) & 0x01);
                    break;
                }

                case FieldType.Token:
                    value = new PyToken(column.Token);
                    break;

                default:
                    throw new Exception("No support for " + column.Type);
                }
                int index = Descriptor.Columns.FindIndex(x => x.Name == column.Name);
                values[index] = value;
            }

            return(true);
        }
示例#2
0
        private PyRep analyseType1(PyObjectEx obj, out bool usedList, out bool usedDict)
        {
            usedDict = false;
            usedList = false;
            // Type1
            PyTuple headerTuple = obj.Header as PyTuple;

            if (headerTuple != null && headerTuple.Items.Count > 1)
            {
                int     headerCount = headerTuple.Items.Count;
                PyToken token       = headerTuple.Items[0] as PyToken;
                if (token != null)
                {
                    PyTuple tuple1      = null;
                    int     tuple1Count = 0;
                    if (headerCount > 1)
                    {
                        tuple1 = headerTuple.Items[1] as PyTuple;
                        if (tuple1 != null)
                        {
                            if (headerCount == 3 && token.Token == "eveexceptions.UserError")
                            {
                                return(new UserError(tuple1, headerTuple.Items[2] as PyDict));
                            }
                            tuple1Count = tuple1.Items.Count;
                            if (tuple1Count == 0)
                            {
                                if (headerCount == 3 && token.Token == "carbon.common.script.net.machoNetExceptions.WrongMachoNode")
                                {
                                    return(new WrongMachoNode(headerTuple.Items[2] as PyDict));
                                }
                            }
                            if (tuple1Count == 1)
                            {
                                if (token.Token == "blue.DBRowDescriptor")
                                {
                                    return(new DBRowDescriptor(headerTuple));
                                }
                                PyRep item1 = tuple1.Items[0];
                                if (item1 != null)
                                {
                                    if (token.Token == "__builtin__.set")
                                    {
                                        return(new BuiltinSet(item1 as PyList));
                                    }
                                    if (headerCount == 2 && token.Token == "collections.defaultdict")
                                    {
                                        PyToken tupleToken = item1 as PyToken;
                                        if (tupleToken.Token == "__builtin__.set")
                                        {
                                            usedDict = true;
                                            return(new DefaultDict(obj.Dictionary));
                                        }
                                    }
                                    if (token.Token == "carbon.common.script.net.objectCaching.CacheOK")
                                    {
                                        if (item1.StringValue == "CacheOK")
                                        {
                                            return(new CacheOK());
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (token.Token == "carbon.common.script.net.GPSExceptions.GPSTransportClosed")
                    {
                        return(obj);
                    }
                    unknown.AppendLine("Unknown or malformed token: " + token.Token);
                }
            }
            return(obj);
        }
示例#3
0
        private PyRep analyseType2(PyObjectEx obj, out bool usedList, out bool usedDict)
        {
            usedDict = false;
            usedList = false;
            // type 2
            PyTuple headerTuple = obj.Header as PyTuple;

            if (headerTuple != null && headerTuple.Items.Count > 1)
            {
                int     headerCount = headerTuple.Items.Count;
                PyDict  dict        = headerTuple.Items[1] as PyDict;
                PyToken token       = null;
                PyTuple tokenTuple  = headerTuple.Items[0] as PyTuple;
                if (tokenTuple != null && tokenTuple.Items.Count == 1)
                {
                    token = tokenTuple.Items[0] as PyToken;
                }
                if (token != null)
                {
                    if (headerCount != 2)
                    {
                        unknown.AppendLine("PyObjectEx Type2: headerCount=" + headerCount + " token: " + token.Token);
                    }
                    if (headerCount == 2 && token.Token == "carbon.common.script.sys.crowset.CRowset")
                    {
                        usedList = true;
                        if (dict.Dictionary.Count > 1)
                        {
                            unknown.AppendLine("PyObjectEx Type2: Extra parameters in dict for CRowset");
                        }
                        return(new CRowSet(dict, obj.List));
                    }
                    if (headerCount == 2 && token.Token == "carbon.common.script.sys.crowset.CIndexedRowset")
                    {
                        usedDict = true;
                        if (dict.Dictionary.Count > 2)
                        {
                            unknown.AppendLine("PyObjectEx Type2: Extra parameters in dict for CIndexedRowset");
                        }
                        return(new CIndexedRowset(dict, obj.Dictionary));
                    }
                    if (token.Token == "eve.common.script.dogma.effect.BrainEffect")
                    {
                        return(obj);
                    }
                    if (token.Token == "industry.job.Location")
                    {
                        return(obj);
                    }
                    if (token.Token == "eve.common.script.sys.rowset.RowDict")
                    {
                        return(obj);
                    }
                    if (token.Token == "carbon.common.script.sys.crowset.CFilterRowset")
                    {
                        return(obj);
                    }
                    if (token.Token == "eve.common.script.sys.rowset.RowList")
                    {
                        return(obj);
                    }
                    if (token.Token == "eve.common.script.util.pagedCollection.PagedResultSet")
                    {
                        return(obj);
                    }
                    if (token.Token == "shipskins.storage.LicensedSkin")
                    {
                        return(obj);
                    }
                    if (token.Token == "seasons.common.challenge.Challenge")
                    {
                        return(obj);
                    }
                    unknown.AppendLine("Unknown Token type 2: " + token.Token);
                }
            }
            return(obj);
        }
示例#4
0
 private static string PrintToken(PyToken token)
 {
     return "[PyToken " + token.Token + "]";
 }