public void RaisesEventAfterEachMessage()
        {
            var context = new FudgeContext();
            var messages = new FudgeMsg[]
            {
                new FudgeMsg(context, new Field("test", "data")),
                new FudgeMsg(context, new Field("life", 42))
            };
            var reader = new FudgeMsgStreamReader(context, messages);
            var writer = new FudgeMsgStreamWriter(context);

            var pipe = new FudgeStreamPipe(reader, writer);

            int count = 0;
            pipe.MessageProcessed += () =>
            {
                var message = writer.DequeueMessage();
                FudgeUtils.AssertAllFieldsMatch(messages[count], message);
                count++;
            };

            pipe.Process();

            Assert.Equal(2, count);
        }
        /// <summary>
        /// Convenience method for reading a <see cref="FudgeMsg"/> from a <see cref="IFudgeStreamReader"/>.
        /// </summary>
        /// <param name="reader">Reader providing the data for the message.</param>
        /// <returns>New message containing data from the reader.</returns>
        public static FudgeMsg ReadMsg(this IFudgeStreamReader reader)
        {
            var writer = new FudgeMsgStreamWriter();
            var pipe = new FudgeStreamPipe(reader, writer);
            pipe.ProcessOne();

            return writer.DequeueMessage();
        }
        public void GeneralTest()
        {
            var context = new FudgeContext();

            var msg = StandardFudgeMessages.CreateMessageWithSubMsgs(context);
            var reader = new FudgeMsgStreamReader(context, msg);
            var writer = new FudgeMsgStreamWriter();

            var pipe = new FudgeStreamPipe(reader, writer);
            pipe.Process();

            var newMsg = writer.DequeueMessage();

            FudgeUtils.AssertAllFieldsMatch(msg, newMsg);
        }
        public void MultipleMessages()
        {
            var context = new FudgeContext();

            var msg1 = StandardFudgeMessages.CreateMessageWithSubMsgs(context);
            var msg2 = StandardFudgeMessages.CreateMessageAllNames(context);
            var reader = new FudgeMsgStreamReader(context, new FudgeMsg[] {msg1, msg2});
            var writer = new FudgeMsgStreamWriter();

            var pipe = new FudgeStreamPipe(reader, writer);
            pipe.Process();

            Assert.Equal(2, writer.PeekAllMessages().Count);
            FudgeUtils.AssertAllFieldsMatch(msg1, writer.DequeueMessage());
            FudgeUtils.AssertAllFieldsMatch(msg2, writer.DequeueMessage());
        }
 public ReaderFudgeDeserializationContext(FudgeContext context, SerializationTypeMap typeMap, IFudgeStreamReader reader, IFudgeTypeMappingStrategy typeMappingStrategy)
     : base(context, typeMap, typeMappingStrategy)
 {
     this.msgWriter = new FudgeMsgStreamWriter(context);
     this.pipe = new FudgeStreamPipe(reader, msgWriter);
 }
 /// <summary>
 /// Convenience method for writing a <see cref="FudgeMsg"/> to a <see cref="IFudgeStreamWriter"/>.
 /// </summary>
 /// <param name="writer">Writer to write the data.</param>
 /// <param name="msg">Message to write.</param>
 public static void WriteMsg(this IFudgeStreamWriter writer, FudgeMsg msg)
 {
     var reader = new FudgeMsgStreamReader(msg.Context, msg);
     var pipe = new FudgeStreamPipe(reader, writer);
     pipe.ProcessOne();
 }