System.Runtime.Serialization.Formatters.Binary.BinaryCommon.SwapBytes C# (CSharp) Method

SwapBytes() public static method

public static SwapBytes ( byte byteArray, int size, int dataSize ) : void
byteArray byte
size int
dataSize int
return void
		public static void SwapBytes (byte[] byteArray, int size, int dataSize)
		{
			byte b;
			if (dataSize == 8) {
				for (int n=0; n<size; n+=8) {
					b = byteArray [n]; byteArray [n] = byteArray [n + 7]; byteArray [n + 7] = b;
					b = byteArray [n+1]; byteArray [n+1] = byteArray [n + 6]; byteArray [n + 6] = b;
					b = byteArray [n+2]; byteArray [n+2] = byteArray [n + 5]; byteArray [n + 5] = b;
					b = byteArray [n+3]; byteArray [n+3] = byteArray [n + 4]; byteArray [n + 4] = b;
				}
			} else if (dataSize == 4) {
				for (int n=0; n<size; n+=4) {
					b = byteArray [n]; byteArray [n] = byteArray [n + 3]; byteArray [n + 3] = b;
					b = byteArray [n+1]; byteArray [n+1] = byteArray [n + 2]; byteArray [n + 2] = b;
				}
			} else if (dataSize == 2) {
				for (int n=0; n<size; n+=2) {
					b = byteArray [n]; byteArray [n] = byteArray [n + 1]; byteArray [n + 1] = b;
				}
			}
		}
	}

Usage Example

示例#1
0
        private void BlockRead(BinaryReader reader, Array array, int dataSize)
        {
            int i = Buffer.ByteLength(array);

            if (this.arrayBuffer == null || (i > this.arrayBuffer.Length && this.arrayBuffer.Length != this.ArrayBufferLength))
            {
                this.arrayBuffer = new byte[(i > this.ArrayBufferLength) ? this.ArrayBufferLength : i];
            }
            int num = 0;

            while (i > 0)
            {
                int num2 = (i >= this.arrayBuffer.Length) ? this.arrayBuffer.Length : i;
                int num3 = 0;
                do
                {
                    int num4 = reader.Read(this.arrayBuffer, num3, num2 - num3);
                    if (num4 == 0)
                    {
                        break;
                    }
                    num3 += num4;
                }while (num3 < num2);
IL_A6:
                if (!BitConverter.IsLittleEndian && dataSize > 1)
                {
                    BinaryCommon.SwapBytes(this.arrayBuffer, num2, dataSize);
                }
                Buffer.BlockCopy(this.arrayBuffer, 0, array, num, num2);
                i   -= num2;
                num += num2;
                continue;
                goto IL_A6;
            }
        }
All Usage Examples Of System.Runtime.Serialization.Formatters.Binary.BinaryCommon::SwapBytes