public override void Read(BinaryParser input) { this.ObjectId = input.ReadInt32(); this.Name = input.ReadString(); this.NumMembers = input.ReadInt32(); this.MemberNames = new string[this.NumMembers]; this.BinaryTypeEnumArray = new BinaryTypeEnum[this.NumMembers]; this.TypeInformationArray = new object[this.NumMembers]; this.MemberAssemIds = new int[this.NumMembers]; for (int i = 0; i < this.NumMembers; i++) { this.MemberNames[i] = input.ReadString(); } for (int j = 0; j < this.NumMembers; j++) { this.BinaryTypeEnumArray[j] = (BinaryTypeEnum)input.ReadByte(); } for (int k = 0; k < this.NumMembers; k++) { if ((this.BinaryTypeEnumArray[k] != BinaryTypeEnum.ObjectUrt) && (this.BinaryTypeEnumArray[k] != BinaryTypeEnum.ObjectUser)) { this.TypeInformationArray[k] = BinaryTypeConverter.ReadTypeInfo(this.BinaryTypeEnumArray[k], input, out this.MemberAssemIds[k]); } else { BinaryTypeConverter.ReadTypeInfo(this.BinaryTypeEnumArray[k], input, out this.MemberAssemIds[k]); } } if (this.BinaryHeaderEnum == BinaryHeaderEnum.ObjectWithMapTypedAssemId) { this.AssemId = input.ReadInt32(); } }
public 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(RemotingResources.SerializationAssemblyNotFound.Format(objectName)); } this._objectType = objectReader.GetType(assemblyInfo, objectName); this._memberTypes = new Type[memberNames.Length]; for (int i = 0; i < memberNames.Length; i++) { BinaryTypeConverter.TypeFromInfo(binaryTypeEnumA[i], typeInformationA[i], objectReader, (BinaryAssemblyInfo)assemIdToAssemblyTable[memberAssemIds[i]], out _, out _, out Type type, out _); 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 WriteRectangleArray(/*NameInfo memberNameInfo,*/ NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int rank, int[] lengthA, int[] lowerBoundA) { this.InternalWriteItemNull(); BinaryArrayTypeEnum rectangular = BinaryArrayTypeEnum.Rectangular; BinaryTypeEnum binaryTypeEnum = BinaryTypeConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo._type, objectInfo, this._objectWriter, out object typeInformation, out int assemId); if (this._binaryArray == null) { this._binaryArray = new BinaryArray(); } int index = 0; while (true) { if (index < rank) { if (lowerBoundA[index] == 0) { index++; continue; } rectangular = BinaryArrayTypeEnum.RectangularOffset; } this._binaryArray.Set((int)arrayNameInfo._objectId, rank, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, rectangular, assemId); this._binaryArray.Write(this); return; } }
internal void WriteJaggedArray(NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound) { BinaryArrayTypeEnum jagged; this.InternalWriteItemNull(); int[] lengthA = new int[] { length }; int[] lowerBoundA = null; if (lowerBound == 0) { jagged = BinaryArrayTypeEnum.Jagged; } else { jagged = BinaryArrayTypeEnum.JaggedOffset; lowerBoundA = new int[] { lowerBound }; } BinaryTypeEnum binaryTypeEnum = BinaryTypeConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo._type, objectInfo, _objectWriter, out object typeInformation, out int assemId); if (this._binaryArray == null) { this._binaryArray = new BinaryArray(); } this._binaryArray.Set((int)arrayNameInfo._objectId, 1, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, jagged, assemId); this._binaryArray.Write(this); }
public override 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 = (PrimitiveTypeEnum)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 = BinaryTypeConverter.ReadTypeInfo(this._binaryTypeEnum, input, out this._assemId); }
public ObjectMap(string objectName, Type objectType, string[] memberNames, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo) { this._isInitObjectInfo = true; this._objectName = objectName; this._objectType = objectType; this._memberNames = memberNames; this._objectReader = objectReader; this._objectId = objectId; this._assemblyInfo = assemblyInfo; this._objectInfo = objectReader.CreateReadObjectInfo(objectType); this._memberTypes = this._objectInfo.GetMemberTypes(memberNames, objectType); this._binaryTypeEnumA = new BinaryTypeEnum[this._memberTypes.Length]; this._typeInformationA = new object[this._memberTypes.Length]; for (int i = 0; i < this._memberTypes.Length; i++) { this._binaryTypeEnumA[i] = BinaryTypeConverter.GetParserBinaryTypeInfo(this._memberTypes[i], out object typeInformation); this._typeInformationA[i] = typeInformation; } }
public override void Write(BinaryFormatterWriter output) { switch (this._binaryHeaderEnum) { case BinaryHeaderEnum.ArraySinglePrimitive: output.Write((byte)this._binaryHeaderEnum); output.Write(this.ObjectId); output.Write(this._lengthA[0]); output.Write((byte)((PrimitiveTypeEnum)this._typeInformation)); return; case BinaryHeaderEnum.ArraySingleObject: output.Write((byte)this._binaryHeaderEnum); output.Write(this.ObjectId); output.Write(this._lengthA[0]); return; case BinaryHeaderEnum.ArraySingleString: output.Write((byte)this._binaryHeaderEnum); output.Write(this.ObjectId); output.Write(this._lengthA[0]); return; } output.Write((byte)this._binaryHeaderEnum); output.Write(this.ObjectId); output.Write((byte)this._binaryArrayTypeEnum); output.Write(this._rank); for (int i = 0; i < this._rank; i++) { output.Write(this._lengthA[i]); } if ((this._binaryArrayTypeEnum == BinaryArrayTypeEnum.SingleOffset) || ((this._binaryArrayTypeEnum == BinaryArrayTypeEnum.JaggedOffset) || (this._binaryArrayTypeEnum == BinaryArrayTypeEnum.RectangularOffset))) { for (int j = 0; j < this._rank; j++) { output.Write(this._lowerBoundA[j]); } } output.Write((byte)this._binaryTypeEnum); BinaryTypeConverter.WriteTypeInfo(this._binaryTypeEnum, this._typeInformation, this._assemId, output); }
internal void WriteSingleArray(/*NameInfo memberNameInfo,*/ NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, Array array) { BinaryArrayTypeEnum single; this.InternalWriteItemNull(); int[] lengthA = new int[] { length }; int[] lowerBoundA = null; if (lowerBound == 0) { single = BinaryArrayTypeEnum.Single; } else { single = BinaryArrayTypeEnum.SingleOffset; lowerBoundA = new int[] { lowerBound }; } BinaryTypeEnum binaryTypeEnum = BinaryTypeConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo._type, objectInfo, this._objectWriter, out object typeInformation, out int num); if (this._binaryArray == null) { this._binaryArray = new BinaryArray(); } this._binaryArray.Set((int)arrayNameInfo._objectId, 1, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, single, num); this._binaryArray.Write(this); if (Converter.IsWriteAsByteArray(arrayElemTypeNameInfo._primitiveTypeEnum) && (lowerBound == 0)) { if (arrayElemTypeNameInfo._primitiveTypeEnum == PrimitiveTypeEnum.Byte) { this.Write((byte[])array); } else if (arrayElemTypeNameInfo._primitiveTypeEnum == PrimitiveTypeEnum.Char) { this.Write((char[])array); } else { this.WriteArrayAsBytes(array, Converter.TypeLength(arrayElemTypeNameInfo._primitiveTypeEnum)); } } }
public override void Write(BinaryFormatterWriter output) { output.Write((byte)this.BinaryHeaderEnum); output.Write(this.ObjectId); output.Write(this.Name); output.Write(this.NumMembers); for (int i = 0; i < this.NumMembers; i++) { output.Write(this.MemberNames[i]); } for (int j = 0; j < this.NumMembers; j++) { output.Write((byte)this.BinaryTypeEnumArray[j]); } for (int k = 0; k < this.NumMembers; k++) { BinaryTypeConverter.WriteTypeInfo(this.BinaryTypeEnumArray[k], this.TypeInformationArray[k], this.MemberAssemIds[k], output); } if (this.AssemId > 0) { output.Write(this.AssemId); } }
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++; } } } }
private void ReadArray(BinaryHeaderEnum binaryHeaderEnum) { BinaryArray array = new BinaryArray(binaryHeaderEnum); array.Read(this); BinaryAssemblyInfo assemblyInfo; if (array._binaryTypeEnum != BinaryTypeEnum.ObjectUser) { assemblyInfo = SystemAssemblyInfo; } else { if (array._assemId < 1) { throw new SerializationException(RemotingResources.SerializationAssemblyId.Format(array._typeInformation)); } assemblyInfo = (BinaryAssemblyInfo)AssemIdToAssemblyTable[array._assemId]; } ObjectProgress op = GetOp(); ParseRecord pr = op._pr; op._objectTypeEnum = ObjectTypeEnum.Array; op._binaryTypeEnum = array._binaryTypeEnum; op._typeInformation = array._typeInformation; ObjectProgress progress2 = (ObjectProgress)stack.PeekPeek(); if (progress2 == null || array.ObjectId > 0) { op._name = "System.Array"; pr.parseTypeEnum = ParseTypeEnum.Object; op._memberValueEnum = MemberValueEnum.Empty; } else { pr.parseTypeEnum = ParseTypeEnum.Member; pr.memberValueEnum = MemberValueEnum.Nested; op._memberValueEnum = MemberValueEnum.Nested; ObjectTypeEnum ee = progress2._objectTypeEnum; if (ee == ObjectTypeEnum.Object) { pr.name = progress2._name; pr.memberTypeEnum = MemberTypeEnum.Field; op._memberTypeEnum = MemberTypeEnum.Field; pr.keyDt = progress2._name; pr.dtType = progress2._dtType; } else { if (ee != ObjectTypeEnum.Array) { throw new SerializationException(RemotingResources.SerializationObjectTypeEnum.Format(progress2._objectTypeEnum.ToString())); } pr.memberTypeEnum = MemberTypeEnum.Item; op._memberTypeEnum = MemberTypeEnum.Item; } } pr.objectId = objectReader.GetId((long)array.ObjectId); pr.objectPositionEnum = pr.objectId != topId ? headerId <= 0L || pr.objectId != headerId ? ObjectPositionEnum.Child : ObjectPositionEnum.Headers : ObjectPositionEnum.Top; pr.objectTypeEnum = ObjectTypeEnum.Array; BinaryTypeConverter.TypeFromInfo(array._binaryTypeEnum, array._typeInformation, objectReader, assemblyInfo, out pr.arrayElementTypeCode, out pr.arrayElementTypeString, out pr.arrayElementType, out pr.isArrayVariant); pr.dtTypeCode = PrimitiveTypeEnum.Invalid; pr.rank = array._rank; pr.lengthA = array._lengthA; pr.lowerBoundA = array._lowerBoundA; bool flag = false; switch (array._binaryArrayTypeEnum) { case BinaryArrayTypeEnum.Single: case BinaryArrayTypeEnum.SingleOffset: op._numItems = array._lengthA[0]; pr.arrayTypeEnum = ArrayTypeEnum.Single; if (Converter.IsWriteAsByteArray(pr.arrayElementTypeCode) && array._lowerBoundA[0] == 0) { flag = true; ReadArrayAsBytes(pr); } break; case BinaryArrayTypeEnum.Jagged: case BinaryArrayTypeEnum.JaggedOffset: op._numItems = array._lengthA[0]; pr.arrayTypeEnum = ArrayTypeEnum.Jagged; break; case BinaryArrayTypeEnum.Rectangular: case BinaryArrayTypeEnum.RectangularOffset: { int num = 1; int index = 0; while (true) { if (index >= array._rank) { op._numItems = num; pr.arrayTypeEnum = ArrayTypeEnum.Rectangular; break; } num *= array._lengthA[index]; index++; } break; } default: throw new SerializationException(RemotingResources.SerializationArrayType.Format(array._binaryArrayTypeEnum.ToString())); } if (!flag) { stack.Push(op); } else { PutOp(op); } objectReader.Parse(pr); if (flag) { pr.parseTypeEnum = ParseTypeEnum.ObjectEnd; objectReader.Parse(pr); } }