[System.Security.SecurityCritical] // auto-generated internal void WriteSingleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, Array array) { InternalWriteItemNull(); #if _DEBUG arrayNameInfo.Dump("WriteSingleArray arrayNameInfo"); arrayElemTypeNameInfo.Dump("WriteSingleArray arrayElemTypeNameInfo"); #endif BinaryArrayTypeEnum binaryArrayTypeEnum; Int32[] lengthA = new Int32[1]; lengthA[0] = length; Int32[] lowerBoundA = null; Object typeInformation = null; if (lowerBound == 0) { binaryArrayTypeEnum = BinaryArrayTypeEnum.Single; } else { binaryArrayTypeEnum = BinaryArrayTypeEnum.SingleOffset; lowerBoundA = new Int32[1]; lowerBoundA[0] = lowerBound; } int assemId; BinaryTypeEnum binaryTypeEnum = BinaryConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo.NItype, objectInfo, arrayElemTypeNameInfo.NIname, objectWriter, out typeInformation, out assemId); if (binaryArray == null) { binaryArray = new BinaryArray(); } binaryArray.Set((int)arrayNameInfo.NIobjectId, (int)1, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, binaryArrayTypeEnum, assemId); if (arrayNameInfo.NIobjectId > 0) { BCLDebug.Trace("BINARY", "-----Top Level Object-----"); } #if _DEBUG binaryArray.Dump(); #endif binaryArray.Write(this); if (Converter.IsWriteAsByteArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum) && (lowerBound == 0)) { //array is written out as an array of bytes if (arrayElemTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Byte) { WriteBytes((Byte[])array); } else if (arrayElemTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Char) { WriteChars((char[])array); } else { WriteArrayAsBytes(array, Converter.TypeLength(arrayElemTypeNameInfo.NIprimitiveTypeEnum)); } } }
private void ReadArrayAsBytes(ParseRecord pr) { if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Byte) { pr.PRnewObj = (object)this.ReadBytes(pr.PRlengthA[0]); } else if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Char) { pr.PRnewObj = (object)this.ReadChars(pr.PRlengthA[0]); } else { int num1 = Converter.TypeLength(pr.PRarrayElementTypeCode); pr.PRnewObj = (object)Converter.CreatePrimitiveArray(pr.PRarrayElementTypeCode, pr.PRlengthA[0]); Array dst = (Array)pr.PRnewObj; int num2 = 0; if (this.byteBuffer == null) { this.byteBuffer = new byte[4096]; } while (num2 < dst.Length) { int num3 = Math.Min(4096 / num1, dst.Length - num2); int num4 = num3 * num1; this.ReadBytes(this.byteBuffer, 0, num4); Buffer.InternalBlockCopy((Array)this.byteBuffer, 0, dst, num2 * num1, num4); num2 += num3; } } }
private void ReadArrayAsBytes(ParseRecord pr) { if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Byte) { pr.PRnewObj = this.ReadBytes(pr.PRlengthA[0]); } else if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Char) { pr.PRnewObj = this.ReadChars(pr.PRlengthA[0]); } else { int num = Converter.TypeLength(pr.PRarrayElementTypeCode); pr.PRnewObj = Converter.CreatePrimitiveArray(pr.PRarrayElementTypeCode, pr.PRlengthA[0]); Array pRnewObj = (Array)pr.PRnewObj; int num2 = 0; if (this.byteBuffer == null) { this.byteBuffer = new byte[0x1000]; } while (num2 < pRnewObj.Length) { int num3 = Math.Min((int)(0x1000 / num), (int)(pRnewObj.Length - num2)); int size = num3 * num; this.ReadBytes(this.byteBuffer, 0, size); Buffer.InternalBlockCopy(this.byteBuffer, 0, pRnewObj, num2 * num, size); num2 += num3; } } }
internal void WriteSingleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, Array array) { InternalWriteItemNull(); BinaryArrayTypeEnum binaryArrayTypeEnum; var lengthA = new int[1]; lengthA[0] = length; int[] lowerBoundA = null; object typeInformation = null; if (lowerBound == 0) { binaryArrayTypeEnum = BinaryArrayTypeEnum.Single; } else { binaryArrayTypeEnum = BinaryArrayTypeEnum.SingleOffset; lowerBoundA = new int[1]; lowerBoundA[0] = lowerBound; } int assemId; BinaryTypeEnum binaryTypeEnum = BinaryTypeConverter.GetBinaryTypeInfo( arrayElemTypeNameInfo._type, objectInfo, arrayElemTypeNameInfo.NIname, _objectWriter, out typeInformation, out assemId); if (_binaryArray == null) { _binaryArray = new BinaryArray(); } _binaryArray.Set((int)arrayNameInfo._objectId, 1, lengthA, lowerBoundA, binaryTypeEnum, typeInformation, binaryArrayTypeEnum, assemId); _binaryArray.Write(this); if (Converter.IsWriteAsByteArray(arrayElemTypeNameInfo._primitiveTypeEnum) && (lowerBound == 0)) { //array is written out as an array of bytes if (arrayElemTypeNameInfo._primitiveTypeEnum == InternalPrimitiveTypeE.Byte) { WriteBytes((byte[])array); } else if (arrayElemTypeNameInfo._primitiveTypeEnum == InternalPrimitiveTypeE.Char) { WriteChars((char[])array); } else { WriteArrayAsBytes(array, Converter.TypeLength(arrayElemTypeNameInfo._primitiveTypeEnum)); } } }
internal void WriteSingleArray(NameInfo memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, int length, int lowerBound, Array array) { this.InternalWriteItemNull(); int[] lengthA = new int[] { length }; int[] lowerBoundA = null; object typeInformation = null; BinaryArrayTypeEnum binaryArrayTypeEnum; if (lowerBound == 0) { binaryArrayTypeEnum = BinaryArrayTypeEnum.Single; } else { binaryArrayTypeEnum = BinaryArrayTypeEnum.SingleOffset; lowerBoundA = new int[] { lowerBound }; } int assemId; BinaryTypeEnum binaryTypeInfo = BinaryConverter.GetBinaryTypeInfo(arrayElemTypeNameInfo.NItype, objectInfo, arrayElemTypeNameInfo.NIname, this.objectWriter, out typeInformation, out assemId); if (this.binaryArray == null) { this.binaryArray = new BinaryArray(); } this.binaryArray.Set((int)arrayNameInfo.NIobjectId, 1, lengthA, lowerBoundA, binaryTypeInfo, typeInformation, binaryArrayTypeEnum, assemId); long niobjectId = arrayNameInfo.NIobjectId; this.binaryArray.Write(this); if (Converter.IsWriteAsByteArray(arrayElemTypeNameInfo.NIprimitiveTypeEnum) && lowerBound == 0) { if (arrayElemTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Byte) { this.WriteBytes((byte[])array); return; } if (arrayElemTypeNameInfo.NIprimitiveTypeEnum == InternalPrimitiveTypeE.Char) { this.WriteChars((char[])array); return; } this.WriteArrayAsBytes(array, Converter.TypeLength(arrayElemTypeNameInfo.NIprimitiveTypeEnum)); } }
private void ReadArrayAsBytes(ParseRecord pr) { Debug.Assert(pr._lengthA != null); if (pr._arrayElementTypeCode == InternalPrimitiveTypeE.Byte) { pr._newObj = ReadBytes(pr._lengthA[0]); } else if (pr._arrayElementTypeCode == InternalPrimitiveTypeE.Char) { pr._newObj = ReadChars(pr._lengthA[0]); } else { int typeLength = Converter.TypeLength(pr._arrayElementTypeCode); pr._newObj = Converter.CreatePrimitiveArray(pr._arrayElementTypeCode, pr._lengthA[0]); Debug.Assert((pr._newObj != null), "[BinaryParser expected a Primitive Array]"); Array array = (Array)pr._newObj; int arrayOffset = 0; if (_byteBuffer == null) { _byteBuffer = new byte[ChunkSize]; } while (arrayOffset < array.Length) { int numArrayItems = Math.Min(ChunkSize / typeLength, array.Length - arrayOffset); int bufferUsed = numArrayItems * typeLength; ReadBytes(_byteBuffer, 0, bufferUsed); if (!BitConverter.IsLittleEndian) { // we know that we are reading a primitive type, so just do a simple swap Debug.Fail("Re-review this code if/when we start running on big endian systems"); for (int i = 0; i < bufferUsed; i += typeLength) { for (int j = 0; j < typeLength / 2; j++) { byte tmp = _byteBuffer[i + j]; _byteBuffer[i + j] = _byteBuffer[i + typeLength - 1 - j]; _byteBuffer[i + typeLength - 1 - j] = tmp; } } } Buffer.BlockCopy(_byteBuffer, 0, array, arrayOffset * typeLength, bufferUsed); arrayOffset += numArrayItems; } } }
private void ReadArrayAsBytes(ParseRecord pr) { if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Byte) { pr.PRnewObj = ReadBytes(pr.PRlengthA[0]); } else if (pr.PRarrayElementTypeCode == InternalPrimitiveTypeE.Char) { pr.PRnewObj = ReadChars(pr.PRlengthA[0]); } else { int typeLength = Converter.TypeLength(pr.PRarrayElementTypeCode); pr.PRnewObj = Converter.CreatePrimitiveArray(pr.PRarrayElementTypeCode, pr.PRlengthA[0]); //pr.PRnewObj = Array.CreateInstance(pr.PRarrayElementType, pr.PRlengthA[0]); BCLDebug.Assert((pr.PRnewObj != null), "[BinaryParser expected a Primitive Array]"); Array array = (Array)pr.PRnewObj; int arrayOffset = 0; if (byteBuffer == null) { byteBuffer = new byte[chunkSize]; } while (arrayOffset < array.Length) { int numArrayItems = Math.Min(chunkSize / typeLength, array.Length - arrayOffset); int bufferUsed = numArrayItems * typeLength; ReadBytes(byteBuffer, 0, bufferUsed); Buffer.InternalBlockCopy(byteBuffer, 0, array, arrayOffset * typeLength, bufferUsed); arrayOffset += numArrayItems; } } }