Esempio n. 1
0
        public override void Decode(Unmarshal context, MarshalOpcode op)
        {
            if (op == MarshalOpcode.ObjectEx2)
            {
                IsType2 = true;
            }

            Dictionary = new Dictionary <PyRep, PyRep>();
            List       = new List <PyRep>();
            Header     = context.ReadObject();

            while (context.reader.BaseStream.Position < context.reader.BaseStream.Length)
            {
                var b = context.reader.ReadByte();
                if (b == PackedTerminator)
                {
                    break;
                }
                context.reader.BaseStream.Seek(-1, SeekOrigin.Current);
                List.Add(context.ReadObject());
            }

            while (context.reader.BaseStream.Position < context.reader.BaseStream.Length)
            {
                var b = context.reader.ReadByte();
                if (b == PackedTerminator)
                {
                    break;
                }
                context.reader.BaseStream.Seek(-1, SeekOrigin.Current);
                var key   = context.ReadObject();
                var value = context.ReadObject();
                Dictionary.Add(key, value);
            }
        }
Esempio n. 2
0
        public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
        {
            var nameObject = context.ReadObject(source);

            if (nameObject.Type != PyObjectType.String)
            {
                throw new DataException("Expected PyString");
            }
            Name = (nameObject as PyString).Value;

            Arguments = context.ReadObject(source);
        }
Esempio n. 3
0
        public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
        {
            var entries = source.ReadSizeEx();

            Dictionary = new Dictionary <PyRep, PyRep>((int)entries);
            for (uint i = 0; i < entries; i++)
            {
                var value = context.ReadObject(source);
                var key   = context.ReadObject(source);
                Dictionary.Add(key, value);
            }
        }
Esempio n. 4
0
        public override void Decode(Unmarshal context, MarshalOpcode op)
        {
            int count = -1;

            switch (op)
            {
            case MarshalOpcode.TupleEmpty:
                count = 0;
                break;

            case MarshalOpcode.TupleOne:
                count = 1;
                break;

            case MarshalOpcode.TupleTwo:
                count = 2;
                break;

            case MarshalOpcode.Tuple:
                count = (int)context.reader.ReadSizeEx();
                break;
            }

            if (count >= 0)
            {
                Items = new List <PyRep>(count);
                for (int i = 0; i < count; i++)
                {
                    Items.Add(context.ReadObject());
                }
            }
        }
Esempio n. 5
0
        public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
        {
            int count = -1;

            switch (op)
            {
            case MarshalOpcode.ListEmpty:
                count = 0;
                break;

            case MarshalOpcode.ListOne:
                count = 1;
                break;

            case MarshalOpcode.List:
                count = (int)source.ReadSizeEx();
                break;
            }

            if (count >= 0)
            {
                Items = new List <PyRep>(count);
                for (int i = 0; i < count; i++)
                {
                    Items.Add(context.ReadObject(source));
                }
            }
        }
Esempio n. 6
0
        public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
        {
            PyRep obj = context.ReadObject(source);

            Descriptor = obj as DBRowDescriptor;
            if (Descriptor == null)
            {
                throw new InvalidDataException("PyPackedRow: Header must be DBRowDescriptor got " + obj.Type);
            }
            RawData = LoadZeroCompressed(source);

            if (!ParseRowData(context, source))
            {
                throw new InvalidDataException("Could not fully unpack PackedRow, stream integrity is broken");
            }
        }
Esempio n. 7
0
        public override void Decode(Unmarshal context, MarshalOpcode op)
        {
            PyRep obj = context.ReadObject();

            Descriptor = obj as DBRowDescriptor;
            if (Descriptor == null)
            {
                if (!context.analizeInput && obj is PyObjectEx)
                {
                    DescriptorObj = obj;
                }
                else
                {
                    throw new InvalidDataException("PyPackedRow: Header must be DBRowDescriptor got " + obj.Type);
                }
            }
            RawData = LoadZeroCompressed(context);

            if (!ParseRowData(context))
            {
                throw new InvalidDataException("Could not fully unpack PackedRow, stream integrity is broken");
            }
        }
Esempio n. 8
0
 public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
 {
     Checksum = source.ReadUInt32();
     Data     = context.ReadObject(source);
 }
Esempio n. 9
0
 public override void Decode(Unmarshal context, MarshalOpcode op)
 {
     Checksum = context.reader.ReadUInt32();
     Data     = context.ReadObject();
 }
Esempio n. 10
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);
        }
Esempio n. 11
0
 public override void Decode(Unmarshal context, MarshalOpcode op)
 {
     Definition = context.ReadObject();
 }
Esempio n. 12
0
 public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
 {
     Definition = context.ReadObject(source);
 }