public void one_and_incomplete() { string AText = "AAAAAA"; var bytes = new byte[15] { 06, 00, 00, 00, 65, 65, 65, 65, 65, 65, 06, 00, 00, 00, 66 }; var incomplete = new byte[1] { 66 }; var buf = AbstructByteBuf.Small(); buf.Write(bytes); var output = new List <object>(); decoder.Decoder(ctx, buf, output); Assert.IsTrue(output != null && output.Count == 1); Assert.IsTrue(ctx.IncompleteMessage != null); Assert.AreEqual(ctx.IncompleteHeader, 6); for (int i = 0; i < ctx.IncompleteMessage.Readables(); i++) { int readindex = ctx.IncompleteMessage.ReadIndex; Assert.AreEqual(ctx.IncompleteMessage.GetBytes()[readindex + i], incomplete[i]); } var result = output[0] as IByteBuf; var resultText = System.Text.Encoding.UTF8.GetString(result.GetBytes(), result.ReadIndex, result.Readables()); Assert.AreEqual(AText, resultText); }
public void one_and_incomplete_nolengthframe() { string AText = "AAAAAA"; var bytes = new byte[13] { 06, 00, 00, 00, 65, 65, 65, 65, 65, 65, 06, 00, 00 }; var incomplete = new byte[3] { 06, 00, 00 }; var buf = AbstructByteBuf.Small(); buf.Write(bytes); var output = new List <object>(); decoder.Decoder(ctx, buf, output); Assert.IsTrue(output != null && output.Count == 1); Assert.IsTrue(ctx.IncompleteMessage == null); Assert.IsTrue(ctx.IncompleteLength == 3); var result = output[0] as IByteBuf; var resultText = System.Text.Encoding.UTF8.GetString(result.GetBytes(), result.ReadIndex, result.Readables()); Assert.AreEqual(AText, resultText); }
public void incomplete() { string AText = "BBBBBB"; /* * * 原始数据第一个包 { 06, 00, 00, 00, 66 } * 第二个包 {66, 66, 66, 66, 66 } * 半包数据 { 66 } * 包长 6 * 包长已读:4 * */ var bytes1 = new byte[5] { 06, 00, 00, 00, 66 }; var bytes2 = new byte[5] { 66, 66, 66, 66, 66 }; var output = new List <object>(); //数据包 var buf = AbstructByteBuf.Small().Write(bytes2); //虚构一个半包 ctx.IncompleteMessage = AbstructByteBuf.Small().WriteByte(66); ctx.IncompleteHeader = 06; ctx.IncompleteLength = 4; decoder.Decoder(ctx, buf, output); Assert.AreEqual(output.Count, 1); var outbuf = (IByteBuf)output[0]; var outstring = System.Text.Encoding.UTF8.GetString(outbuf.GetBytes(), outbuf.ReadIndex, outbuf.Readables()); Assert.AreEqual(outstring, AText); }