Inheritance: PyObject
Beispiel #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);
        }
Beispiel #2
0
 private static string PrintLongLong(PyLongLong ll)
 {
     return "[PyLongLong " + ll.Value + "]";
 }