public void Write(byte[] ABuffer, int offset) { ByteArrayUtility.WriteInt32(ABuffer, offset, Major); ByteArrayUtility.WriteInt32(ABuffer, offset + sizeof(int), Minor); ByteArrayUtility.WriteInt32(ABuffer, offset + sizeof(int) * 2, Revision); ByteArrayUtility.WriteInt32(ABuffer, offset + sizeof(int) * 3, Build); }
public static VersionNumber Read(byte[] ABuffer, int offset) { return (new VersionNumber ( ByteArrayUtility.ReadInt32(ABuffer, offset), ByteArrayUtility.ReadInt32(ABuffer, offset + sizeof(int)), ByteArrayUtility.ReadInt32(ABuffer, offset + sizeof(int) * 2), ByteArrayUtility.ReadInt32(ABuffer, offset + sizeof(int) * 3) )); }
public void WriteWithEndiannessTest() { const int intNumber = 0x12345678; var bytesPreserved = new byte[4]; var bytesReversed = new byte[4]; var bytesBigEndian = new byte[4]; var bytesLittleEndian = new byte[4]; unsafe { fixed(byte *pBytesPreserved = &bytesPreserved[0]) fixed(byte *pBytesReversed = &bytesReversed[0]) fixed(byte *pBytesBigEndian = &bytesBigEndian[0]) fixed(byte *pBytesLittleEndian = &bytesLittleEndian[0]) { ByteArrayUtility.WriteWithEndiannessPreserved(pBytesPreserved, intNumber); ByteArrayUtility.WriteWithEndiannessReversed(pBytesReversed, intNumber); ByteArrayUtility.WriteInBigEndian(pBytesBigEndian, intNumber); ByteArrayUtility.WriteInLittleEndian(pBytesLittleEndian, intNumber); } } if (BitConverter.IsLittleEndian) { Assert.Equal(new byte[] { 0x78, 0x56, 0x34, 0x12 }, bytesPreserved); Assert.Equal(new byte[] { 0x12, 0x34, 0x56, 0x78 }, bytesReversed); } else { Assert.Equal(new byte[] { 0x12, 0x34, 0x56, 0x78 }, bytesPreserved); Assert.Equal(new byte[] { 0x78, 0x56, 0x34, 0x12 }, bytesReversed); } Assert.Equal(new byte[] { 0x12, 0x34, 0x56, 0x78 }, bytesBigEndian); Assert.Equal(new byte[] { 0x78, 0x56, 0x34, 0x12 }, bytesLittleEndian); }
public override void ReadFromPhysical(byte[] buffer, int offset) { _iD = ByteArrayUtility.ReadInt32(buffer, offset); }
public override void WriteToPhysical(byte[] buffer, int offset, bool expandStreams) { ByteArrayUtility.WriteInt32(buffer, offset, _iD); }
public static StreamID Read(byte[] ABuffer, int offset) { return(new StreamID((ulong)ByteArrayUtility.ReadInt64(ABuffer, offset))); }
public void Write(byte[] ABuffer, int offset) { ByteArrayUtility.WriteInt64(ABuffer, offset, (long)Value); }
public void TestByteArrayUtility() { // short | int | long | decimal | guid | string byte[] LBuffer = new byte[sizeof(short) + sizeof(int) + sizeof(long) + sizeof(decimal) + 16 + 12]; int LOffset = 0; ByteArrayUtility.WriteInt16(LBuffer, LOffset, Int16.MinValue); if (ByteArrayUtility.ReadInt16(LBuffer, LOffset) != Int16.MinValue) { throw new Exception("Int16 failed"); } ByteArrayUtility.WriteInt16(LBuffer, LOffset, Int16.MaxValue); if (ByteArrayUtility.ReadInt16(LBuffer, LOffset) != Int16.MaxValue) { throw new Exception("Int16 failed"); } LOffset += sizeof(short); ByteArrayUtility.WriteInt32(LBuffer, LOffset, Int32.MinValue); if (ByteArrayUtility.ReadInt32(LBuffer, LOffset) != Int32.MinValue) { throw new Exception("Int32 failed"); } ByteArrayUtility.WriteInt32(LBuffer, LOffset, Int32.MaxValue); if (ByteArrayUtility.ReadInt32(LBuffer, LOffset) != Int32.MaxValue) { throw new Exception("Int32 failed"); } LOffset += sizeof(int); ByteArrayUtility.WriteInt64(LBuffer, LOffset, Int64.MinValue); if (ByteArrayUtility.ReadInt64(LBuffer, LOffset) != Int64.MinValue) { throw new Exception("Int64 failed"); } ByteArrayUtility.WriteInt64(LBuffer, LOffset, Int64.MaxValue); if (ByteArrayUtility.ReadInt64(LBuffer, LOffset) != Int64.MaxValue) { throw new Exception("Int64 failed"); } LOffset += sizeof(long); ByteArrayUtility.WriteDecimal(LBuffer, LOffset, Decimal.MinValue); if (ByteArrayUtility.ReadDecimal(LBuffer, LOffset) != Decimal.MinValue) { throw new Exception("Decimal failed"); } ByteArrayUtility.WriteDecimal(LBuffer, LOffset, Decimal.MaxValue); if (ByteArrayUtility.ReadDecimal(LBuffer, LOffset) != Decimal.MaxValue) { throw new Exception("Decimal failed"); } LOffset += sizeof(decimal); Guid LGuid = Guid.NewGuid(); ByteArrayUtility.WriteGuid(LBuffer, LOffset, LGuid); if (ByteArrayUtility.ReadGuid(LBuffer, LOffset) != LGuid) { throw new Exception("Guid failed"); } LOffset += 16; string LString = "Test"; ByteArrayUtility.WriteString(LBuffer, LOffset, LString); if (ByteArrayUtility.ReadString(LBuffer, LOffset) != LString) { throw new Exception("String failed"); } }
public override void Write(object tempValue, byte[] buffer, int offset) { ByteArrayUtility.WriteGuid(buffer, offset, (Guid)tempValue); }
public override object Read(byte[] buffer, int offset) { return(ByteArrayUtility.ReadGuid(buffer, offset)); }
public override void Write(object tempValue, byte[] buffer, int offset) { ByteArrayUtility.WriteInt64(buffer, offset, ((TimeSpan)tempValue).Ticks); }
public override object Read(byte[] buffer, int offset) { return(new TimeSpan(ByteArrayUtility.ReadInt64(buffer, offset))); }
public override void Write(object tempValue, byte[] buffer, int offset) { ByteArrayUtility.WriteDecimal(buffer, offset, (decimal)tempValue); }
public override void Write(object tempValue, byte[] buffer, int offset) { ByteArrayUtility.WriteInt64(buffer, offset, (long)tempValue); }