public void ReadUInt16LE_WithValidUint16_ReadsData() { using MemoryStream ms = new MemoryStream(new byte[] { 0x10, 0x0 }); using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding()); var result = EndianUtility.ReadUInt16LE(br); Assert.Equal(16u, result); }
public void WriteUInt16LE_WithUInt16_WritesData() { using MemoryStream ms = new MemoryStream(new byte[2]); using BinaryWriter bw = new BinaryWriter(ms); EndianUtility.WriteUInt16LE(bw, 1234); ms.Seek(0, SeekOrigin.Begin); using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding()); Assert.Equal(1234u, EndianUtility.ReadUInt16LE(br)); }
private List <uint> ReadChunkTableValues(MemoryStream ms) { List <uint> valueList = new List <uint>(); using (BinaryReader br = new BinaryReader(ms, new ASCIIEncoding(), true)) { // get the offset information byte type = br.ReadByte(); // Get the size of each object in bytes int countByteSize = type - 12; uint count = 0; if (countByteSize == 1) { count = br.ReadByte(); } else if (countByteSize == 2) { count = EndianUtility.ReadUInt16LE(br); } else if (countByteSize == 4) { count = EndianUtility.ReadUInt32LE(br); } byte entrySizeType = br.ReadByte(); int entryByteSize = entrySizeType - 12; uint value = 0; // Read in the values for (int i = 0; i < count; i++) { if (countByteSize == 1) { value = br.ReadByte(); } if (entryByteSize == 2) { value = EndianUtility.ReadUInt16LE(br); } else if (entryByteSize == 4) { value = EndianUtility.ReadUInt32LE(br); } valueList.Add(value); } } return(valueList); }
public void ReadUInt16LE_WithInvalidUint16_ThrowsException() { using MemoryStream ms = new MemoryStream(new byte[] { 0x10 }); using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding()); Assert.Throws <System.IO.EndOfStreamException>(() => EndianUtility.ReadUInt16LE(br)); }