public void BitReadBoundariesTest() { var reader = new ByteReader(new byte[] { 0x01, 0x02 }); reader.GetBits(3); reader.GetBits(6); }
public void NormalOperationTest() { byte[] bytes = File.ReadAllBytes(Path.Combine("Files", "structdata.dat")); var reader = new ByteReader(bytes); Assert.AreEqual(35000, reader.GetUshort()); Assert.AreEqual(230, reader.GetByte()); Assert.AreEqual("spam", reader.GetString(4)); Assert.AreEqual(4211001100, reader.GetUint()); Assert.AreEqual(1, reader.GetBits(1)); Assert.AreEqual(2, reader.GetBits(4)); Assert.AreEqual(1, reader.GetBits(3)); Assert.AreEqual(10, reader.GetByte()); }
public void BitmodeBreakTest() { var reader = new ByteReader(new byte[] { 0x01, 0x02, 0x03 }); reader.GetUshort(); reader.GetBits(1); reader.GetByte(); }
/// <summary> /// Create new header from byte reader. /// </summary> public static DnsHeader FromByteReader(ByteReader byteReader) { var header = new DnsHeader(); header.ID = byteReader.GetUshort(); header.QR = byteReader.GetBits(1); header.OPCODE = byteReader.GetBits(4); header.AA = byteReader.GetBits(1); header.TC = byteReader.GetBits(1); header.RD = byteReader.GetBits(1); header.RA = byteReader.GetBits(1); header.Z = byteReader.GetBits(3); header.RCODE = byteReader.GetBits(4); header.QDCOUNT = byteReader.GetUshort(); header.ANCOUNT = byteReader.GetUshort(); header.NSCOUNT = byteReader.GetUshort(); header.ARCOUNT = byteReader.GetUshort(); return(header); }