protected override Variant fixupImpl() { var ref1 = elements["ref1"]; var ref2 = elements["ref2"]; var data = new BitStreamList(); data.Add(ref1.Value); data.Add(ref2.Value); data.Seek(0, System.IO.SeekOrigin.Begin); CRCTool crcTool = new CRCTool(); crcTool.Init(type); return(new Variant((uint)crcTool.crctablefast(data))); }
public void TestList() { BitStreamList lst = new BitStreamList(); lst.Add(new BitStream(new MemoryStream(Encoding.ASCII.GetBytes("Hello")))); lst.Add(new BitStream(new MemoryStream(Encoding.ASCII.GetBytes("World")))); Assert.AreEqual(0, lst.Position); Assert.AreEqual(0, lst.PositionBits); Assert.AreEqual(10, lst.Length); Assert.AreEqual(80, lst.LengthBits); long ret = lst.SeekBits(12, SeekOrigin.Begin); Assert.AreEqual(12, ret); Assert.AreEqual(1, lst.Position); Assert.AreEqual(12, lst.PositionBits); ret = lst.Seek(2, SeekOrigin.Current); Assert.AreEqual(3, ret); Assert.AreEqual(3, lst.Position); Assert.AreEqual(28, lst.PositionBits); ret = lst.SeekBits(-12, SeekOrigin.End); Assert.AreEqual(68, ret); Assert.AreEqual(8, lst.Position); Assert.AreEqual(68, lst.PositionBits); ulong bits; int b = lst.ReadBits(out bits, 15); Assert.AreEqual(12, b); Assert.AreEqual(0xc64, bits); Assert.AreEqual(lst.Length, lst.Position); Assert.AreEqual(lst.LengthBits, lst.PositionBits); lst.Add(new BitStream(new MemoryStream(Encoding.ASCII.GetBytes("!")))); Assert.AreEqual(10, lst.Position); Assert.AreEqual(80, lst.PositionBits); Assert.AreEqual(11, lst.Length); Assert.AreEqual(88, lst.LengthBits); ret = lst.SeekBits(-12, SeekOrigin.End); Assert.AreEqual(76, ret); Assert.AreEqual(9, lst.Position); Assert.AreEqual(76, lst.PositionBits); b = lst.ReadBits(out bits, 15); Assert.AreEqual(12, b); Assert.AreEqual(lst.Length, lst.Position); Assert.AreEqual(lst.LengthBits, lst.PositionBits); Assert.AreEqual(0x421, bits); var buf = new byte[3]; b = lst.Read(buf, 0, buf.Length); Assert.AreEqual(0, b); Assert.AreEqual(lst.Length, lst.Position); Assert.AreEqual(lst.LengthBits, lst.PositionBits); lst.Seek(-3, SeekOrigin.End); b = lst.Read(buf, 0, buf.Length); Assert.AreEqual(3, b); Assert.AreEqual(Encoding.ASCII.GetBytes("ld!"), buf); Assert.AreEqual(lst.Length, lst.Position); Assert.AreEqual(lst.LengthBits, lst.PositionBits); }