internal ObjectMap(string objectName, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
 {
     this.isInitObjectInfo = true;
     this.objectName = objectName;
     this.memberNames = memberNames;
     this.binaryTypeEnumA = binaryTypeEnumA;
     this.typeInformationA = typeInformationA;
     this.objectReader = objectReader;
     this.objectId = objectId;
     this.assemblyInfo = assemblyInfo;
     if (assemblyInfo == null)
     {
         throw new SerializationException(Environment.GetResourceString("Serialization_Assembly", new object[] { objectName }));
     }
     this.objectType = objectReader.GetType(assemblyInfo, objectName);
     this.memberTypes = new Type[memberNames.Length];
     for (int i = 0; i < memberNames.Length; i++)
     {
         InternalPrimitiveTypeE ee;
         string str;
         Type type;
         bool flag;
         BinaryConverter.TypeFromInfo(binaryTypeEnumA[i], typeInformationA[i], objectReader, (BinaryAssemblyInfo) assemIdToAssemblyTable[memberAssemIds[i]], out ee, out str, out type, out flag);
         this.memberTypes[i] = type;
     }
     this.objectInfo = objectReader.CreateReadObjectInfo(this.objectType, memberNames, null);
     if (!this.objectInfo.isSi)
     {
         this.objectInfo.GetMemberTypes(memberNames, this.objectInfo.objectType);
     }
 }
 internal void Set(int objectId, int rank, int[] lengthA, int[] lowerBoundA, BinaryTypeEnum binaryTypeEnum, object typeInformation, BinaryArrayTypeEnum binaryArrayTypeEnum, int assemId)
 {
     this.objectId = objectId;
     this.binaryArrayTypeEnum = binaryArrayTypeEnum;
     this.rank = rank;
     this.lengthA = lengthA;
     this.lowerBoundA = lowerBoundA;
     this.binaryTypeEnum = binaryTypeEnum;
     this.typeInformation = typeInformation;
     this.assemId = assemId;
     this.binaryHeaderEnum = BinaryHeaderEnum.Array;
     if (binaryArrayTypeEnum == BinaryArrayTypeEnum.Single)
     {
         if (binaryTypeEnum == BinaryTypeEnum.Primitive)
         {
             this.binaryHeaderEnum = BinaryHeaderEnum.ArraySinglePrimitive;
         }
         else if (binaryTypeEnum == BinaryTypeEnum.String)
         {
             this.binaryHeaderEnum = BinaryHeaderEnum.ArraySingleString;
         }
         else if (binaryTypeEnum == BinaryTypeEnum.Object)
         {
             this.binaryHeaderEnum = BinaryHeaderEnum.ArraySingleObject;
         }
     }
 }
 internal bool GetNext(out BinaryTypeEnum outBinaryTypeEnum, out object outTypeInformation)
 {
     outBinaryTypeEnum = BinaryTypeEnum.Primitive;
     outTypeInformation = null;
     if (this.objectTypeEnum == InternalObjectTypeE.Array)
     {
         if (this.count == this.numItems)
         {
             return false;
         }
         outBinaryTypeEnum = this.binaryTypeEnum;
         outTypeInformation = this.typeInformation;
         if (this.count == 0)
         {
             this.isInitial = false;
         }
         this.count++;
         return true;
     }
     if ((this.count == this.memberLength) && !this.isInitial)
     {
         return false;
     }
     outBinaryTypeEnum = this.binaryTypeEnumA[this.count];
     outTypeInformation = this.typeInformationA[this.count];
     if (this.count == 0)
     {
         this.isInitial = false;
     }
     this.name = this.memberNames[this.count];
     Type[] memberTypes = this.memberTypes;
     this.dtType = this.memberTypes[this.count];
     this.count++;
     return true;
 }
Example #4
0
        internal void Init()
        {
            _isInitial = false;
            _count = 0;
            _expectedType = BinaryTypeEnum.ObjectUrt;
            _expectedTypeInformation = null;

            _name = null;
            _objectTypeEnum = InternalObjectTypeE.Empty;
            _memberTypeEnum = InternalMemberTypeE.Empty;
            _memberValueEnum = InternalMemberValueE.Empty;
            _dtType = null;

            // Array Information
            _numItems = 0;

            //binaryTypeEnum
            _typeInformation = null;

            // Member Information
            _memberLength = 0;
            _binaryTypeEnumA = null;
            _typeInformationA = null;
            _memberNames = null;
            _memberTypes = null;

            _pr.Init();
        }
        public void Read(__BinaryParser input)
        {
            switch (this.binaryHeaderEnum)
            {
                case BinaryHeaderEnum.ArraySinglePrimitive:
                    this.objectId = input.ReadInt32();
                    this.lengthA = new int[] { input.ReadInt32() };
                    this.binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                    this.rank = 1;
                    this.lowerBoundA = new int[this.rank];
                    this.binaryTypeEnum = BinaryTypeEnum.Primitive;
                    this.typeInformation = (InternalPrimitiveTypeE) input.ReadByte();
                    return;

                case BinaryHeaderEnum.ArraySingleObject:
                    this.objectId = input.ReadInt32();
                    this.lengthA = new int[] { input.ReadInt32() };
                    this.binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                    this.rank = 1;
                    this.lowerBoundA = new int[this.rank];
                    this.binaryTypeEnum = BinaryTypeEnum.Object;
                    this.typeInformation = null;
                    return;

                case BinaryHeaderEnum.ArraySingleString:
                    this.objectId = input.ReadInt32();
                    this.lengthA = new int[] { input.ReadInt32() };
                    this.binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                    this.rank = 1;
                    this.lowerBoundA = new int[this.rank];
                    this.binaryTypeEnum = BinaryTypeEnum.String;
                    this.typeInformation = null;
                    return;
            }
            this.objectId = input.ReadInt32();
            this.binaryArrayTypeEnum = (BinaryArrayTypeEnum) input.ReadByte();
            this.rank = input.ReadInt32();
            this.lengthA = new int[this.rank];
            this.lowerBoundA = new int[this.rank];
            for (int i = 0; i < this.rank; i++)
            {
                this.lengthA[i] = input.ReadInt32();
            }
            if (((this.binaryArrayTypeEnum == BinaryArrayTypeEnum.SingleOffset) || (this.binaryArrayTypeEnum == BinaryArrayTypeEnum.JaggedOffset)) || (this.binaryArrayTypeEnum == BinaryArrayTypeEnum.RectangularOffset))
            {
                for (int j = 0; j < this.rank; j++)
                {
                    this.lowerBoundA[j] = input.ReadInt32();
                }
            }
            this.binaryTypeEnum = (BinaryTypeEnum) input.ReadByte();
            this.typeInformation = BinaryConverter.ReadTypeInfo(this.binaryTypeEnum, input, out this.assemId);
        }
        internal void Set(int objectId, string name, int numMembers, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object[] typeInformationA, int[] memberAssemIds, int assemId)
        {
            _objectId = objectId;
            _assemId = assemId;
            _name = name;
            _numMembers = numMembers;
            _memberNames = memberNames;
            _binaryTypeEnumA = binaryTypeEnumA;
            _typeInformationA = typeInformationA;
            _memberAssemIds = memberAssemIds;
            _assemId = assemId;

            _binaryHeaderEnum = assemId > 0 ?
                 BinaryHeaderEnum.ObjectWithMapTypedAssemId :
                 BinaryHeaderEnum.ObjectWithMapTyped;
        }
Example #7
0
        // Specifies what is to parsed next from the wire.
        internal bool GetNext(out BinaryTypeEnum outBinaryTypeEnum, out object outTypeInformation)
        {
            //Initialize the out params up here.
            outBinaryTypeEnum = BinaryTypeEnum.Primitive;
            outTypeInformation = null;

            if (_objectTypeEnum == InternalObjectTypeE.Array)
            {
                // Array
                if (_count == _numItems)
                {
                    return false;
                }
                else
                {
                    outBinaryTypeEnum = _binaryTypeEnum;
                    outTypeInformation = _typeInformation;
                    if (_count == 0)
                        _isInitial = false;
                    _count++;
                    return true;
                }
            }
            else
            {
                // Member
                if ((_count == _memberLength) && (!_isInitial))
                {
                    return false;
                }
                else
                {
                    outBinaryTypeEnum = _binaryTypeEnumA[_count];
                    outTypeInformation = _typeInformationA[_count];
                    if (_count == 0)
                    {
                        _isInitial = false;
                    }
                    _name = _memberNames[_count];
                    _dtType = _memberTypes[_count];
                    _count++;
                    return true;
                }
            }
        }
 internal void Set(int objectId, string name, int numMembers, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object[] typeInformationA, int[] memberAssemIds, int assemId)
 {
     this.objectId = objectId;
     this.assemId = assemId;
     this.name = name;
     this.numMembers = numMembers;
     this.memberNames = memberNames;
     this.binaryTypeEnumA = binaryTypeEnumA;
     this.typeInformationA = typeInformationA;
     this.memberAssemIds = memberAssemIds;
     this.assemId = assemId;
     if (assemId > 0)
     {
         this.binaryHeaderEnum = BinaryHeaderEnum.ObjectWithMapTypedAssemId;
     }
     else
     {
         this.binaryHeaderEnum = BinaryHeaderEnum.ObjectWithMapTyped;
     }
 }
Example #9
0
        internal ObjectMap(string objectName, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
        {
            _objectName = objectName;
            _memberNames = memberNames;
            _binaryTypeEnumA = binaryTypeEnumA;
            _typeInformationA = typeInformationA;
            _objectReader = objectReader;
            _objectId = objectId;
            _assemblyInfo = assemblyInfo;

            if (assemblyInfo == null)
            {
                throw new SerializationException(SR.Format(SR.Serialization_Assembly, objectName));
            }

            _objectType = objectReader.GetType(assemblyInfo, objectName);
            _memberTypes = new Type[memberNames.Length];

            for (int i = 0; i < memberNames.Length; i++)
            {
                InternalPrimitiveTypeE primitiveTypeEnum;
                string typeString;
                Type type;
                bool isVariant;

                BinaryTypeConverter.TypeFromInfo(
                    binaryTypeEnumA[i], typeInformationA[i], objectReader, (BinaryAssemblyInfo)assemIdToAssemblyTable[memberAssemIds[i]],
                    out primitiveTypeEnum, out typeString, out type, out isVariant);
                _memberTypes[i] = type;
            }

            _objectInfo = objectReader.CreateReadObjectInfo(_objectType, memberNames, null);
            if (!_objectInfo._isSi)
            {
                _objectInfo.GetMemberTypes(memberNames, _objectInfo._objectType);  // Check version match
            }
        }
Example #10
0
        public void Read(BinaryParser input)
        {
            switch (_binaryHeaderEnum)
            {
            case BinaryHeaderEnum.ArraySinglePrimitive:
                _objectId            = input.ReadInt32();
                _lengthA             = new int[1];
                _lengthA[0]          = input.ReadInt32();
                _binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                _rank            = 1;
                _lowerBoundA     = new int[_rank];
                _binaryTypeEnum  = BinaryTypeEnum.Primitive;
                _typeInformation = (InternalPrimitiveTypeE)input.ReadByte();
                break;

            case BinaryHeaderEnum.ArraySingleString:
                _objectId            = input.ReadInt32();
                _lengthA             = new int[1];
                _lengthA[0]          = input.ReadInt32();
                _binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                _rank            = 1;
                _lowerBoundA     = new int[_rank];
                _binaryTypeEnum  = BinaryTypeEnum.String;
                _typeInformation = null;
                break;

            case BinaryHeaderEnum.ArraySingleObject:
                _objectId            = input.ReadInt32();
                _lengthA             = new int[1];
                _lengthA[0]          = input.ReadInt32();
                _binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                _rank            = 1;
                _lowerBoundA     = new int[_rank];
                _binaryTypeEnum  = BinaryTypeEnum.Object;
                _typeInformation = null;
                break;

            default:
                _objectId            = input.ReadInt32();
                _binaryArrayTypeEnum = (BinaryArrayTypeEnum)input.ReadByte();
                _rank        = input.ReadInt32();
                _lengthA     = new int[_rank];
                _lowerBoundA = new int[_rank];
                for (int i = 0; i < _rank; i++)
                {
                    _lengthA[i] = input.ReadInt32();
                }
                if ((_binaryArrayTypeEnum == BinaryArrayTypeEnum.SingleOffset) ||
                    (_binaryArrayTypeEnum == BinaryArrayTypeEnum.JaggedOffset) ||
                    (_binaryArrayTypeEnum == BinaryArrayTypeEnum.RectangularOffset))
                {
                    for (int i = 0; i < _rank; i++)
                    {
                        _lowerBoundA[i] = input.ReadInt32();
                    }
                }
                _binaryTypeEnum  = (BinaryTypeEnum)input.ReadByte();
                _typeInformation = BinaryTypeConverter.ReadTypeInfo(_binaryTypeEnum, input, out _assemId);
                break;
            }
        }
        internal void Run()
        {
            try
            {
                bool flag = true;
                this.ReadBegin();
                this.ReadSerializationHeaderRecord();
                while (flag)
                {
                    byte             num;
                    BinaryHeaderEnum binaryHeaderEnum = BinaryHeaderEnum.Object;
                    switch (this.expectedType)
                    {
                    case BinaryTypeEnum.Primitive:
                        this.ReadMemberPrimitiveUnTyped();
                        goto Label_0177;

                    case BinaryTypeEnum.String:
                    case BinaryTypeEnum.Object:
                    case BinaryTypeEnum.ObjectUrt:
                    case BinaryTypeEnum.ObjectUser:
                    case BinaryTypeEnum.ObjectArray:
                    case BinaryTypeEnum.StringArray:
                    case BinaryTypeEnum.PrimitiveArray:
                        num = this.dataReader.ReadByte();
                        binaryHeaderEnum = (BinaryHeaderEnum)num;
                        switch (binaryHeaderEnum)
                        {
                        case BinaryHeaderEnum.Object:
                            goto Label_00C9;

                        case BinaryHeaderEnum.ObjectWithMap:
                        case BinaryHeaderEnum.ObjectWithMapAssemId:
                            goto Label_00DF;

                        case BinaryHeaderEnum.ObjectWithMapTyped:
                        case BinaryHeaderEnum.ObjectWithMapTypedAssemId:
                            goto Label_00EB;

                        case BinaryHeaderEnum.ObjectString:
                        case BinaryHeaderEnum.CrossAppDomainString:
                            goto Label_0100;

                        case BinaryHeaderEnum.Array:
                        case BinaryHeaderEnum.ArraySinglePrimitive:
                        case BinaryHeaderEnum.ArraySingleObject:
                        case BinaryHeaderEnum.ArraySingleString:
                            goto Label_0109;

                        case BinaryHeaderEnum.MemberPrimitiveTyped:
                            goto Label_0112;

                        case BinaryHeaderEnum.MemberReference:
                            goto Label_011A;

                        case BinaryHeaderEnum.ObjectNull:
                        case BinaryHeaderEnum.ObjectNullMultiple256:
                        case BinaryHeaderEnum.ObjectNullMultiple:
                            goto Label_0122;

                        case BinaryHeaderEnum.MessageEnd:
                            goto Label_012B;

                        case BinaryHeaderEnum.CrossAppDomainMap:
                            goto Label_00D4;

                        case BinaryHeaderEnum.MethodCall:
                        case BinaryHeaderEnum.MethodReturn:
                            goto Label_00F7;
                        }
                        goto Label_013B;

                    default:
                        throw new SerializationException(Environment.GetResourceString("Serialization_TypeExpected"));
                    }
                    this.ReadAssembly(binaryHeaderEnum);
                    goto Label_0177;
Label_00C9:
                    this.ReadObject();
                    goto Label_0177;
Label_00D4:
                    this.ReadCrossAppDomainMap();
                    goto Label_0177;
Label_00DF:
                    this.ReadObjectWithMap(binaryHeaderEnum);
                    goto Label_0177;
Label_00EB:
                    this.ReadObjectWithMapTyped(binaryHeaderEnum);
                    goto Label_0177;
Label_00F7:
                    this.ReadMethodObject(binaryHeaderEnum);
                    goto Label_0177;
Label_0100:
                    this.ReadObjectString(binaryHeaderEnum);
                    goto Label_0177;
Label_0109:
                    this.ReadArray(binaryHeaderEnum);
                    goto Label_0177;
Label_0112:
                    this.ReadMemberPrimitiveTyped();
                    goto Label_0177;
Label_011A:
                    this.ReadMemberReference();
                    goto Label_0177;
Label_0122:
                    this.ReadObjectNull(binaryHeaderEnum);
                    goto Label_0177;
Label_012B:
                    flag = false;
                    this.ReadMessageEnd();
                    this.ReadEnd();
                    goto Label_0177;
                    Label_013B :;
                    throw new SerializationException(Environment.GetResourceString("Serialization_BinaryHeader", new object[] { num }));
Label_0177:
                    if (binaryHeaderEnum != BinaryHeaderEnum.Assembly)
                    {
                        bool next = false;
                        while (!next)
                        {
                            ObjectProgress op = (ObjectProgress)this.stack.Peek();
                            if (op == null)
                            {
                                this.expectedType            = BinaryTypeEnum.ObjectUrt;
                                this.expectedTypeInformation = null;
                                next = true;
                            }
                            else
                            {
                                next = op.GetNext(out op.expectedType, out op.expectedTypeInformation);
                                this.expectedType            = op.expectedType;
                                this.expectedTypeInformation = op.expectedTypeInformation;
                                if (!next)
                                {
                                    this.prs.Init();
                                    if (op.memberValueEnum == InternalMemberValueE.Nested)
                                    {
                                        this.prs.PRparseTypeEnum   = InternalParseTypeE.MemberEnd;
                                        this.prs.PRmemberTypeEnum  = op.memberTypeEnum;
                                        this.prs.PRmemberValueEnum = op.memberValueEnum;
                                        this.objectReader.Parse(this.prs);
                                    }
                                    else
                                    {
                                        this.prs.PRparseTypeEnum   = InternalParseTypeE.ObjectEnd;
                                        this.prs.PRmemberTypeEnum  = op.memberTypeEnum;
                                        this.prs.PRmemberValueEnum = op.memberValueEnum;
                                        this.objectReader.Parse(this.prs);
                                    }
                                    this.stack.Pop();
                                    this.PutOp(op);
                                }
                            }
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_StreamEnd"));
            }
        }
 [System.Security.SecurityCritical]  // auto-generated 
 internal static ObjectMap Create(String name, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
 {
     return new ObjectMap(name, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, objectReader, objectId, assemblyInfo, assemIdToAssemblyTable);
 } 
        // Specifies what is to parsed next from the wire.
        internal bool GetNext(out BinaryTypeEnum outBinaryTypeEnum, out Object outTypeInformation)
        {
            //Initialize the out params up here. 
            //<
            outBinaryTypeEnum = BinaryTypeEnum.Primitive; 
            outTypeInformation = null; 

#if _DEBUG 
            SerTrace.Log( this, "GetNext Entry");
            Dump();
#endif
 
            if (objectTypeEnum == InternalObjectTypeE.Array)
            { 
                SerTrace.Log( this, "GetNext Array"); 
                // Array
                if (count == numItems) 
                    return false;
                else
                {
                    outBinaryTypeEnum =  binaryTypeEnum; 
                    outTypeInformation = typeInformation;
                    if (count == 0) 
                        isInitial = false; 
                    count++;
                    SerTrace.Log( this, "GetNext Array Exit ",((Enum)outBinaryTypeEnum).ToString()," ",outTypeInformation); 
                    return true;
                }
            }
            else 
            {
                // Member 
                SerTrace.Log( this, "GetNext Member"); 
                if ((count == memberLength) && (!isInitial))
                    return false; 
                else
                {
                    outBinaryTypeEnum = binaryTypeEnumA[count];
                    outTypeInformation = typeInformationA[count]; 
                    if (count == 0)
                        isInitial = false; 
                    name = memberNames[count]; 
                    if (memberTypes == null)
                    { 
                        SerTrace.Log( this, "GetNext memberTypes = null");
                    }
                    dtType = memberTypes[count];
                    count++; 
                    SerTrace.Log( this, "GetNext Member Exit ",((Enum)outBinaryTypeEnum).ToString()," ",outTypeInformation," memberName ",name);
                    return true; 
                } 
            }
        } 
        internal  void Set(Int32 objectId, String name, Int32 numMembers, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, Int32 assemId)
        {
            SerTrace.Log(this, "BinaryObjectWithMapTyped Set ",objectId," assemId ",assemId," ",name," numMembers ",numMembers);
            this.objectId = objectId; 
            this.assemId = assemId;
            this.name = name; 
            this.numMembers = numMembers; 
            this.memberNames = memberNames;
            this.binaryTypeEnumA = binaryTypeEnumA; 
            this.typeInformationA = typeInformationA;
            this.memberAssemIds = memberAssemIds;
            this.assemId = assemId;
 
            if (assemId > 0)
                binaryHeaderEnum = BinaryHeaderEnum.ObjectWithMapTypedAssemId; 
            else 
                binaryHeaderEnum = BinaryHeaderEnum.ObjectWithMapTyped;
        } 
 [System.Security.SecurityCritical] // implements Critical method
 public void Read(__BinaryParser input)
 {
     switch (binaryHeaderEnum) 
     {
         case BinaryHeaderEnum.ArraySinglePrimitive: 
             objectId = input.ReadInt32(); 
             lengthA = new int[1];
             lengthA[0] = input.ReadInt32(); 
             binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
             rank = 1;
             lowerBoundA = new Int32[rank];
             binaryTypeEnum = BinaryTypeEnum.Primitive; 
             typeInformation = (InternalPrimitiveTypeE)input.ReadByte();
             break; 
         case BinaryHeaderEnum.ArraySingleString: 
             objectId = input.ReadInt32();
             lengthA = new int[1]; 
             lengthA[0] = (int)input.ReadInt32();
             binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
             rank = 1;
             lowerBoundA = new Int32[rank]; 
             binaryTypeEnum = BinaryTypeEnum.String;
             typeInformation = null; 
             break; 
         case BinaryHeaderEnum.ArraySingleObject:
             objectId = input.ReadInt32(); 
             lengthA = new int[1];
             lengthA[0] = (int)input.ReadInt32();
             binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
             rank = 1; 
             lowerBoundA = new Int32[rank];
             binaryTypeEnum = BinaryTypeEnum.Object; 
             typeInformation = null; 
             break;
 default: 
             objectId = input.ReadInt32();
             binaryArrayTypeEnum = (BinaryArrayTypeEnum)input.ReadByte();
             rank = input.ReadInt32();
             lengthA = new Int32[rank]; 
             lowerBoundA = new Int32[rank];
             for (int i=0; i<rank; i++) 
                 lengthA[i] = input.ReadInt32(); 
             if ((binaryArrayTypeEnum == BinaryArrayTypeEnum.SingleOffset) ||
                 (binaryArrayTypeEnum == BinaryArrayTypeEnum.JaggedOffset) || 
                 (binaryArrayTypeEnum == BinaryArrayTypeEnum.RectangularOffset))
             {
                 for (int i=0; i<rank; i++)
                     lowerBoundA[i] = input.ReadInt32(); 
             }
             binaryTypeEnum = (BinaryTypeEnum)input.ReadByte(); 
             typeInformation = BinaryConverter.ReadTypeInfo(binaryTypeEnum, input, out assemId); 
             break;
     } 
 }
        internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum,
                                          object?typeInformation,
                                          ObjectReader objectReader,
                                          BinaryAssemblyInfo?assemblyInfo,
                                          out InternalPrimitiveTypeE primitiveTypeEnum,
                                          out string?typeString,
                                          out Type?type,
                                          out bool isVariant)
        {
            isVariant         = false;
            primitiveTypeEnum = InternalPrimitiveTypeE.Invalid;
            typeString        = null;
            type = null;

            switch (binaryTypeEnum)
            {
            case BinaryTypeEnum.Primitive:
                primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation !;
                typeString        = Converter.ToComType(primitiveTypeEnum);
                type = Converter.ToType(primitiveTypeEnum);
                break;

            case BinaryTypeEnum.String:
                type = Converter.s_typeofString;
                break;

            case BinaryTypeEnum.Object:
                type      = Converter.s_typeofObject;
                isVariant = true;
                break;

            case BinaryTypeEnum.ObjectArray:
                type = Converter.s_typeofObjectArray;
                break;

            case BinaryTypeEnum.StringArray:
                type = Converter.s_typeofStringArray;
                break;

            case BinaryTypeEnum.PrimitiveArray:
                primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation !;
                type = Converter.ToArrayType(primitiveTypeEnum);
                break;

            case BinaryTypeEnum.ObjectUser:
            case BinaryTypeEnum.ObjectUrt:
                if (typeInformation != null)
                {
                    typeString = typeInformation.ToString();
                    type       = objectReader.GetType(assemblyInfo !, typeString !);
                    if (ReferenceEquals(type, Converter.s_typeofObject))
                    {
                        isVariant = true;
                    }
                }
                break;

            default:
                throw new SerializationException(SR.Format(SR.Serialization_TypeRead, binaryTypeEnum.ToString()));
            }
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum, 
                                          Object typeInformation,
                                          ObjectReader objectReader, 
                                          BinaryAssemblyInfo assemblyInfo, 
                                          out InternalPrimitiveTypeE primitiveTypeEnum,
                                          out String typeString, 
                                          out Type type,
                                          out bool isVariant)
        {
            SerTrace.Log( "BinaryConverter", "TypeFromInfo Entry  ",((Enum)binaryTypeEnum).ToString()); 

            isVariant = false; 
            primitiveTypeEnum = InternalPrimitiveTypeE.Invalid; 
            typeString = null;
            type = null; 

            switch (binaryTypeEnum)
            {
                case BinaryTypeEnum.Primitive: 
                    primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation;
                    typeString = Converter.ToComType(primitiveTypeEnum); 
                    type = Converter.ToType(primitiveTypeEnum); 
                    break;
                case BinaryTypeEnum.String: 
                    //typeString = "System.String";
                    type = Converter.typeofString;
                    break;
                case BinaryTypeEnum.Object: 
                    //typeString = "System.Object";
                    type = Converter.typeofObject; 
                    isVariant = true; 
                    break;
                case BinaryTypeEnum.ObjectArray: 
                    //typeString = "System.Object[]";
                    type = Converter.typeofObjectArray;
                    break;
                case BinaryTypeEnum.StringArray: 
                    //typeString = "System.String[]";
                    type = Converter.typeofStringArray; 
                    break; 
                case BinaryTypeEnum.PrimitiveArray:
                    primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation; 
                    type = Converter.ToArrayType(primitiveTypeEnum);
                    break;
                case BinaryTypeEnum.ObjectUser:
                case BinaryTypeEnum.ObjectUrt: 
                    if (typeInformation != null)
                    { 
                        typeString = typeInformation.ToString(); 
                        type = objectReader.GetType(assemblyInfo, typeString);
                        // Temporary for backward compatibility 
                        if (Object.ReferenceEquals(type, Converter.typeofObject))
                            isVariant = true;
                    }
                    break; 
                default:
                    throw new SerializationException(Environment.GetResourceString("Serialization_TypeRead",((Enum)binaryTypeEnum).ToString())); 
            } 

#if _DEBUG 
                SerTrace.Log( "BinaryConverter", "TypeFromInfo Exit  "
                          ,((Enum)primitiveTypeEnum).ToString(),",typeString ",Util.PString(typeString)
                          ,", type ",Util.PString(type),", isVariant ",isVariant);
#endif 

        } 
Example #18
0
        public void Read(BinaryReader input)
        {
            switch (binaryHeaderEnum)
            {
            case BinaryHeaderEnum.ArraySinglePrimitive:
                objectId            = input.ReadInt32();
                lengthA             = new int[1];
                lengthA[0]          = input.ReadInt32();
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                rank            = 1;
                lowerBoundA     = new Int32[rank];
                binaryTypeEnum  = BinaryTypeEnum.Primitive;
                typeInformation = (InternalPrimitiveTypeE)input.ReadByte();
                break;

            case BinaryHeaderEnum.ArraySingleString:
                objectId            = input.ReadInt32();
                lengthA             = new int[1];
                lengthA[0]          = (int)input.ReadInt32();
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                rank            = 1;
                lowerBoundA     = new Int32[rank];
                binaryTypeEnum  = BinaryTypeEnum.String;
                typeInformation = null;
                break;

            case BinaryHeaderEnum.ArraySingleObject:
                objectId            = input.ReadInt32();
                lengthA             = new int[1];
                lengthA[0]          = (int)input.ReadInt32();
                binaryArrayTypeEnum = BinaryArrayTypeEnum.Single;
                rank            = 1;
                lowerBoundA     = new Int32[rank];
                binaryTypeEnum  = BinaryTypeEnum.Object;
                typeInformation = null;
                break;

            default:
                objectId            = input.ReadInt32();
                binaryArrayTypeEnum = (BinaryArrayTypeEnum)input.ReadByte();
                rank        = input.ReadInt32();
                lengthA     = new Int32[rank];
                lowerBoundA = new Int32[rank];
                for (int i = 0; i < rank; i++)
                {
                    lengthA[i] = input.ReadInt32();
                }
                if ((binaryArrayTypeEnum == BinaryArrayTypeEnum.SingleOffset) ||
                    (binaryArrayTypeEnum == BinaryArrayTypeEnum.JaggedOffset) ||
                    (binaryArrayTypeEnum == BinaryArrayTypeEnum.RectangularOffset))
                {
                    for (int i = 0; i < rank; i++)
                    {
                        lowerBoundA[i] = input.ReadInt32();
                    }
                }
                binaryTypeEnum  = (BinaryTypeEnum)input.ReadByte();
                typeInformation = BinaryConverter.ReadTypeInfo(binaryTypeEnum, input, out assemId);
                break;
            }
        }
Example #19
0
        internal void WriteObject(NameInfo nameInfo, NameInfo?typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            InternalWriteItemNull();
            int assemId;
            int objectId = (int)nameInfo._objectId;

            Debug.Assert(typeNameInfo != null);       // Explicitly called with null. Potential bug, but closed as Won't Fix: https://github.com/dotnet/runtime/issues/31402
            string?objectName = objectId < 0 ?
                                typeNameInfo.NIname : // Nested Object
                                nameInfo.NIname;      // Non-Nested

            _objectMapTable ??= new Dictionary <string, ObjectMapInfo>();

            Debug.Assert(objectName != null);
            if (_objectMapTable.TryGetValue(objectName, out ObjectMapInfo? objectMapInfo) &&
                objectMapInfo.IsCompatible(numMembers, memberNames, memberTypes))
            {
                // Object
                _binaryObject ??= new BinaryObject();

                _binaryObject.Set(objectId, objectMapInfo._objectId);
                _binaryObject.Write(this);
            }
            else if (!typeNameInfo._transmitTypeOnObject)
            {
                // ObjectWithMap
                _binaryObjectWithMap ??= new BinaryObjectWithMap();

                // BCL types are not placed into table
                assemId = (int)typeNameInfo._assemId;
                _binaryObjectWithMap.Set(objectId, objectName, numMembers, memberNames, assemId);

                _binaryObjectWithMap.Write(this);
                if (objectMapInfo == null)
                {
                    _objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
            else
            {
                // ObjectWithMapTyped
                var binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                var typeInformationA = new object?[numMembers];
                var assemIdA         = new int[numMembers];
                for (int i = 0; i < numMembers; i++)
                {
                    object?typeInformation;
                    binaryTypeEnumA[i]  = BinaryTypeConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, _objectWriter, out typeInformation, out assemId);
                    typeInformationA[i] = typeInformation;
                    assemIdA[i]         = assemId;
                }

                _binaryObjectWithMapTyped ??= new BinaryObjectWithMapTyped();

                // BCL types are not placed in table
                assemId = (int)typeNameInfo._assemId;
                _binaryObjectWithMapTyped.Set(objectId, objectName, numMembers, memberNames, binaryTypeEnumA, typeInformationA, assemIdA, assemId);
                _binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo == null)
                {
                    _objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
        }
Example #20
0
        internal void Set(Int32 objectId, Int32 rank, Int32[] lengthA, Int32[] lowerBoundA, BinaryTypeEnum binaryTypeEnum, Object typeInformation, BinaryArrayTypeEnum binaryArrayTypeEnum, int assemId)
        {
            this.objectId            = objectId;
            this.binaryArrayTypeEnum = binaryArrayTypeEnum;
            this.rank            = rank;
            this.lengthA         = lengthA;
            this.lowerBoundA     = lowerBoundA;
            this.binaryTypeEnum  = binaryTypeEnum;
            this.typeInformation = typeInformation;
            this.assemId         = assemId;
            binaryHeaderEnum     = BinaryHeaderEnum.Array;

            if (binaryArrayTypeEnum == BinaryArrayTypeEnum.Single)
            {
                if (binaryTypeEnum == BinaryTypeEnum.Primitive)
                {
                    binaryHeaderEnum = BinaryHeaderEnum.ArraySinglePrimitive;
                }
                else if (binaryTypeEnum == BinaryTypeEnum.String)
                {
                    binaryHeaderEnum = BinaryHeaderEnum.ArraySingleString;
                }
                else if (binaryTypeEnum == BinaryTypeEnum.Object)
                {
                    binaryHeaderEnum = BinaryHeaderEnum.ArraySingleObject;
                }
            }
        }
        //internal BinaryCrossAppDomainMap crossAppDomainMap;

        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, String[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            InternalWriteItemNull();
            int assemId;

#if _DEBUG
            nameInfo.Dump("WriteObject nameInfo");
            typeNameInfo.Dump("WriteObject typeNameInfo");
#endif

            int objectId = (int)nameInfo.NIobjectId;

            //if (objectId < 0)
            //  objectId = --m_nestedObjectCount;

            if (objectId > 0)
            {
                BCLDebug.Trace("BINARY", "-----Top Level Object-----");
            }

            String objectName = null;
            if (objectId < 0)
            {
                // Nested Object
                objectName = typeNameInfo.NIname;
            }
            else
            {
                // Non-Nested
                objectName = nameInfo.NIname;
            }
            SerTrace.Log(this, "WriteObject objectName ", objectName);

            if (objectMapTable == null)
            {
                objectMapTable = new Hashtable();
            }

            ObjectMapInfo objectMapInfo = (ObjectMapInfo)objectMapTable[objectName];

            if (objectMapInfo != null && objectMapInfo.isCompatible(numMembers, memberNames, memberTypes))
            {
                // Object
                if (binaryObject == null)
                {
                    binaryObject = new BinaryObject();
                }
                binaryObject.Set(objectId, objectMapInfo.objectId);
#if _DEBUG
                binaryObject.Dump();
#endif
                binaryObject.Write(this);
            }
            else if (!typeNameInfo.NItransmitTypeOnObject)
            {
                // ObjectWithMap
                if (binaryObjectWithMap == null)
                {
                    binaryObjectWithMap = new BinaryObjectWithMap();
                }

                // BCL types are not placed into table
                assemId = (int)typeNameInfo.NIassemId;
                binaryObjectWithMap.Set(objectId, objectName, numMembers, memberNames, assemId);

                binaryObjectWithMap.Dump();
                binaryObjectWithMap.Write(this);
                if (objectMapInfo == null)
                {
                    objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
            else
            {
                // ObjectWithMapTyped
                BinaryTypeEnum[] binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                Object[]         typeInformationA = new Object[numMembers];
                int[]            assemIdA         = new int[numMembers];
                for (int i = 0; i < numMembers; i++)
                {
                    Object typeInformation = null;

                    binaryTypeEnumA[i]  = BinaryConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, objectWriter, out typeInformation, out assemId);
                    typeInformationA[i] = typeInformation;
                    assemIdA[i]         = assemId;
                    SerTrace.Log(this, "WriteObject ObjectWithMapTyped memberNames "
                                 , memberNames[i], ", memberType ", memberTypes[i], " binaryTypeEnum ", ((Enum)binaryTypeEnumA[i]).ToString()
                                 , ", typeInformation ", typeInformationA[i], " assemId ", assemIdA[i]);
                }

                if (binaryObjectWithMapTyped == null)
                {
                    binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                }

                // BCL types are not placed in table
                assemId = (int)typeNameInfo.NIassemId;
                binaryObjectWithMapTyped.Set(objectId, objectName, numMembers, memberNames, binaryTypeEnumA, typeInformationA, assemIdA, assemId);
#if _DEBUG
                binaryObjectWithMapTyped.Dump();
#endif
                binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo == null)
                {
                    objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
        }
Example #22
0
        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            InternalWriteItemNull();
            int assemId;
            int objectId = (int)nameInfo._objectId;

            string objectName = objectId < 0 ?
                                objectName = typeNameInfo.NIname :         // Nested Object
                                             objectName = nameInfo.NIname; // Non-Nested

            if (_objectMapTable == null)
            {
                _objectMapTable = new Dictionary <string, ObjectMapInfo>();
            }

            ObjectMapInfo objectMapInfo;

            if (_objectMapTable.TryGetValue(objectName, out objectMapInfo) &&
                objectMapInfo.IsCompatible(numMembers, memberNames, memberTypes))
            {
                // Object
                if (_binaryObject == null)
                {
                    _binaryObject = new BinaryObject();
                }

                _binaryObject.Set(objectId, objectMapInfo._objectId);
                _binaryObject.Write(this);
            }
            else if (!typeNameInfo._transmitTypeOnObject)
            {
                // ObjectWithMap
                if (_binaryObjectWithMap == null)
                {
                    _binaryObjectWithMap = new BinaryObjectWithMap();
                }

                // BCL types are not placed into table
                assemId = (int)typeNameInfo._assemId;
                _binaryObjectWithMap.Set(objectId, objectName, numMembers, memberNames, assemId);

                _binaryObjectWithMap.Write(this);
                if (objectMapInfo == null)
                {
                    _objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
            else
            {
                // ObjectWithMapTyped
                var binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                var typeInformationA = new object[numMembers];
                var assemIdA         = new int[numMembers];
                for (int i = 0; i < numMembers; i++)
                {
                    object typeInformation = null;
                    binaryTypeEnumA[i]  = BinaryTypeConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, _objectWriter, out typeInformation, out assemId);
                    typeInformationA[i] = typeInformation;
                    assemIdA[i]         = assemId;
                }

                if (_binaryObjectWithMapTyped == null)
                {
                    _binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                }

                // BCL types are not placed in table
                assemId = (int)typeNameInfo._assemId;
                _binaryObjectWithMapTyped.Set(objectId, objectName, numMembers, memberNames, binaryTypeEnumA, typeInformationA, assemIdA, assemId);
                _binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo == null)
                {
                    _objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
        }
        // Writes the type information on the wire 
        internal static void WriteTypeInfo(BinaryTypeEnum binaryTypeEnum, Object typeInformation, int assemId, __BinaryWriter sout)
        {
            SerTrace.Log( "BinaryConverter", "WriteTypeInfo Entry  ",((Enum)binaryTypeEnum).ToString()," ",typeInformation," assemId ",assemId);
 
            switch (binaryTypeEnum)
            { 
                case BinaryTypeEnum.Primitive: 
                case BinaryTypeEnum.PrimitiveArray:
                    Contract.Assert(typeInformation!=null, "[BinaryConverter.WriteTypeInfo]typeInformation!=null"); 
                    sout.WriteByte((Byte)((InternalPrimitiveTypeE)typeInformation));
                    break;
                case BinaryTypeEnum.String:
                case BinaryTypeEnum.Object: 
                case BinaryTypeEnum.StringArray:
                case BinaryTypeEnum.ObjectArray: 
                    break; 
                case BinaryTypeEnum.ObjectUrt:
                    Contract.Assert(typeInformation!=null, "[BinaryConverter.WriteTypeInfo]typeInformation!=null"); 
                    sout.WriteString(typeInformation.ToString());
                    break;
                case BinaryTypeEnum.ObjectUser:
                    Contract.Assert(typeInformation!=null, "[BinaryConverter.WriteTypeInfo]typeInformation!=null"); 
                    sout.WriteString(typeInformation.ToString());
                    sout.WriteInt32(assemId); 
                    break; 
                default:
                    throw new SerializationException(Environment.GetResourceString("Serialization_TypeWrite",((Enum)binaryTypeEnum).ToString())); 
            }
            SerTrace.Log( "BinaryConverter", "WriteTypeInfo Exit");
        }
Example #24
0
        internal void Run()
        {
            try
            {
                bool isLoop = true;
                ReadBegin();
                ReadSerializationHeaderRecord();
                while (isLoop)
                {
                    BinaryHeaderEnum binaryHeaderEnum = BinaryHeaderEnum.Object;
                    switch (_expectedType)
                    {
                    case BinaryTypeEnum.ObjectUrt:
                    case BinaryTypeEnum.ObjectUser:
                    case BinaryTypeEnum.String:
                    case BinaryTypeEnum.Object:
                    case BinaryTypeEnum.ObjectArray:
                    case BinaryTypeEnum.StringArray:
                    case BinaryTypeEnum.PrimitiveArray:
                        byte inByte = _dataReader.ReadByte();
                        binaryHeaderEnum = (BinaryHeaderEnum)inByte;
                        switch (binaryHeaderEnum)
                        {
                        case BinaryHeaderEnum.Assembly:
                        case BinaryHeaderEnum.CrossAppDomainAssembly:
                            ReadAssembly(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.Object:
                            ReadObject();
                            break;

                        case BinaryHeaderEnum.CrossAppDomainMap:
                            ReadCrossAppDomainMap();
                            break;

                        case BinaryHeaderEnum.ObjectWithMap:
                        case BinaryHeaderEnum.ObjectWithMapAssemId:
                            ReadObjectWithMap(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.ObjectWithMapTyped:
                        case BinaryHeaderEnum.ObjectWithMapTypedAssemId:
                            ReadObjectWithMapTyped(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.ObjectString:
                        case BinaryHeaderEnum.CrossAppDomainString:
                            ReadObjectString(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.Array:
                        case BinaryHeaderEnum.ArraySinglePrimitive:
                        case BinaryHeaderEnum.ArraySingleObject:
                        case BinaryHeaderEnum.ArraySingleString:
                            ReadArray(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.MemberPrimitiveTyped:
                            ReadMemberPrimitiveTyped();
                            break;

                        case BinaryHeaderEnum.MemberReference:
                            ReadMemberReference();
                            break;

                        case BinaryHeaderEnum.ObjectNull:
                        case BinaryHeaderEnum.ObjectNullMultiple256:
                        case BinaryHeaderEnum.ObjectNullMultiple:
                            ReadObjectNull(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.MessageEnd:
                            isLoop = false;
                            ReadMessageEnd();
                            ReadEnd();
                            break;

                        default:
                            throw new SerializationException(SR.Format(SR.Serialization_BinaryHeader, inByte));
                        }
                        break;

                    case BinaryTypeEnum.Primitive:
                        ReadMemberPrimitiveUnTyped();
                        break;

                    default:
                        throw new SerializationException(SR.Serialization_TypeExpected);
                    }

                    // If an assembly is encountered, don't advance
                    // object Progress,
                    if (binaryHeaderEnum != BinaryHeaderEnum.Assembly)
                    {
                        // End of parse loop.
                        bool isData = false;

                        // Set up loop for next iteration.
                        // If this is an object, and the end of object has been reached, then parse object end.
                        while (!isData)
                        {
                            ObjectProgress?op = (ObjectProgress?)_stack.Peek();
                            if (op == null)
                            {
                                // No more object on stack, then the next record is a top level object
                                _expectedType            = BinaryTypeEnum.ObjectUrt;
                                _expectedTypeInformation = null;
                                isData = true;
                            }
                            else
                            {
                                // Find out what record is expected next
                                isData                   = op.GetNext(out op._expectedType, out op._expectedTypeInformation);
                                _expectedType            = op._expectedType;
                                _expectedTypeInformation = op._expectedTypeInformation;

                                if (!isData)
                                {
                                    // No record is expected next, this is the end of an object or array
                                    PRs.Init();
                                    if (op._memberValueEnum == InternalMemberValueE.Nested)
                                    {
                                        // Nested object
                                        PRs._parseTypeEnum   = InternalParseTypeE.MemberEnd;
                                        PRs._memberTypeEnum  = op._memberTypeEnum;
                                        PRs._memberValueEnum = op._memberValueEnum;
                                        _objectReader.Parse(PRs);
                                    }
                                    else
                                    {
                                        // Top level object
                                        PRs._parseTypeEnum   = InternalParseTypeE.ObjectEnd;
                                        PRs._memberTypeEnum  = op._memberTypeEnum;
                                        PRs._memberValueEnum = op._memberValueEnum;
                                        _objectReader.Parse(PRs);
                                    }
                                    _stack.Pop();
                                    PutOp(op);
                                }
                            }
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                // EOF should never be thrown since there is a MessageEnd record to stop parsing
                throw new SerializationException(SR.Serialization_StreamEnd);
            }
        }
        // Reads the type information from the wire
        internal static Object ReadTypeInfo(BinaryTypeEnum binaryTypeEnum, __BinaryParser input, out int assemId) 
        { 
            SerTrace.Log( "BinaryConverter", "ReadTypeInfo Entry  ",((Enum)binaryTypeEnum).ToString());
            Object var = null; 
            int readAssemId = 0;

            switch (binaryTypeEnum)
            { 
                case BinaryTypeEnum.Primitive:
                case BinaryTypeEnum.PrimitiveArray: 
                    var = (InternalPrimitiveTypeE)input.ReadByte(); 
                    break;
                case BinaryTypeEnum.String: 
                case BinaryTypeEnum.Object:
                case BinaryTypeEnum.StringArray:
                case BinaryTypeEnum.ObjectArray:
                    break; 
                case BinaryTypeEnum.ObjectUrt:
                    var = input.ReadString(); 
                    break; 
                case BinaryTypeEnum.ObjectUser:
                    var = input.ReadString(); 
                    readAssemId = input.ReadInt32();
                    break;
                default:
                    throw new SerializationException(Environment.GetResourceString("Serialization_TypeRead",((Enum)binaryTypeEnum).ToString())); 
            }
            SerTrace.Log( "BinaryConverter", "ReadTypeInfo Exit  ",var," assemId ",readAssemId); 
            assemId = readAssemId; 
            return var;
        } 
Example #26
0
        // Reads the type information from the wire
        internal static object ReadTypeInfo(BinaryTypeEnum binaryTypeEnum, BinaryParser input, out int assemId)
        {
            object var = null;
            int readAssemId = 0;

            switch (binaryTypeEnum)
            {
                case BinaryTypeEnum.Primitive:
                case BinaryTypeEnum.PrimitiveArray:
                    var = (InternalPrimitiveTypeE)input.ReadByte();
                    break;
                case BinaryTypeEnum.String:
                case BinaryTypeEnum.Object:
                case BinaryTypeEnum.StringArray:
                case BinaryTypeEnum.ObjectArray:
                    break;
                case BinaryTypeEnum.ObjectUrt:
                    var = input.ReadString();
                    break;
                case BinaryTypeEnum.ObjectUser:
                    var = input.ReadString();
                    readAssemId = input.ReadInt32();
                    break;
                default:
                    throw new SerializationException(SR.Format(SR.Serialization_TypeRead, binaryTypeEnum.ToString()));
            }
            assemId = readAssemId;
            return var;
        }
        internal BinaryObjectWithMapTyped Copy() 
        {
        BinaryObjectWithMapTyped newBOWM = new BinaryObjectWithMapTyped(binaryHeaderEnum);

        String[] newMemberNames = new String[numMembers]; 
        Array.Copy(memberNames, newMemberNames, numMembers);
        BinaryTypeEnum[] newBinaryTypeEnumA = new BinaryTypeEnum[binaryTypeEnumA.Length]; 
        Array.Copy(binaryTypeEnumA, newBinaryTypeEnumA, binaryTypeEnumA.Length); 
        Object[] newTypeInformationA = new Object[typeInformationA.Length];
        Array.Copy(typeInformationA, newTypeInformationA, typeInformationA.Length); 
        Int32[] newMemberAssemIds = new Int32[memberAssemIds.Length];
        Array.Copy(memberAssemIds, newMemberAssemIds, memberAssemIds.Length);

        newBOWM.Set(objectId, name, numMembers, newMemberNames, newBinaryTypeEnumA, newTypeInformationA, newMemberAssemIds, assemId); 
        return newBOWM;
        } 
Example #28
0
        // Given the wire type information, returns the actual type and additional information
        internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum,
                                          object typeInformation,
                                          ObjectReader objectReader,
                                          BinaryAssemblyInfo assemblyInfo,
                                          out InternalPrimitiveTypeE primitiveTypeEnum,
                                          out string typeString,
                                          out Type type,
                                          out bool isVariant)
        {
            isVariant = false;
            primitiveTypeEnum = InternalPrimitiveTypeE.Invalid;
            typeString = null;
            type = null;

            switch (binaryTypeEnum)
            {
                case BinaryTypeEnum.Primitive:
                    primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation;
                    typeString = Converter.ToComType(primitiveTypeEnum);
                    type = Converter.ToType(primitiveTypeEnum);
                    break;
                case BinaryTypeEnum.String:
                    type = Converter.s_typeofString;
                    break;
                case BinaryTypeEnum.Object:
                    type = Converter.s_typeofObject;
                    isVariant = true;
                    break;
                case BinaryTypeEnum.ObjectArray:
                    type = Converter.s_typeofObjectArray;
                    break;
                case BinaryTypeEnum.StringArray:
                    type = Converter.s_typeofStringArray;
                    break;
                case BinaryTypeEnum.PrimitiveArray:
                    primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation;
                    type = Converter.ToArrayType(primitiveTypeEnum);
                    break;
                case BinaryTypeEnum.ObjectUser:
                case BinaryTypeEnum.ObjectUrt:
                    if (typeInformation != null)
                    {
                        typeString = typeInformation.ToString();
                        type = objectReader.GetType(assemblyInfo, typeString);
                        if (ReferenceEquals(type, Converter.s_typeofObject))
                        {
                            isVariant = true;
                        }
                    }
                    break;
                default:
                    throw new SerializationException(SR.Format(SR.Serialization_TypeRead, binaryTypeEnum.ToString()));
            }
        }
        internal void Set(Int32 objectId, Int32 rank, Int32[] lengthA, Int32[] lowerBoundA, BinaryTypeEnum binaryTypeEnum, Object typeInformation, BinaryArrayTypeEnum binaryArrayTypeEnum, int assemId)
        { 
            SerTrace.Log( this, "BinaryArray Set objectId ",objectId," rank ",rank," ",((Enum)binaryTypeEnum).ToString(),", assemId ",assemId); 
            this.objectId = objectId;
            this.binaryArrayTypeEnum = binaryArrayTypeEnum; 
            this.rank = rank;
            this.lengthA = lengthA;
            this.lowerBoundA = lowerBoundA;
            this.binaryTypeEnum = binaryTypeEnum; 
            this.typeInformation = typeInformation;
            this.assemId = assemId; 
            binaryHeaderEnum = BinaryHeaderEnum.Array; 

            if (binaryArrayTypeEnum == BinaryArrayTypeEnum.Single) 
            {
                if (binaryTypeEnum == BinaryTypeEnum.Primitive)
                    binaryHeaderEnum = BinaryHeaderEnum.ArraySinglePrimitive;
                else if (binaryTypeEnum == BinaryTypeEnum.String) 
                    binaryHeaderEnum = BinaryHeaderEnum.ArraySingleString;
                else if (binaryTypeEnum == BinaryTypeEnum.Object) 
                    binaryHeaderEnum = BinaryHeaderEnum.ArraySingleObject; 
            }
            SerTrace.Log( this, "BinaryArray Set Exit ",((Enum)binaryHeaderEnum).ToString()); 
        }
        internal static void WriteTypeInfo(BinaryTypeEnum binaryTypeEnum, object typeInformation, int assemId, __BinaryWriter sout)
        {
            switch (binaryTypeEnum)
            {
                case BinaryTypeEnum.Primitive:
                case BinaryTypeEnum.PrimitiveArray:
                    sout.WriteByte((byte) ((InternalPrimitiveTypeE) typeInformation));
                    return;

                case BinaryTypeEnum.String:
                case BinaryTypeEnum.Object:
                case BinaryTypeEnum.ObjectArray:
                case BinaryTypeEnum.StringArray:
                    return;

                case BinaryTypeEnum.ObjectUrt:
                    sout.WriteString(typeInformation.ToString());
                    return;

                case BinaryTypeEnum.ObjectUser:
                    sout.WriteString(typeInformation.ToString());
                    sout.WriteInt32(assemId);
                    return;
            }
            throw new SerializationException(Environment.GetResourceString("Serialization_TypeWrite", new object[] { binaryTypeEnum.ToString() }));
        }
        [System.Security.SecurityCritical]  // auto-generated 
        internal ObjectMap(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
        {
            SerTrace.Log( this, "Constructor 2 objectName ",objectName);
            this.objectName = objectName; 
            this.memberNames = memberNames;
            this.binaryTypeEnumA = binaryTypeEnumA; 
            this.typeInformationA = typeInformationA; 
            this.objectReader = objectReader;
            this.objectId = objectId; 
            this.assemblyInfo = assemblyInfo;

            if (assemblyInfo == null)
                throw new SerializationException(Environment.GetResourceString("Serialization_Assembly",objectName)); 

            objectType = objectReader.GetType(assemblyInfo, objectName); 
 
            memberTypes = new Type[memberNames.Length];
 
            for (int i=0; i<memberNames.Length; i++)
            {
                InternalPrimitiveTypeE primitiveTypeEnum;
                String typeString; 
                Type type;
                bool isVariant; 
 
                BinaryConverter.TypeFromInfo(binaryTypeEnumA[i], typeInformationA[i], objectReader, (BinaryAssemblyInfo)assemIdToAssemblyTable[memberAssemIds[i]],
                                             out primitiveTypeEnum, out typeString, out type, out isVariant); 
                //if ((object)type == null)
                //    throw new SerializationException(String.Format(Environment.GetResourceString("Serialization_TypeResolved"),objectName+" "+memberNames[i]+" "+typeInformationA[i]));
                memberTypes[i] = type;
            } 

            objectInfo = objectReader.CreateReadObjectInfo(objectType, memberNames, null); 
            if (!objectInfo.isSi) 
                objectInfo.GetMemberTypes(memberNames, objectInfo.objectType);  // Check version match
        } 
        /*
         * Parse the input
         * Reads each record from the input stream. If the record is a primitive type (A number)
         *  then it doesn't have a BinaryHeaderEnum byte. For this case the expected type
         *  has been previously set to Primitive
         * @internalonly
         */
        internal void Run()
        {
            try
            {
                bool isLoop = true;
                ReadBegin();
                ReadSerializationHeaderRecord();
                while (isLoop)
                {
                    SerTrace.Log(this, "Run loop ", ((Enum)expectedType).ToString());
                    BinaryHeaderEnum binaryHeaderEnum = BinaryHeaderEnum.Object;
                    switch (expectedType)
                    {
                    case BinaryTypeEnum.ObjectUrt:
                    case BinaryTypeEnum.ObjectUser:
                    case BinaryTypeEnum.String:
                    case BinaryTypeEnum.Object:
                    case BinaryTypeEnum.ObjectArray:
                    case BinaryTypeEnum.StringArray:
                    case BinaryTypeEnum.PrimitiveArray:
                        Byte inByte = dataReader.ReadByte();
                        binaryHeaderEnum = (BinaryHeaderEnum)inByte;
                        //Console.WriteLine("Beginning of loop "+((Enum)binaryHeaderEnum).ToString());
                        switch (binaryHeaderEnum)
                        {
                        case BinaryHeaderEnum.Assembly:
                        case BinaryHeaderEnum.CrossAppDomainAssembly:
                            ReadAssembly(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.Object:
                            ReadObject();
                            break;

                        case BinaryHeaderEnum.CrossAppDomainMap:
                            ReadCrossAppDomainMap();
                            break;

                        case BinaryHeaderEnum.ObjectWithMap:
                        case BinaryHeaderEnum.ObjectWithMapAssemId:
                            ReadObjectWithMap(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.ObjectWithMapTyped:
                        case BinaryHeaderEnum.ObjectWithMapTypedAssemId:
                            ReadObjectWithMapTyped(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.MethodCall:
                        case BinaryHeaderEnum.MethodReturn:
                            ReadMethodObject(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.ObjectString:
                        case BinaryHeaderEnum.CrossAppDomainString:
                            ReadObjectString(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.Array:
                        case BinaryHeaderEnum.ArraySinglePrimitive:
                        case BinaryHeaderEnum.ArraySingleObject:
                        case BinaryHeaderEnum.ArraySingleString:
                            ReadArray(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.MemberPrimitiveTyped:
                            ReadMemberPrimitiveTyped();
                            break;

                        case BinaryHeaderEnum.MemberReference:
                            ReadMemberReference();
                            break;

                        case BinaryHeaderEnum.ObjectNull:
                        case BinaryHeaderEnum.ObjectNullMultiple256:
                        case BinaryHeaderEnum.ObjectNullMultiple:
                            ReadObjectNull(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.MessageEnd:
                            isLoop = false;
                            ReadMessageEnd();
                            ReadEnd();
                            break;

                        default:
                            throw new SerializationException(String.Format(Environment.GetResourceString("Serialization_BinaryHeader"), inByte));
                        }
                        break;

                    case BinaryTypeEnum.Primitive:
                        ReadMemberPrimitiveUnTyped();
                        break;

                    default:
                        throw new SerializationException(Environment.GetResourceString("Serialization_TypeExpected"));
                    }

                    // If an assembly is encountered, don't advance
                    // object Progress,
                    if (binaryHeaderEnum != BinaryHeaderEnum.Assembly)
                    {
                        // End of parse loop.
                        bool isData = false;
                        // Set up loop for next iteration.
                        // If this is an object, and the end of object has been reached, then parse object end.
                        while (!isData)
                        {
                            ObjectProgress op = (ObjectProgress)stack.Peek();
                            if (op == null)
                            {
                                // No more object on stack, then the next record is a top level object
                                SerTrace.Log(this, "Run loop op null, top level object");
                                expectedType            = BinaryTypeEnum.ObjectUrt;
                                expectedTypeInformation = null;
                                isData = true;
                            }
                            else
                            {
                                SerTrace.Log(this, "Run loop op not null, continue object");
                                // Find out what record is expected next
                                isData                  = op.GetNext(out op.expectedType, out op.expectedTypeInformation);
                                expectedType            = op.expectedType;
                                expectedTypeInformation = op.expectedTypeInformation;
                                SerTrace.Log(this, "Run loop opName ", op.name, ", expectedType ", ((Enum)expectedType).ToString(), " expectedTypeInformation, ", expectedTypeInformation);

                                SerTrace.Log(this, "Run ", isData);
                                if (!isData)
                                {
                                    // No record is expected next, this is the end of an object or array
                                    SerTrace.Log(this, "Run End of Object ");
                                    stack.Dump();

                                    prs.Init();
                                    if (op.memberValueEnum == InternalMemberValueE.Nested)
                                    {
                                        // Nested object
                                        prs.PRparseTypeEnum   = InternalParseTypeE.MemberEnd;
                                        prs.PRmemberTypeEnum  = op.memberTypeEnum;
                                        prs.PRmemberValueEnum = op.memberValueEnum;
                                        objectReader.Parse(prs);
                                    }
                                    else
                                    {
                                        // Top level object
                                        prs.PRparseTypeEnum   = InternalParseTypeE.ObjectEnd;
                                        prs.PRmemberTypeEnum  = op.memberTypeEnum;
                                        prs.PRmemberValueEnum = op.memberValueEnum;
                                        objectReader.Parse(prs);
                                    }
                                    stack.Pop();
                                    PutOp(op);
                                }
                            }
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                // EOF should never be thrown since there is a MessageEnd record to stop parsing
                BCLDebug.Trace("BINARY", "\n*****EOF*************************\n");
                throw new SerializationException(Environment.GetResourceString("Serialization_StreamEnd"));
            }
        }
        internal void Init()
        {
            isInitial = false;
            count = 0; 
            expectedType = BinaryTypeEnum.ObjectUrt;
            expectedTypeInformation = null; 
 
            name = null;
            objectTypeEnum = InternalObjectTypeE.Empty; 
            memberTypeEnum = InternalMemberTypeE.Empty;
            memberValueEnum = InternalMemberValueE.Empty;
            dtType = null;
 
            // Array Information
            numItems = 0; 
            nullCount = 0; 
            //binaryTypeEnum
            typeInformation = null; 

            // Member Information
            memberLength = 0;
            binaryTypeEnumA = null; 
            typeInformationA = null;
            memberNames = null; 
            memberTypes = null; 

            pr.Init(); 
        }
        internal static object ReadTypeInfo(BinaryTypeEnum binaryTypeEnum, __BinaryParser input, out int assemId)
        {
            object obj2 = null;
            int num = 0;
            switch (binaryTypeEnum)
            {
                case BinaryTypeEnum.Primitive:
                case BinaryTypeEnum.PrimitiveArray:
                    obj2 = (InternalPrimitiveTypeE) input.ReadByte();
                    break;

                case BinaryTypeEnum.String:
                case BinaryTypeEnum.Object:
                case BinaryTypeEnum.ObjectArray:
                case BinaryTypeEnum.StringArray:
                    break;

                case BinaryTypeEnum.ObjectUrt:
                    obj2 = input.ReadString();
                    break;

                case BinaryTypeEnum.ObjectUser:
                    obj2 = input.ReadString();
                    num = input.ReadInt32();
                    break;

                default:
                    throw new SerializationException(Environment.GetResourceString("Serialization_TypeRead", new object[] { binaryTypeEnum.ToString() }));
            }
            assemId = num;
            return obj2;
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal void Run()
        {
            try
            {
                bool isLoop = true;
                ReadBegin();
                ReadSerializationHeaderRecord();
                while (isLoop)
                {
                    SerTrace.Log( this, "Run loop ",((Enum)expectedType).ToString());
                    BinaryHeaderEnum binaryHeaderEnum = BinaryHeaderEnum.Object;
                    switch (expectedType)
                    {
                    case BinaryTypeEnum.ObjectUrt:
                    case BinaryTypeEnum.ObjectUser:
                    case BinaryTypeEnum.String:
                    case BinaryTypeEnum.Object:
                    case BinaryTypeEnum.ObjectArray:
                    case BinaryTypeEnum.StringArray:
                    case BinaryTypeEnum.PrimitiveArray:
                        Byte inByte = dataReader.ReadByte();
                        binaryHeaderEnum = (BinaryHeaderEnum)inByte;
                        //Console.WriteLine("Beginning of loop "+((Enum)binaryHeaderEnum).ToString());
                        switch (binaryHeaderEnum)
                        {
                        case BinaryHeaderEnum.Assembly:
                        case BinaryHeaderEnum.CrossAppDomainAssembly:
                            ReadAssembly(binaryHeaderEnum);
                            break;
                        case BinaryHeaderEnum.Object:
                            ReadObject();
                            break;
                        case BinaryHeaderEnum.CrossAppDomainMap:
                            ReadCrossAppDomainMap();
                            break;
                        case BinaryHeaderEnum.ObjectWithMap:
                        case BinaryHeaderEnum.ObjectWithMapAssemId:
                            ReadObjectWithMap(binaryHeaderEnum);
                            break;
                        case BinaryHeaderEnum.ObjectWithMapTyped:
                        case BinaryHeaderEnum.ObjectWithMapTypedAssemId:
                            ReadObjectWithMapTyped(binaryHeaderEnum);                                   
                            break;
#if FEATURE_REMOTING                            
                        case BinaryHeaderEnum.MethodCall:
                        case BinaryHeaderEnum.MethodReturn:
                            ReadMethodObject(binaryHeaderEnum);                                 
                            break;
#endif                            
                        case BinaryHeaderEnum.ObjectString:
                        case BinaryHeaderEnum.CrossAppDomainString:
                            ReadObjectString(binaryHeaderEnum);
                            break;
                        case BinaryHeaderEnum.Array:
                        case BinaryHeaderEnum.ArraySinglePrimitive:
                        case BinaryHeaderEnum.ArraySingleObject:
                        case BinaryHeaderEnum.ArraySingleString:
                            ReadArray(binaryHeaderEnum);
                            break;
                        case BinaryHeaderEnum.MemberPrimitiveTyped:
                            ReadMemberPrimitiveTyped();
                            break;                                                              
                        case BinaryHeaderEnum.MemberReference:
                            ReadMemberReference();
                            break;
                        case BinaryHeaderEnum.ObjectNull:
                        case BinaryHeaderEnum.ObjectNullMultiple256:
                        case BinaryHeaderEnum.ObjectNullMultiple:
                            ReadObjectNull(binaryHeaderEnum);
                            break;
                        case BinaryHeaderEnum.MessageEnd:
                            isLoop = false;
                            ReadMessageEnd();
                            ReadEnd();
                            break;
                        default:
                            throw new SerializationException(Environment.GetResourceString("Serialization_BinaryHeader",inByte));
                        }
                        break;
                    case BinaryTypeEnum.Primitive:
                        ReadMemberPrimitiveUnTyped();
                        break;
                    default:
                        throw new SerializationException(Environment.GetResourceString("Serialization_TypeExpected"));

                    }

                    // If an assembly is encountered, don't advance
                    // object Progress, 
                    if (binaryHeaderEnum != BinaryHeaderEnum.Assembly)
                    {
                        // End of parse loop.
                        bool isData = false;
                        // Set up loop for next iteration.
                        // If this is an object, and the end of object has been reached, then parse object end.
                        while (!isData)
                        {
                            ObjectProgress op = (ObjectProgress)stack.Peek();
                            if (op == null)
                            {
                                // No more object on stack, then the next record is a top level object
                                SerTrace.Log( this, "Run loop op null, top level object");                      
                                expectedType = BinaryTypeEnum.ObjectUrt;
                                expectedTypeInformation = null;
                                isData = true;
                            }
                            else
                            {
                                SerTrace.Log( this, "Run loop op not null, continue object");
                                // Find out what record is expected next
                                isData = op.GetNext(out op.expectedType, out op.expectedTypeInformation);
                                expectedType = op.expectedType;
                                expectedTypeInformation = op.expectedTypeInformation;
                                SerTrace.Log( this, "Run loop opName ",op.name,", expectedType ",((Enum)expectedType).ToString()," expectedTypeInformation, ",expectedTypeInformation);

                                SerTrace.Log( this, "Run ",isData);     
                                if (!isData)
                                {
                                    // No record is expected next, this is the end of an object or array
                                    SerTrace.Log( this, "Run End of Object ");
                                    stack.Dump();

                                    prs.Init();
                                    if (op.memberValueEnum == InternalMemberValueE.Nested)
                                    {
                                        // Nested object
                                        prs.PRparseTypeEnum = InternalParseTypeE.MemberEnd;
                                        prs.PRmemberTypeEnum = op.memberTypeEnum;
                                        prs.PRmemberValueEnum = op.memberValueEnum;
                                        objectReader.Parse(prs);
                                    }
                                    else
                                    {
                                        // Top level object
                                        prs.PRparseTypeEnum = InternalParseTypeE.ObjectEnd;
                                        prs.PRmemberTypeEnum = op.memberTypeEnum;
                                        prs.PRmemberValueEnum = op.memberValueEnum;                             
                                        objectReader.Parse(prs);
                                    }
                                    stack.Pop();
                                    PutOp(op);
                                }
                            }
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {

                // EOF should never be thrown since there is a MessageEnd record to stop parsing
                BCLDebug.Trace("BINARY", "\n*****EOF*************************\n");
                throw new SerializationException(Environment.GetResourceString("Serialization_StreamEnd"));             
            }
        }
        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            this.InternalWriteItemNull();
            int    objectId = (int)nameInfo.NIobjectId;
            string name     = objectId >= 0 ? nameInfo.NIname : typeNameInfo.NIname;

            if (this.objectMapTable == null)
            {
                this.objectMapTable = new Hashtable();
            }
            ObjectMapInfo objectMapInfo = (ObjectMapInfo)this.objectMapTable[(object)name];

            if (objectMapInfo != null && objectMapInfo.isCompatible(numMembers, memberNames, memberTypes))
            {
                if (this.binaryObject == null)
                {
                    this.binaryObject = new BinaryObject();
                }
                this.binaryObject.Set(objectId, objectMapInfo.objectId);
                this.binaryObject.Write(this);
            }
            else if (!typeNameInfo.NItransmitTypeOnObject)
            {
                if (this.binaryObjectWithMap == null)
                {
                    this.binaryObjectWithMap = new BinaryObjectWithMap();
                }
                int assemId = (int)typeNameInfo.NIassemId;
                this.binaryObjectWithMap.Set(objectId, name, numMembers, memberNames, assemId);
                this.binaryObjectWithMap.Dump();
                this.binaryObjectWithMap.Write(this);
                if (objectMapInfo != null)
                {
                    return;
                }
                this.objectMapTable.Add((object)name, (object)new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
            }
            else
            {
                BinaryTypeEnum[] binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                object[]         typeInformationA = new object[numMembers];
                int[]            memberAssemIds   = new int[numMembers];
                int assemId;
                for (int index = 0; index < numMembers; ++index)
                {
                    object typeInformation = (object)null;
                    binaryTypeEnumA[index]  = BinaryConverter.GetBinaryTypeInfo(memberTypes[index], memberObjectInfos[index], (string)null, this.objectWriter, out typeInformation, out assemId);
                    typeInformationA[index] = typeInformation;
                    memberAssemIds[index]   = assemId;
                }
                if (this.binaryObjectWithMapTyped == null)
                {
                    this.binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                }
                assemId = (int)typeNameInfo.NIassemId;
                this.binaryObjectWithMapTyped.Set(objectId, name, numMembers, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, assemId);
                this.binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo != null)
                {
                    return;
                }
                this.objectMapTable.Add((object)name, (object)new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
            }
        }
 internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
 {
     this.InternalWriteItemNull();
     int nIobjectId = (int) nameInfo.NIobjectId;
     string name = null;
     if (nIobjectId < 0)
     {
         name = typeNameInfo.NIname;
     }
     else
     {
         name = nameInfo.NIname;
     }
     if (this.objectMapTable == null)
     {
         this.objectMapTable = new Hashtable();
     }
     ObjectMapInfo info = (ObjectMapInfo) this.objectMapTable[name];
     if ((info != null) && info.isCompatible(numMembers, memberNames, memberTypes))
     {
         if (this.binaryObject == null)
         {
             this.binaryObject = new BinaryObject();
         }
         this.binaryObject.Set(nIobjectId, info.objectId);
         this.binaryObject.Write(this);
     }
     else
     {
         int nIassemId;
         if (!typeNameInfo.NItransmitTypeOnObject)
         {
             if (this.binaryObjectWithMap == null)
             {
                 this.binaryObjectWithMap = new BinaryObjectWithMap();
             }
             nIassemId = (int) typeNameInfo.NIassemId;
             this.binaryObjectWithMap.Set(nIobjectId, name, numMembers, memberNames, nIassemId);
             this.binaryObjectWithMap.Dump();
             this.binaryObjectWithMap.Write(this);
             if (info == null)
             {
                 this.objectMapTable.Add(name, new ObjectMapInfo(nIobjectId, numMembers, memberNames, memberTypes));
             }
         }
         else
         {
             BinaryTypeEnum[] binaryTypeEnumA = new BinaryTypeEnum[numMembers];
             object[] typeInformationA = new object[numMembers];
             int[] memberAssemIds = new int[numMembers];
             for (int i = 0; i < numMembers; i++)
             {
                 object typeInformation = null;
                 binaryTypeEnumA[i] = BinaryConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, this.objectWriter, out typeInformation, out nIassemId);
                 typeInformationA[i] = typeInformation;
                 memberAssemIds[i] = nIassemId;
             }
             if (this.binaryObjectWithMapTyped == null)
             {
                 this.binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
             }
             nIassemId = (int) typeNameInfo.NIassemId;
             this.binaryObjectWithMapTyped.Set(nIobjectId, name, numMembers, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, nIassemId);
             this.binaryObjectWithMapTyped.Write(this);
             if (info == null)
             {
                 this.objectMapTable.Add(name, new ObjectMapInfo(nIobjectId, numMembers, memberNames, memberTypes));
             }
         }
     }
 }
Example #38
0
        internal void Run()
        {
            try
            {
                bool flag = true;
                ReadBegin();
                ReadSerializationHeaderRecord();
                while (flag)
                {
                    BinaryHeaderEnum binaryHeaderEnum = BinaryHeaderEnum.Object;
                    BinaryTypeEnum   enum3            = expectedType;
                    if (enum3 == BinaryTypeEnum.Primitive)
                    {
                        ReadMemberPrimitiveUnTyped();
                    }
                    else
                    {
                        if (enum3 - (BinaryTypeEnum)1 > (int)BinaryTypeEnum.StringArray)
                        {
                            throw new SerializationException(RemotingResources.SerializationTypeExpected);
                        }
                        byte num = dataReader.ReadByte();
                        binaryHeaderEnum = (BinaryHeaderEnum)num;
                        switch (binaryHeaderEnum)
                        {
                        case BinaryHeaderEnum.Object:
                            ReadObject();
                            break;

                        case BinaryHeaderEnum.ObjectWithMap:
                        case BinaryHeaderEnum.ObjectWithMapAssemId:
                            ReadObjectWithMap(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.ObjectWithMapTyped:
                        case BinaryHeaderEnum.ObjectWithMapTypedAssemId:
                            ReadObjectWithMapTyped(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.ObjectString:
                        case BinaryHeaderEnum.CrossAppDomainString:
                            ReadObjectString(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.Array:
                        case BinaryHeaderEnum.ArraySinglePrimitive:
                        case BinaryHeaderEnum.ArraySingleObject:
                        case BinaryHeaderEnum.ArraySingleString:
                            ReadArray(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.MemberPrimitiveTyped:
                            ReadMemberPrimitiveTyped();
                            break;

                        case BinaryHeaderEnum.MemberReference:
                            ReadMemberReference();
                            break;

                        case BinaryHeaderEnum.ObjectNull:
                        case BinaryHeaderEnum.ObjectNullMultiple256:
                        case BinaryHeaderEnum.ObjectNullMultiple:
                            ReadObjectNull(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.MessageEnd:
                            flag = false;
                            ReadMessageEnd();
                            ReadEnd();
                            break;

                        case BinaryHeaderEnum.Assembly:
                        case BinaryHeaderEnum.CrossAppDomainAssembly:
                            ReadAssembly(binaryHeaderEnum);
                            break;

                        case BinaryHeaderEnum.CrossAppDomainMap:
                            ReadCrossAppDomainMap();
                            break;

                        default:
                            throw new SerializationException(RemotingResources.SerializationBinaryHeader.Format(num));
                        }
                    }
                    if (binaryHeaderEnum != BinaryHeaderEnum.Assembly)
                    {
                        bool next = false;
                        while (!next)
                        {
                            ObjectProgress op = (ObjectProgress)stack.Peek();
                            if (op == null)
                            {
                                expectedType            = BinaryTypeEnum.ObjectUrt;
                                expectedTypeInformation = null;
                                next = true;
                                continue;
                            }
                            next                    = op.GetNext(out op._expectedType, out op._expectedTypeInformation);
                            expectedType            = op._expectedType;
                            expectedTypeInformation = op._expectedTypeInformation;
                            if (!next)
                            {
                                PRs.Init();
                                if (op._memberValueEnum == MemberValueEnum.Nested)
                                {
                                    PRs.parseTypeEnum   = ParseTypeEnum.MemberEnd;
                                    PRs.memberTypeEnum  = op._memberTypeEnum;
                                    PRs.memberValueEnum = op._memberValueEnum;
                                    objectReader.Parse(PRs);
                                }
                                else
                                {
                                    PRs.parseTypeEnum   = ParseTypeEnum.ObjectEnd;
                                    PRs.memberTypeEnum  = op._memberTypeEnum;
                                    PRs.memberValueEnum = op._memberValueEnum;
                                    objectReader.Parse(PRs);
                                }
                                stack.Pop();
                                PutOp(op);
                            }
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                throw new SerializationException(RemotingResources.SerializationStreamEnd);
            }
        }
        internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum, object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, out InternalPrimitiveTypeE primitiveTypeEnum, out string typeString, out Type type, out bool isVariant)
        {
            isVariant = false;
            primitiveTypeEnum = InternalPrimitiveTypeE.Invalid;
            typeString = null;
            type = null;
            switch (binaryTypeEnum)
            {
                case BinaryTypeEnum.Primitive:
                    primitiveTypeEnum = (InternalPrimitiveTypeE) typeInformation;
                    typeString = Converter.ToComType(primitiveTypeEnum);
                    type = Converter.ToType(primitiveTypeEnum);
                    return;

                case BinaryTypeEnum.String:
                    type = Converter.typeofString;
                    return;

                case BinaryTypeEnum.Object:
                    type = Converter.typeofObject;
                    isVariant = true;
                    return;

                case BinaryTypeEnum.ObjectUrt:
                case BinaryTypeEnum.ObjectUser:
                    if (typeInformation == null)
                    {
                        break;
                    }
                    typeString = typeInformation.ToString();
                    type = objectReader.GetType(assemblyInfo, typeString);
                    if (!object.ReferenceEquals(type, Converter.typeofObject))
                    {
                        break;
                    }
                    isVariant = true;
                    return;

                case BinaryTypeEnum.ObjectArray:
                    type = Converter.typeofObjectArray;
                    return;

                case BinaryTypeEnum.StringArray:
                    type = Converter.typeofStringArray;
                    return;

                case BinaryTypeEnum.PrimitiveArray:
                    primitiveTypeEnum = (InternalPrimitiveTypeE) typeInformation;
                    type = Converter.ToArrayType(primitiveTypeEnum);
                    return;

                default:
                    throw new SerializationException(Environment.GetResourceString("Serialization_TypeRead", new object[] { binaryTypeEnum.ToString() }));
            }
        }
Example #40
0
        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            string str;

            this.InternalWriteItemNull();
            int objectId = (int)nameInfo._objectId;

            str = (objectId < 0) ? typeNameInfo.NIname : nameInfo.NIname;
            if (this._objectMapTable == null)
            {
                this._objectMapTable = new Dictionary <string, ObjectMapInfo>();
            }
            if (this._objectMapTable.TryGetValue(str, out ObjectMapInfo info) && info.IsCompatible(numMembers, memberNames, memberTypes))
            {
                if (this._binaryObject == null)
                {
                    this._binaryObject = new BinaryObject();
                }
                this._binaryObject.Set(objectId, info._objectId);
                this._binaryObject.Write(this);
            }
            else
            {
                int num;
                if (!typeNameInfo._transmitTypeOnObject)
                {
                    if (this._binaryObjectWithMap == null)
                    {
                        this._binaryObjectWithMap = new BinaryObjectWithMap();
                    }
                    num = (int)typeNameInfo._assemId;
                    this._binaryObjectWithMap.Set(objectId, str, numMembers, memberNames, num);
                    this._binaryObjectWithMap.Write(this);
                    if (info == null)
                    {
                        this._objectMapTable.Add(str, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                    }
                }
                else
                {
                    BinaryTypeEnum[] binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                    object[]         typeInformationA = new object[numMembers];
                    int[]            memberAssemIds   = new int[numMembers];
                    int index = 0;
                    while (true)
                    {
                        if (index >= numMembers)
                        {
                            if (this._binaryObjectWithMapTyped == null)
                            {
                                this._binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                            }
                            this._binaryObjectWithMapTyped.Set(objectId, str, numMembers, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, (int)typeNameInfo._assemId);
                            this._binaryObjectWithMapTyped.Write(this);
                            if (info == null)
                            {
                                this._objectMapTable.Add(str, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                            }
                            break;
                        }
                        binaryTypeEnumA[index]  = BinaryTypeConverter.GetBinaryTypeInfo(memberTypes[index], memberObjectInfos[index], this._objectWriter, out object typeInformation, out num);
                        typeInformationA[index] = typeInformation;
                        memberAssemIds[index]   = num;
                        index++;
                    }
                }
            }
        }
        //internal BinaryCrossAppDomainMap crossAppDomainMap;
 
        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, String[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        { 
            InternalWriteItemNull(); 
            int assemId;
#if _DEBUG 
            nameInfo.Dump("WriteObject nameInfo");
            typeNameInfo.Dump("WriteObject typeNameInfo");
#endif
 
            int objectId = (int)nameInfo.NIobjectId;
 
            //if (objectId < 0) 
            //  objectId = --m_nestedObjectCount;
 
            if (objectId > 0)
            {
                BCLDebug.Trace("BINARY", "-----Top Level Object-----");
            } 

            String objectName = null; 
            if (objectId < 0) 
            {
                // Nested Object 
                objectName = typeNameInfo.NIname;
            }
            else
            { 
                // Non-Nested
                objectName = nameInfo.NIname; 
            } 
            SerTrace.Log( this, "WriteObject objectName ",objectName);
 
            if (objectMapTable == null)
            {
                objectMapTable = new Hashtable();
            } 

            ObjectMapInfo objectMapInfo = (ObjectMapInfo)objectMapTable[objectName]; 
 
            if (objectMapInfo != null && objectMapInfo.isCompatible(numMembers, memberNames, memberTypes))
            { 
                // Object
                if (binaryObject == null)
                    binaryObject = new BinaryObject();
                binaryObject.Set(objectId, objectMapInfo.objectId); 
#if _DEBUG
                binaryObject.Dump(); 
#endif 
                binaryObject.Write(this);
            } 
            else if (!typeNameInfo.NItransmitTypeOnObject)
            {

                // ObjectWithMap 
                if (binaryObjectWithMap == null)
                    binaryObjectWithMap = new BinaryObjectWithMap(); 
 
                // BCL types are not placed into table
                assemId = (int)typeNameInfo.NIassemId; 
                binaryObjectWithMap.Set(objectId, objectName, numMembers, memberNames, assemId);

                binaryObjectWithMap.Dump();
                binaryObjectWithMap.Write(this); 
                if (objectMapInfo == null)
                    objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes)); 
            } 
            else
            { 
                // ObjectWithMapTyped
                BinaryTypeEnum[] binaryTypeEnumA = new BinaryTypeEnum[numMembers];
                Object[] typeInformationA = new Object[numMembers];
                int[] assemIdA = new int[numMembers]; 
                for (int i=0; i<numMembers; i++)
                { 
                    Object typeInformation = null; 

                    binaryTypeEnumA[i] = BinaryConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, objectWriter, out typeInformation, out assemId); 
                    typeInformationA[i] = typeInformation;
                    assemIdA[i] = assemId;
                    SerTrace.Log( this, "WriteObject ObjectWithMapTyped memberNames "
                                  ,memberNames[i],", memberType ",memberTypes[i]," binaryTypeEnum ",((Enum)binaryTypeEnumA[i]).ToString() 
                                  ,", typeInformation ",typeInformationA[i]," assemId ",assemIdA[i]);
                } 
 
                if (binaryObjectWithMapTyped == null)
                    binaryObjectWithMapTyped = new BinaryObjectWithMapTyped(); 

                // BCL types are not placed in table
                assemId = (int)typeNameInfo.NIassemId;
                binaryObjectWithMapTyped.Set(objectId, objectName, numMembers,memberNames, binaryTypeEnumA, typeInformationA, assemIdA, assemId); 
#if _DEBUG
                binaryObjectWithMapTyped.Dump(); 
#endif 
                binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo == null) 
                    objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
            }
        }
        internal void Run()
        {
            try
            {
                bool flag = true;
                this.ReadBegin();
                this.ReadSerializationHeaderRecord();
                while (flag)
                {
                    byte num;
                    BinaryHeaderEnum binaryHeaderEnum = BinaryHeaderEnum.Object;
                    switch (this.expectedType)
                    {
                        case BinaryTypeEnum.Primitive:
                            this.ReadMemberPrimitiveUnTyped();
                            goto Label_0177;

                        case BinaryTypeEnum.String:
                        case BinaryTypeEnum.Object:
                        case BinaryTypeEnum.ObjectUrt:
                        case BinaryTypeEnum.ObjectUser:
                        case BinaryTypeEnum.ObjectArray:
                        case BinaryTypeEnum.StringArray:
                        case BinaryTypeEnum.PrimitiveArray:
                            num = this.dataReader.ReadByte();
                            binaryHeaderEnum = (BinaryHeaderEnum) num;
                            switch (binaryHeaderEnum)
                            {
                                case BinaryHeaderEnum.Object:
                                    goto Label_00C9;

                                case BinaryHeaderEnum.ObjectWithMap:
                                case BinaryHeaderEnum.ObjectWithMapAssemId:
                                    goto Label_00DF;

                                case BinaryHeaderEnum.ObjectWithMapTyped:
                                case BinaryHeaderEnum.ObjectWithMapTypedAssemId:
                                    goto Label_00EB;

                                case BinaryHeaderEnum.ObjectString:
                                case BinaryHeaderEnum.CrossAppDomainString:
                                    goto Label_0100;

                                case BinaryHeaderEnum.Array:
                                case BinaryHeaderEnum.ArraySinglePrimitive:
                                case BinaryHeaderEnum.ArraySingleObject:
                                case BinaryHeaderEnum.ArraySingleString:
                                    goto Label_0109;

                                case BinaryHeaderEnum.MemberPrimitiveTyped:
                                    goto Label_0112;

                                case BinaryHeaderEnum.MemberReference:
                                    goto Label_011A;

                                case BinaryHeaderEnum.ObjectNull:
                                case BinaryHeaderEnum.ObjectNullMultiple256:
                                case BinaryHeaderEnum.ObjectNullMultiple:
                                    goto Label_0122;

                                case BinaryHeaderEnum.MessageEnd:
                                    goto Label_012B;

                                case BinaryHeaderEnum.CrossAppDomainMap:
                                    goto Label_00D4;

                                case BinaryHeaderEnum.MethodCall:
                                case BinaryHeaderEnum.MethodReturn:
                                    goto Label_00F7;
                            }
                            goto Label_013B;

                        default:
                            throw new SerializationException(Environment.GetResourceString("Serialization_TypeExpected"));
                    }
                    this.ReadAssembly(binaryHeaderEnum);
                    goto Label_0177;
                Label_00C9:
                    this.ReadObject();
                    goto Label_0177;
                Label_00D4:
                    this.ReadCrossAppDomainMap();
                    goto Label_0177;
                Label_00DF:
                    this.ReadObjectWithMap(binaryHeaderEnum);
                    goto Label_0177;
                Label_00EB:
                    this.ReadObjectWithMapTyped(binaryHeaderEnum);
                    goto Label_0177;
                Label_00F7:
                    this.ReadMethodObject(binaryHeaderEnum);
                    goto Label_0177;
                Label_0100:
                    this.ReadObjectString(binaryHeaderEnum);
                    goto Label_0177;
                Label_0109:
                    this.ReadArray(binaryHeaderEnum);
                    goto Label_0177;
                Label_0112:
                    this.ReadMemberPrimitiveTyped();
                    goto Label_0177;
                Label_011A:
                    this.ReadMemberReference();
                    goto Label_0177;
                Label_0122:
                    this.ReadObjectNull(binaryHeaderEnum);
                    goto Label_0177;
                Label_012B:
                    flag = false;
                    this.ReadMessageEnd();
                    this.ReadEnd();
                    goto Label_0177;
                Label_013B:;
                    throw new SerializationException(Environment.GetResourceString("Serialization_BinaryHeader", new object[] { num }));
                Label_0177:
                    if (binaryHeaderEnum != BinaryHeaderEnum.Assembly)
                    {
                        bool next = false;
                        while (!next)
                        {
                            ObjectProgress op = (ObjectProgress) this.stack.Peek();
                            if (op == null)
                            {
                                this.expectedType = BinaryTypeEnum.ObjectUrt;
                                this.expectedTypeInformation = null;
                                next = true;
                            }
                            else
                            {
                                next = op.GetNext(out op.expectedType, out op.expectedTypeInformation);
                                this.expectedType = op.expectedType;
                                this.expectedTypeInformation = op.expectedTypeInformation;
                                if (!next)
                                {
                                    this.prs.Init();
                                    if (op.memberValueEnum == InternalMemberValueE.Nested)
                                    {
                                        this.prs.PRparseTypeEnum = InternalParseTypeE.MemberEnd;
                                        this.prs.PRmemberTypeEnum = op.memberTypeEnum;
                                        this.prs.PRmemberValueEnum = op.memberValueEnum;
                                        this.objectReader.Parse(this.prs);
                                    }
                                    else
                                    {
                                        this.prs.PRparseTypeEnum = InternalParseTypeE.ObjectEnd;
                                        this.prs.PRmemberTypeEnum = op.memberTypeEnum;
                                        this.prs.PRmemberValueEnum = op.memberValueEnum;
                                        this.objectReader.Parse(this.prs);
                                    }
                                    this.stack.Pop();
                                    this.PutOp(op);
                                }
                            }
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_StreamEnd"));
            }
        }
Example #43
0
        // Parse the input
        // Reads each record from the input stream. If the record is a primitive type (A number)
        //  then it doesn't have a BinaryHeaderEnum byte. For this case the expected type
        //  has been previously set to Primitive
        internal void Run()
        {
            try
            {
                bool isLoop = true;
                ReadBegin();
                ReadSerializationHeaderRecord();
                while (isLoop)
                {
                    BinaryHeaderEnum binaryHeaderEnum = BinaryHeaderEnum.Object;
                    switch (_expectedType)
                    {
                        case BinaryTypeEnum.ObjectUrt:
                        case BinaryTypeEnum.ObjectUser:
                        case BinaryTypeEnum.String:
                        case BinaryTypeEnum.Object:
                        case BinaryTypeEnum.ObjectArray:
                        case BinaryTypeEnum.StringArray:
                        case BinaryTypeEnum.PrimitiveArray:
                            byte inByte = _dataReader.ReadByte();
                            binaryHeaderEnum = (BinaryHeaderEnum)inByte;
                            switch (binaryHeaderEnum)
                            {
                                case BinaryHeaderEnum.Assembly:
                                case BinaryHeaderEnum.CrossAppDomainAssembly:
                                    ReadAssembly(binaryHeaderEnum);
                                    break;
                                case BinaryHeaderEnum.Object:
                                    ReadObject();
                                    break;
                                case BinaryHeaderEnum.CrossAppDomainMap:
                                    ReadCrossAppDomainMap();
                                    break;
                                case BinaryHeaderEnum.ObjectWithMap:
                                case BinaryHeaderEnum.ObjectWithMapAssemId:
                                    ReadObjectWithMap(binaryHeaderEnum);
                                    break;
                                case BinaryHeaderEnum.ObjectWithMapTyped:
                                case BinaryHeaderEnum.ObjectWithMapTypedAssemId:
                                    ReadObjectWithMapTyped(binaryHeaderEnum);
                                    break;
                                case BinaryHeaderEnum.ObjectString:
                                case BinaryHeaderEnum.CrossAppDomainString:
                                    ReadObjectString(binaryHeaderEnum);
                                    break;
                                case BinaryHeaderEnum.Array:
                                case BinaryHeaderEnum.ArraySinglePrimitive:
                                case BinaryHeaderEnum.ArraySingleObject:
                                case BinaryHeaderEnum.ArraySingleString:
                                    ReadArray(binaryHeaderEnum);
                                    break;
                                case BinaryHeaderEnum.MemberPrimitiveTyped:
                                    ReadMemberPrimitiveTyped();
                                    break;
                                case BinaryHeaderEnum.MemberReference:
                                    ReadMemberReference();
                                    break;
                                case BinaryHeaderEnum.ObjectNull:
                                case BinaryHeaderEnum.ObjectNullMultiple256:
                                case BinaryHeaderEnum.ObjectNullMultiple:
                                    ReadObjectNull(binaryHeaderEnum);
                                    break;
                                case BinaryHeaderEnum.MessageEnd:
                                    isLoop = false;
                                    ReadMessageEnd();
                                    ReadEnd();
                                    break;
                                default:
                                    throw new SerializationException(SR.Format(SR.Serialization_BinaryHeader, inByte));
                            }
                            break;
                        case BinaryTypeEnum.Primitive:
                            ReadMemberPrimitiveUnTyped();
                            break;
                        default:
                            throw new SerializationException(SR.Serialization_TypeExpected);
                    }

                    // If an assembly is encountered, don't advance
                    // object Progress, 
                    if (binaryHeaderEnum != BinaryHeaderEnum.Assembly)
                    {
                        // End of parse loop.
                        bool isData = false;

                        // Set up loop for next iteration.
                        // If this is an object, and the end of object has been reached, then parse object end.
                        while (!isData)
                        {
                            ObjectProgress op = (ObjectProgress)_stack.Peek();
                            if (op == null)
                            {
                                // No more object on stack, then the next record is a top level object
                                _expectedType = BinaryTypeEnum.ObjectUrt;
                                _expectedTypeInformation = null;
                                isData = true;
                            }
                            else
                            {
                                // Find out what record is expected next
                                isData = op.GetNext(out op._expectedType, out op._expectedTypeInformation);
                                _expectedType = op._expectedType;
                                _expectedTypeInformation = op._expectedTypeInformation;

                                if (!isData)
                                {
                                    // No record is expected next, this is the end of an object or array
                                    PRs.Init();
                                    if (op._memberValueEnum == InternalMemberValueE.Nested)
                                    {
                                        // Nested object
                                        PRs._parseTypeEnum = InternalParseTypeE.MemberEnd;
                                        PRs._memberTypeEnum = op._memberTypeEnum;
                                        PRs._memberValueEnum = op._memberValueEnum;
                                        _objectReader.Parse(PRs);
                                    }
                                    else
                                    {
                                        // Top level object
                                        PRs._parseTypeEnum = InternalParseTypeE.ObjectEnd;
                                        PRs._memberTypeEnum = op._memberTypeEnum;
                                        PRs._memberValueEnum = op._memberValueEnum;
                                        _objectReader.Parse(PRs);
                                    }
                                    _stack.Pop();
                                    PutOp(op);
                                }
                            }
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                // EOF should never be thrown since there is a MessageEnd record to stop parsing
                throw new SerializationException(SR.Serialization_StreamEnd);
            }
        }
Example #44
0
        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            this.InternalWriteItemNull();
            int    nIobjectId = (int)nameInfo.NIobjectId;
            string name       = null;

            if (nIobjectId < 0)
            {
                name = typeNameInfo.NIname;
            }
            else
            {
                name = nameInfo.NIname;
            }
            if (this.objectMapTable == null)
            {
                this.objectMapTable = new Hashtable();
            }
            ObjectMapInfo info = (ObjectMapInfo)this.objectMapTable[name];

            if ((info != null) && info.isCompatible(numMembers, memberNames, memberTypes))
            {
                if (this.binaryObject == null)
                {
                    this.binaryObject = new BinaryObject();
                }
                this.binaryObject.Set(nIobjectId, info.objectId);
                this.binaryObject.Write(this);
            }
            else
            {
                int nIassemId;
                if (!typeNameInfo.NItransmitTypeOnObject)
                {
                    if (this.binaryObjectWithMap == null)
                    {
                        this.binaryObjectWithMap = new BinaryObjectWithMap();
                    }
                    nIassemId = (int)typeNameInfo.NIassemId;
                    this.binaryObjectWithMap.Set(nIobjectId, name, numMembers, memberNames, nIassemId);
                    this.binaryObjectWithMap.Dump();
                    this.binaryObjectWithMap.Write(this);
                    if (info == null)
                    {
                        this.objectMapTable.Add(name, new ObjectMapInfo(nIobjectId, numMembers, memberNames, memberTypes));
                    }
                }
                else
                {
                    BinaryTypeEnum[] binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                    object[]         typeInformationA = new object[numMembers];
                    int[]            memberAssemIds   = new int[numMembers];
                    for (int i = 0; i < numMembers; i++)
                    {
                        object typeInformation = null;
                        binaryTypeEnumA[i]  = BinaryConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, this.objectWriter, out typeInformation, out nIassemId);
                        typeInformationA[i] = typeInformation;
                        memberAssemIds[i]   = nIassemId;
                    }
                    if (this.binaryObjectWithMapTyped == null)
                    {
                        this.binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                    }
                    nIassemId = (int)typeNameInfo.NIassemId;
                    this.binaryObjectWithMapTyped.Set(nIobjectId, name, numMembers, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, nIassemId);
                    this.binaryObjectWithMapTyped.Write(this);
                    if (info == null)
                    {
                        this.objectMapTable.Add(name, new ObjectMapInfo(nIobjectId, numMembers, memberNames, memberTypes));
                    }
                }
            }
        }