public void CheckActualBytes()
        {
            var t = new FudgeTime(1, 2, 3, 123456789, 60, FudgeDateTimePrecision.Microsecond);
            var stream = new MemoryStream();
            var writer = new FudgeBinaryWriter(stream);
            TimeFieldType.Instance.WriteValue(writer, t);

            Assert.Equal("04-90-0e-8b-07-5b-cd-15", stream.ToArray().ToNiceString());   // 04 = timezone, 9 = accuracy, 00e8b = seconds, 075bcd15 = nanos
        }
        public void CheckActualBytes()
        {
            Func<FudgeDate, string> toByteString = d =>
            {
                var stream = new MemoryStream();
                var writer = new FudgeBinaryWriter(stream);
                DateFieldType.Instance.WriteValue(writer, d);
                return stream.ToArray().ToNiceString();
            };

            // Using examples from Confluence at http://www.fudgemsg.org/display/FDG/DateTime+encoding
            Assert.Equal("00-0f-b4-3f", toByteString(new FudgeDate(20100131)));
            Assert.Equal("00-0f-a1-00", toByteString(new FudgeDate(20000800)));
            Assert.Equal("a4-72-80-00", toByteString(new FudgeDate(-3000000, 0, 0)));
        }
        private static int FudgeCycle(bool useNames, bool useOrdinals)
        {
            MemoryStream outputStream = new MemoryStream();
            var bw = new FudgeBinaryWriter(outputStream);
            SmallFinancialTick tick = new SmallFinancialTick();
            FudgeMsg msg = new FudgeMsg(fudgeContext);
            if (useNames && useOrdinals)
            {
                msg.Add("ask", (short)1, tick.Ask);
                msg.Add("askVolume", (short)2, tick.AskVolume);
                msg.Add("bid", (short)3, tick.Bid);
                msg.Add("bidVolume", (short)4, tick.BidVolume);
                msg.Add("ts", (short)5, tick.Timestamp);
            }
            else if (useNames)
            {
                msg.Add("ask", tick.Ask);
                msg.Add("askVolume", tick.AskVolume);
                msg.Add("bid", tick.Bid);
                msg.Add("bidVolume", tick.BidVolume);
                msg.Add("ts", tick.Timestamp);
            }
            else if (useOrdinals)
            {
                msg.Add(1, tick.Ask);
                msg.Add(2, tick.AskVolume);
                msg.Add(3, tick.Bid);
                msg.Add(4, tick.BidVolume);
                msg.Add(5, tick.Timestamp);
            }
            fudgeContext.Serialize(msg, bw);

            byte[] data = outputStream.ToArray();

            MemoryStream inputstream = new MemoryStream(data);
            var br = new FudgeBinaryReader(inputstream);
            msg = fudgeContext.Deserialize(inputstream).Message;

            tick = new SmallFinancialTick();
            if (useOrdinals)
            {
                tick.Ask = msg.GetDouble(1).Value;
                tick.AskVolume = msg.GetDouble(2).Value;
                tick.Bid = msg.GetDouble(3).Value;
                tick.BidVolume = msg.GetDouble(4).Value;
                tick.Timestamp = msg.GetLong(5).Value;
            }
            else if (useNames)
            {
                tick.Ask = msg.GetDouble("ask").Value;
                tick.AskVolume = msg.GetDouble("askVolume").Value;
                tick.Bid = msg.GetDouble("bid").Value;
                tick.BidVolume = msg.GetDouble("bidVolume").Value;
                tick.Timestamp = msg.GetLong("ts").Value;
            }
            else
            {
                throw new InvalidOperationException("Names or ordinals, pick at least one.");
            }
            return data.Length;
        }
        /// <inheritdoc/>
        public void StartMessage()
        {
            if (stack.Count > 0)
                throw new InvalidOperationException("Attempting to start message when already started.");

            memStream = new MemoryStream();
            memWriter = new FudgeBinaryWriter(memStream);
            taxonomy = null;
            if (TaxonomyId.HasValue && context.TaxonomyResolver != null)
            {
                taxonomy = context.TaxonomyResolver.ResolveTaxonomy(TaxonomyId.Value);
            }
            stack.Push(new State(0, 0, false, false, 0));
        }
        /// <inheritdoc/>
        public void EndMessage()
        {
            if (stack.Count != 1)
            {
                throw new InvalidOperationException("Ending message before all sub-messages ended");
            }
            var state = stack.Pop();
            int totalMessageSize = state.FinalMessageContentsSize;
            WriteMsgEnvelopeHeader(outputWriter, TaxonomyId ?? 0, totalMessageSize, EnvelopeVersion);
            memStream.Position = 0;

            WriteMemStreamToOutput();

            // Tidy up
            sizePositions.Clear();
            memStream = null;
            memWriter = null;
        }