public void Can_deserialize_struct_from_disk_with_offset() { var fileName = Path.Combine(Setup.Dir, "Can_deserialize_struct_from_disk_with_offset.tri"); var node1 = new LcrsNode("a00100000000000000000000"); var node2 = new LcrsNode("b00100000000000000000000"); using (var fs = new FileStream(fileName, FileMode.Create)) { var bytes = LcrsTrieSerializer.TypeToBytes(node1); fs.Write(bytes, 0, bytes.Length); bytes = LcrsTrieSerializer.TypeToBytes(node2); fs.Write(bytes, 0, bytes.Length); } using (var fs = new FileStream(fileName, FileMode.Open)) { var len = Marshal.SizeOf(typeof(LcrsNode)); var buffer = new byte[len]; fs.Seek(len, SeekOrigin.Begin); fs.Read(buffer, 0, buffer.Length); var resurrected = LcrsTrieSerializer.BytesToType <LcrsNode>(buffer); Assert.That(resurrected.Value, Is.EqualTo(node2.Value)); } }
public void Can_serialize_struct() { var node = new LcrsNode("a00100000000000000000000"); var bytes = LcrsTrieSerializer.TypeToBytes(node); var resurrected = LcrsTrieSerializer.BytesToType <LcrsNode>(bytes); Assert.That(resurrected.Value, Is.EqualTo(node.Value)); Assert.IsTrue(resurrected.EndOfWord); }
public void Can_deserialize_struct_from_disk() { var fileName = Path.Combine(Setup.Dir, "Can_deserialize_struct_from_disk.tri"); var node = new LcrsNode("ä00100000000000000000000"); using (var fs = new FileStream(fileName, FileMode.Create)) { var bytes = LcrsTrieSerializer.TypeToBytes(node); fs.Write(bytes, 0, bytes.Length); } using (var fs = new FileStream(fileName, FileMode.Open)) { var len = Marshal.SizeOf(typeof(LcrsNode)); var buffer = new byte[len]; fs.Read(buffer, 0, buffer.Length); var resurrected = LcrsTrieSerializer.BytesToType <LcrsNode>(buffer); Assert.That(resurrected.Value, Is.EqualTo(node.Value)); Assert.IsTrue(resurrected.EndOfWord); } }
protected override LcrsNode Step() { if (Replay != LcrsNode.MinValue) { var replayed = Replay; Replay = LcrsNode.MinValue; return(replayed); } var data = new byte[_blockSize]; var read = _stream.Read(data, 0, data.Length); if (read < _blockSize) { return(LcrsNode.MinValue); } LastRead = LcrsTrieSerializer.BytesToType <LcrsNode>(data); return(LastRead); }