예제 #1
0
        public void Example()
        {
            var context = new FudgeContext();

            // Create a message
            var msg = new FudgeMsg(new Field("name", "Eric"),
                                   new Field("age", 14),
                                   new Field("address",
                                             new Field("line1", "29 Acacia Road"),
                                             new Field("city", "London")));

            // Serialise it
            var stream = new MemoryStream();

            context.Serialize(msg, stream);

            // Get the raw bytes
            var bytes = stream.ToArray();

            // Deserialise it
            var msg2 = context.Deserialize(bytes).Message;

            // Get some data
            int age = msg2.GetInt("age") ?? 0;
        }
예제 #2
0
        private void Cycle(FudgeTime t)
        {
            var msg1  = new FudgeMsg(context, new Field("t", t));
            var bytes = msg1.ToByteArray();
            var msg2  = context.Deserialize(bytes).Message;

            Assert.Equal(t, msg2.GetValue <FudgeTime>("t"));
        }
예제 #3
0
        public void RoundTrip()
        {
            var d = new FudgeDate(1999, 12, 10);

            var msg1  = new FudgeMsg(context, new Field("d", d));
            var bytes = msg1.ToByteArray();
            var msg2  = context.Deserialize(bytes).Message;

            Assert.Equal("1999-12-10", msg2.GetValue <FudgeDate>("d").ToString());
        }
        public void RoundTrip()
        {
            var dt = new FudgeDateTime(1999, 12, 10, 3, 4, 5, 987654321, -75, FudgeDateTimePrecision.Nanosecond);

            var msg1  = new FudgeMsg(context, new Field("dt", dt));
            var bytes = msg1.ToByteArray();
            var msg2  = context.Deserialize(bytes).Message;

            Assert.Equal("1999-12-10T03:04:05.987654321-01:15", msg2.GetValue <FudgeDateTime>("dt").ToString());
        }
예제 #5
0
        protected static FudgeMsg CycleMessage(FudgeMsg msg) //throws IOException
        {
            byte[] content = fudgeContext.ToByteArray(msg);
            // Double-check the size calc was right
            Assert.Equal(content.Length, new FudgeMsgEnvelope(msg).ComputeSize(null));

            MemoryStream     stream2           = new MemoryStream(content);
            FudgeMsgEnvelope outputMsgEnvelope = fudgeContext.Deserialize(stream2);

            Assert.NotNull(outputMsgEnvelope);
            Assert.NotNull(outputMsgEnvelope.Message);
            return(outputMsgEnvelope.Message);
        }
예제 #6
0
        private FudgeMsg CycleMessage(FudgeMsg msg, FudgeContext context, short?taxonomy)
        {
            MemoryStream outputStream = new MemoryStream();

            context.Serialize(msg, taxonomy, outputStream);

            byte[] content = outputStream.ToArray();

            MemoryStream     inputStream       = new MemoryStream(content);
            FudgeMsgEnvelope outputMsgEnvelope = context.Deserialize(inputStream);

            Assert.NotNull(outputMsgEnvelope);
            Assert.NotNull(outputMsgEnvelope.Message);
            return(outputMsgEnvelope.Message);
        }
예제 #7
0
        protected static FudgeMsg CycleMessage(FudgeMsg msg, string filename) //throws IOException
        {
            Assembly     assembly        = Assembly.GetExecutingAssembly();
            Stream       stream          = assembly.GetManifestResourceStream("Fudge.Tests.Resources." + filename);
            BinaryReader referenceReader = new FudgeBinaryReader(stream);
            Stream       memoryStream    = new MemoryStream();
            // set the last parameter of the following line to true to see the full diff report between streams and not fail at the first difference.
            BinaryWriter bw = new StreamComparingBinaryNBOWriter(referenceReader, memoryStream, false);

            fudgeContext.Serialize(msg, bw);
            bw.Close();

            // Reload as closed above
            stream = assembly.GetManifestResourceStream("Fudge.Tests.Resources." + filename);
            FudgeMsg outputMsg = fudgeContext.Deserialize(stream).Message;      // Load the message from the resource rather than our output

            return(outputMsg);
        }
예제 #8
0
        private FudgeMsg CycleMessage(FudgeMsg msg, FudgeContext context, short? taxonomy)
        {
            MemoryStream outputStream = new MemoryStream();
            context.Serialize(msg, taxonomy, outputStream);

            byte[] content = outputStream.ToArray();

            MemoryStream inputStream = new MemoryStream(content);
            FudgeMsgEnvelope outputMsgEnvelope = context.Deserialize(inputStream);
            Assert.NotNull(outputMsgEnvelope);
            Assert.NotNull(outputMsgEnvelope.Message);
            return outputMsgEnvelope.Message;
        }
예제 #9
0
        public void Example()
        {
            var context = new FudgeContext();

            // Create a message
            var msg = new FudgeMsg(new Field("name", "Eric"),
                                   new Field("age", 14),
                                   new Field("address",
                                       new Field("line1", "29 Acacia Road"),
                                       new Field("city", "London")));

            // Serialise it
            var stream = new MemoryStream();
            context.Serialize(msg, stream);

            // Get the raw bytes
            var bytes = stream.ToArray();

            // Deserialise it
            var msg2 = context.Deserialize(bytes).Message;

            // Get some data
            int age = msg2.GetInt("age") ?? 0;
        }
예제 #10
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);
        }