public void TestPacketConsumption() { // This just tests the packet reader's ability to // munch through all the packets in the stream, and // gracefully reach the end without exception. // Therefore it will return true, and we will keep // calling into it, until it returns false. At // which point it's assumed we've reached the end // of the stream. If not something went wrong. PacketReader r = new PacketReader(Input, Input); while(Input.Position < (Input.Length - 1)) { if (!r.ReadNext()) { // Have we reached the end, if not // this is an error. Assert.IsTrue(Input.Position == (Input.Length - 1)); } } }
public void TestMessageConsumption() { PacketReader r = new PacketReader(Input, Input); while(true) { if (!r.ReadNext()) { break; } } Type[] expectedMessages = new[] { typeof(EventId), typeof(Copyright), typeof(Notice), typeof(RefreshRate), typeof(Unknown1), typeof(Unknown1), typeof(KeyFrame) }; IMessage[] extractedMessages = r.MessageQueue.ToArray(); for (int i = 0; i < expectedMessages.Length; ++i) { Assert.AreEqual(expectedMessages[i], extractedMessages[i].GetType()); } }
/// <summary> /// Call this from your IDriver if you have an entire frames worth of data to process. This useful only /// when processing keyframe data as it disregards any stateful information associated with the live stream. /// </summary> /// <param name="keyFrameData">The stream must contain complete data for a keyframe.</param> public void HandleReadAdHoc(Stream keyFrameData) { PacketReader keyFrameReader = new PacketReader(keyFrameData, new DecryptStreamDecorator(keyFrameData, _decryptor)); _decryptor.Reset(); bool keepReading; do { keepReading = keyFrameReader.ReadNext(); while (keyFrameReader.MessageQueue.Count > 0) { DispatchMessage(keyFrameReader.MessageQueue.Dequeue(), false); } } while (keepReading); // The live stream may not yet know its own event type because it probably // hasn't received the EventId message. So we copy the value across from the // keyframe. This is necessary to know how to deserialise car packets. UpdateEventType(keyFrameReader.CurrentEventType); }
public void TestMessageConsumption() { PacketReader r = new PacketReader(Input, DecryptedInput); while (true) { if (!r.ReadNext()) { break; } } // This means we have sucesfully navigated our way to the end and understood // all the packets along the way ... yipee! Assert.AreEqual( Input.Length, Input.Position ); }