public void PassSlidingStreamReadAndWrite() { var ss = new Nets.SlidingStream(); { var bytes = Encoding.Default.GetBytes("packet info"); var lenBytes = BitConverter.GetBytes(bytes.Length); ss.Write(lenBytes, 0, lenBytes.Length); ss.Write(bytes, 0, bytes.Length); } Assert.AreEqual<long>(15, ss.Length); ss.PushPosition(); { var br = new BinaryReader(ss); var length = br.ReadInt32(); Assert.AreEqual<int>(11, length); var bytes = br.ReadBytes(length); Assert.AreEqual<string>("packet info", Encoding.Default.GetString(bytes)); ss.PopPosition(); } ss.RestorePosition(); Assert.AreEqual<long>(0, ss.Length); { var bytes = Encoding.Default.GetBytes("packet info222"); var lenBytes = BitConverter.GetBytes(bytes.Length); ss.Write(lenBytes, 0, lenBytes.Length); ss.Write(bytes, 0, bytes.Length); } Assert.AreEqual<long>(18, ss.Length); ss.PushPosition(); { var br = new BinaryReader(ss); var length = br.ReadInt32(); Assert.AreEqual<int>(14, length); var bytes = br.ReadBytes(length); Assert.AreEqual<string>("packet info222", Encoding.Default.GetString(bytes)); ss.PopPosition(); } ss.RestorePosition(); Assert.AreEqual<long>(0, ss.Length); }
public void PassSlidingStreamRead() { var ss = new Nets.SlidingStream(); var bytes = Encoding.Default.GetBytes("ABCDEF1234567890"); ss.Write(bytes, 0, bytes.Length); ss.PushPosition(); { var br = new BinaryReader(ss); // 6개를 리턴한 다음 읽은 적 없는 척 한다. Assert.AreEqual<int>(6, br.ReadBytes(6).Length); ss.RestorePosition(); ss.PushPosition(); Assert.AreEqual<int>(6, br.ReadBytes(6).Length); Assert.AreEqual<int>(6, br.ReadBytes(6).Length); // 데이터 길이가 짧아서 4개만 리턴된다. Assert.AreEqual<int>(4, br.ReadBytes(6).Length); } ss.RestorePosition(); }
public void PassSlidingStreamWrite() { var ss = new Nets.SlidingStream(); var totalLength = 0; foreach (var line in PassDataSet.GetNormalStrings()) { var bytes = Encoding.Default.GetBytes(line); ss.Write(bytes, 0, bytes.Length); totalLength += bytes.Length; Assert.AreEqual<long>(totalLength, ss.Length, line); } }