Example #1
0
        public Scl(IStreamReader reader, RecordType id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.nscl = reader.ReadInt16();
            this.dscl = reader.ReadInt16();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #2
0
        public MainWindow(IStreamReader reader, GraphRecordNumber id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.wLeft   = reader.ReadInt16();
            this.wTop    = reader.ReadInt16();
            this.wWidth  = reader.ReadInt16();
            this.wHeight = reader.ReadInt16();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #3
0
        internal static void SkipTypeMetaInfo(IStreamReader reader)
        {
            byte metaTypeVersion = reader.ReadUInt8();

            if (metaTypeVersion == SingleTypeDescr)
            {
                reader.SkipString(); // skip assembly name
                reader.SkipString(); // skip type name

                short itemCount = reader.ReadInt16();

                for (int i = 0; i < itemCount; i++)
                {
                    SkipPropertyMetaInfo(reader);
                }
            }
            else if (metaTypeVersion == CollectionTypeDescr)
            {
                reader.SkipString(); // skip assembly name
                reader.SkipString(); // skip type name
            }
            else
            {
                throw new NotSupportedException($"Type meta information version {metaTypeVersion} not supported!");
            }
        }
Example #4
0
 /// <summary>
 /// Reads the value.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns>System.Object.</returns>
 public override object ReadValue(IStreamReader reader, ISerializeContext context)
 {
     return(NullableRead(reader, () =>
     {
         return reader.ReadInt16();
     }));
 }
Example #5
0
        public Selection(IStreamReader reader, RecordType id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.pnn     = (PaneType)reader.ReadByte();
            this.rwAct   = reader.ReadUInt16();
            this.colAct  = reader.ReadUInt16();
            this.irefAct = reader.ReadInt16();
            this.cref    = reader.ReadUInt16();

            if (this.cref > 0)
            {
                this.rgref = new RefU[this.cref];
                for (int i = 0; i < this.cref; i++)
                {
                    this.rgref[i] = new RefU(reader);
                }
            }

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #6
0
 public BkHim(IStreamReader reader, RecordType id, ushort length)
     : base(reader, id, length)
 {
     this.cf = (ImageFormat)reader.ReadInt16();
     reader.ReadBytes(2); // skip 2 bytes
     this.lcb       = reader.ReadInt32();
     this.imageBlob = reader.ReadBytes(this.lcb);
 }
Example #7
0
        public Window1(IStreamReader reader, GraphRecordNumber id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.xWn  = reader.ReadInt16();
            this.yWn  = reader.ReadInt16();
            this.dxWn = reader.ReadUInt16();
            this.dyWn = reader.ReadUInt16();

            // skipped reserved and unused bytes
            reader.ReadBytes(10);

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #8
0
        public CatSerRange(IStreamReader reader, RecordType id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.catCross = reader.ReadInt16();
            this.catLabel = reader.ReadInt16();
            this.catMark  = reader.ReadInt16();

            ushort flags = reader.ReadUInt16();

            this.fBetween  = Utils.BitmaskToBool(flags, 0x0001);
            this.fMaxCross = Utils.BitmaskToBool(flags, 0x0002);
            this.fReverse  = Utils.BitmaskToBool(flags, 0x0004);

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #9
0
        public BopPop(IStreamReader reader, GraphRecordNumber id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.pst            = (Subtype)reader.ReadByte();
            this.fAutoSplit     = !(reader.ReadByte() == 0x0);
            this.split          = (SplitType)reader.ReadUInt16();
            this.iSplitPos      = reader.ReadInt16();
            this.pcSplitPercent = reader.ReadInt16();
            this.pcPie2Size     = reader.ReadInt16();
            this.pcGap          = reader.ReadInt16();
            this.numSplitValue  = reader.ReadDouble();
            this.fHasShadow     = Utils.BitmaskToBool(reader.ReadUInt16(), 0x0001);

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #10
0
        public ChartColors(IStreamReader reader, GraphRecordNumber id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.icvMac = reader.ReadInt16();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #11
0
        public PieFormat(IStreamReader reader, GraphRecordNumber id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.pcExplode = reader.ReadInt16();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #12
0
        public LineFormat(IStreamReader reader, GraphRecordNumber id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.rgb = new RGBColor(reader.ReadInt32(), RGBColor.ByteOrder.RedFirst);
            this.lns = (LineStyle)reader.ReadInt16();
            this.we  = (LineWeight)reader.ReadInt16();
            ushort flags = reader.ReadUInt16();

            this.fAuto = Utils.BitmaskToBool(flags, 0x1);
            // 0x2 is reserved
            this.fAxisOn = Utils.BitmaskToBool(flags, 0x4);
            this.fAutoCo = Utils.BitmaskToBool(flags, 0x8);
            this.icv     = reader.ReadUInt16();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #13
0
        public ControlInfo(IStreamReader reader)
        {
            ushort flags = reader.ReadUInt16();

            this.fDefault = Utils.BitmaskToBool(flags, 0x0001);
            this.fHelp    = Utils.BitmaskToBool(flags, 0x0002);
            this.fCancel  = Utils.BitmaskToBool(flags, 0x0004);
            this.fDismiss = Utils.BitmaskToBool(flags, 0x0008);

            this.accel1 = reader.ReadInt16();

            reader.ReadBytes(2);
        }
Example #14
0
        public Palette(IStreamReader reader, GraphRecordNumber id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.ccv     = reader.ReadInt16();
            this.rgColor = new RGBColor[this.ccv];
            for (int i = 0; i < this.ccv; i++)
            {
                this.rgColor[i] = new RGBColor(reader.ReadInt32(), RGBColor.ByteOrder.RedFirst);
            }

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #15
0
        public YMult(IStreamReader reader, RecordType id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.frtHeaderOld       = new FrtHeaderOld(reader);
            this.axmid              = (AxisMultiplier)reader.ReadInt16();
            this.numLabelMultiplier = reader.ReadDouble();

            ushort flags = reader.ReadUInt16();

            this.fAutoShowMultiplier = Utils.BitmaskToBool(flags, 0x0002);
            this.fBeingEdited        = Utils.BitmaskToBool(flags, 0x0004);

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #16
0
        public Bar(IStreamReader reader, GraphRecordNumber id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.pcOverlap = reader.ReadInt16();
            this.pcGap     = reader.ReadUInt16();

            UInt16 flags = reader.ReadUInt16();

            this.fTranspose = Utils.BitmaskToBool(flags, 0x1);
            this.fStacked   = Utils.BitmaskToBool(flags, 0x2);
            this.f100       = Utils.BitmaskToBool(flags, 0x4);
            this.fHasShadow = Utils.BitmaskToBool(flags, 0x8);

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #17
0
        public PicF(IStreamReader reader, RecordType id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.ptyp = (LayoutType)reader.ReadInt16();
            reader.ReadBytes(2); //unused
            ushort flags = reader.ReadUInt16();

            // first 9 bits are reserved
            this.fTopBottom = Utils.BitmaskToBool(flags, 0x200);
            this.fBackFront = Utils.BitmaskToBool(flags, 0x400);
            this.fSide      = Utils.BitmaskToBool(flags, 0x800);
            this.numScale   = reader.ReadDouble();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #18
0
        public Pos(IStreamReader reader, RecordType id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.mdTopLt = (PositionMode)reader.ReadInt16();
            this.mdBotRt = (PositionMode)reader.ReadInt16();
            this.x1      = reader.ReadInt16();
            reader.ReadBytes(2); // skip 2 bytes
            this.y1 = reader.ReadInt16();
            reader.ReadBytes(2); // skip 2 bytes
            this.x2 = reader.ReadInt16();
            reader.ReadBytes(2); // skip 2 bytes
            this.y2 = reader.ReadInt16();
            reader.ReadBytes(2); // skip 2 bytes

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Example #19
0
        private void ReadData(int dataTypeCd, WireMessage message, IStreamReader reader)
        {
            switch ((TypeCode)dataTypeCd)
            {
            case TypeCode.Boolean:
                message.Data = reader.ReadBoolean();
                break;

            case TypeCode.Byte:
                message.Data = reader.ReadByte();
                break;

            case TypeCode.Char:
                message.Data = reader.ReadChar();
                break;

            case TypeCode.DateTime:
                message.Data = new DateTime(reader.ReadInt64());
                break;

            case TypeCode.DBNull:
                reader.ReadByte();
                message.Data = DBNull.Value;
                break;

            case TypeCode.Decimal:
                message.Data = reader.ReadDecimal();
                break;

            case TypeCode.Double:
                message.Data = reader.ReadDouble();
                break;

            case TypeCode.Empty:
                reader.ReadByte();
                break;

            case TypeCode.Int16:
                message.Data = reader.ReadInt16();
                break;

            case TypeCode.Int32:
                message.Data = reader.ReadInt32();
                break;

            case TypeCode.Int64:
                message.Data = reader.ReadInt64();
                break;

            case TypeCode.SByte:
                message.Data = reader.ReadSByte();
                break;

            case TypeCode.Single:
                message.Data = reader.ReadSingle();
                break;

            case TypeCode.String:
                message.Data = ReadString(reader);
                break;

            case TypeCode.UInt16:
                message.Data = reader.ReadUInt16();
                break;

            case TypeCode.UInt32:
                message.Data = reader.ReadUInt32();
                break;

            case TypeCode.UInt64:
                message.Data = reader.ReadUInt64();
                break;

            default:
            {
                var len = reader.ReadInt32();
                if (len > 0)
                {
                    using (var tempStream = new ChunkedStream())
                    {
                        var chunkSize = tempStream.ChunkSize;
                        while (len > 0)
                        {
                            var bytes = reader.ReadBytes(chunkSize);

                            var readLen = bytes?.Length ?? 0;
                            if (readLen == 0)
                            {
                                throw new Exception(SerializationErrors.StreamNotContainingValidWireMessage);
                            }

                            len -= readLen;
                            tempStream.Write(bytes, 0, readLen);
                        }

                        tempStream.Position = 0;
                        message.Data        = GetSerializer().Deserialize(tempStream);
                    }
                }
            }
            break;
            }
        }
Example #20
0
 public FixedPointNumber(IStreamReader reader)
 {
     // DEVIATION: The order of fractional and integral part is different as specified.
     this.fractional = reader.ReadUInt16();
     this.integral   = reader.ReadInt16();
 }
Example #21
0
        internal static IValueItem ReadTypeMetaInfo(IStreamReader reader, uint typeId, ISerializeContext ctx)
        {
            byte metaTypeVersion = reader.ReadUInt8();

            string assemblyName;
            string typeFullName;
            Type   type;

            if (metaTypeVersion == SingleTypeDescr)
            {
                assemblyName = reader.ReadString();
                typeFullName = reader.ReadString();

                if (!TypeService.TryGetTypeByName(typeFullName, out type, ctx.Serializer.CustomLookupAssemblies))
                {
                    if (ctx.Serializer.AutoCreateMissingTypes)
                    {
                        return(AutoCreateMissingDeserializeType(typeId, assemblyName, typeFullName, reader, ctx));
                    }
                    else
                    {
                        throw new TypeAccessException($"Type {typeFullName} not found!");
                    }
                }

                IValueItem resultItem = ctx.GetByType(type);

                if (resultItem is ITypeStructure)
                {
                    ITypeStructure result = (ITypeStructure)resultItem;

                    short itemCount = reader.ReadInt16();

                    if (result.TypeId == typeId)
                    {
                        // internal type is equal remote type
                        for (int i = 0; i < itemCount; i++)
                        {
                            SkipPropertyMetaInfo(reader);
                        }

                        return(result);
                    }
                    else
                    {
                        // differences between local type and remote type

                        // read actual structure and try map to old/new structure
                        ComplexStructure tolerantLayoutStructure = ComplexStructure.CreateTolerantLayoutStructure(type, ctx);

                        for (int i = 0; i < itemCount; i++)
                        {
                            ItemType itemType       = (ItemType)reader.ReadInt16(); // ItemType Enum
                            uint     propertyTypeId = reader.ReadUInt32();          // TypeId (Type Hash)
                            string   propertyName   = reader.ReadString();          // Property Name
                            bool     isNullable     = reader.ReadBool();            // Nullable Flag

                            IValueItem nameMatchingItem = result.Items.Where(item => item.Name == propertyName).FirstOrDefault();

                            if (nameMatchingItem != null)
                            {
                                bool typeMatch       = itemType == nameMatchingItem.Type;
                                bool typeIdMatch     = propertyTypeId == nameMatchingItem.TypeId;
                                bool nullableMatch   = isNullable == nameMatchingItem.IsNullable;
                                bool fromNotNullable = !isNullable && nameMatchingItem.IsNullable;

                                if (typeMatch &&
                                    typeIdMatch &&
                                    nullableMatch)
                                {
                                    // Property has exactly the same attributes > no conversion required
                                    tolerantLayoutStructure.AddTolerantLayoutProperty(ctx, propertyName);
                                }
                                else if (typeMatch &&
                                         typeIdMatch &&
                                         !nullableMatch &&
                                         fromNotNullable)
                                {
                                    // Property changed only from not nullable to nullable
                                    tolerantLayoutStructure.AddTolerantLayoutConverterProperty(nameMatchingItem, ctx, propertyName, itemType, propertyTypeId, isNullable, v => v);
                                }
                                else if (!typeMatch &&
                                         !typeIdMatch &&
                                         (nullableMatch || fromNotNullable))
                                {
                                    // Only property type changed
                                    // Check if type can be converted without loosing data
                                    Func <object, object> converter = null;
                                    if (itemType == ItemType.Int32 &&
                                        nameMatchingItem.Type == ItemType.Int64)
                                    {
                                        // Read incoming Int32 and convert to local Int64 property
                                        converter = v => (long)(int)v;
                                    }
                                    else if (itemType == ItemType.Int16 &&
                                             nameMatchingItem.Type == ItemType.Int32)
                                    {
                                        // Read incoming Int16 and convert to local Int32 property
                                        converter = v => (int)(short)v;
                                    }
                                    else if (itemType == ItemType.Byte &&
                                             nameMatchingItem.Type == ItemType.Int16)
                                    {
                                        // Read incoming Byte and convert to local Int16 property
                                        converter = v => (short)(byte)v;
                                    }
                                    else if (itemType == ItemType.Double &&
                                             nameMatchingItem.Type == ItemType.Decimal)
                                    {
                                        // Read incoming Double and convert to local Decimal property
                                        converter = v => (decimal)(double)v;
                                    }
                                    else if (itemType == ItemType.Char &&
                                             nameMatchingItem.Type == ItemType.String)
                                    {
                                        // Read incoming Char and convert to local String property
                                        converter = v => new string(new char[] { (char)v });
                                    }

                                    if (converter != null)
                                    {
                                        tolerantLayoutStructure.AddTolerantLayoutConverterProperty(nameMatchingItem, ctx, propertyName, itemType, propertyTypeId, isNullable, converter);
                                    }
                                }
                            }
                            else
                            {
                                // no name matching property found (removed, renamed or old local version) > create dummy item
                                tolerantLayoutStructure.AddTolerantLayoutDummyProperty(ctx, propertyName, itemType, propertyTypeId, isNullable);
                            }
                        }

                        tolerantLayoutStructure.FinalizeTolerantLayoutStructure();
                        if (typeId == tolerantLayoutStructure.TypeId)
                        {
                            // Tolerant mapping was successful
                            // Register only type ID in global cache
                            BinarySerializer.RegisterTolerantTypeMapping(tolerantLayoutStructure);

                            return(tolerantLayoutStructure);
                        }
                        else
                        {
                            // Can't map old/new structure to incoming type meta data
                            throw new FormatException($"The incoming binary format does not match the loaded type {type.FullName}! An tolerant mapping was not possible. Please update the remote or local interface assemblies. Expected Type Id: {result.TypeId}; Received Type Id: {typeId}");
                        }
                    }
                }
                else if (resultItem is ITypePrefix)
                {
                    // Only type prefix - e.g. enum
                    ITypePrefix result = (ITypePrefix)resultItem;

                    short itemCount = reader.ReadInt16();

                    if (result.TypeId == typeId)
                    {
                        // internal type is equal remote type
                        for (int i = 0; i < itemCount; i++)
                        {
                            SkipPropertyMetaInfo(reader);
                        }

                        return(result);
                    }
                    else
                    {
                        throw new FormatException($"The incoming binary format does not match the loaded type {type.FullName}! An tolerant mapping was not possible. Please update the remote or local interface assemblies. Expected Type Id: {result.TypeId}; Received Type Id: {typeId}");
                    }
                }
                else
                {
                    return(resultItem);
                }
            }
            else if (metaTypeVersion == CollectionTypeDescr)
            {
                assemblyName = reader.ReadString();
                typeFullName = reader.ReadString();

                //todo: load assembly if required
                if (TypeService.TryGetTypeByName(typeFullName, out type))
                {
                    CollectionItems result = (CollectionItems)ctx.GetByType(type);

                    if (result.TypeId == typeId)
                    {
                        return(result);
                    }
                    else
                    {
                        // differences between local type and remote type
                        //todo: implement
                        throw new NotImplementedException($"Support for different binary layout is not implemented yet! Local Type ID: {result.TypeId}; Remote Type ID: {typeId}");
                    }
                }
                else
                {
                    throw new TypeAccessException($"Type {typeFullName} not found!");
                }
            }
            else
            {
                throw new NotSupportedException($"Type meta information version {metaTypeVersion} not supported!");
            }
        }