public void MultipleMessages()
        {
            // Same as CheckElementsCorrectForSimpleMessage but without using HasNext
            var context = new FudgeContext();
            var msg1    = context.NewMessage();

            msg1.Add("Test", "Bob");
            var msg2 = context.NewMessage();

            msg2.Add("Test2", "Shirley");
            var msgs   = new FudgeMsg[] { msg1, msg2 };
            var stream = new MemoryStream();
            var writer = new FudgeEncodedStreamWriter(context, stream);

            new FudgeStreamPipe(new FudgeMsgStreamReader(context, msgs), writer).Process();

            stream.Position = 0;
            var reader = new FudgeEncodedStreamReader(context, stream);

            Assert.Equal(FudgeStreamElement.MessageStart, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.SimpleField, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.MessageEnd, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.MessageStart, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.SimpleField, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.MessageEnd, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.NoElement, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.NoElement, reader.MoveNext());
        }
        public void CheckElementsCorrectForSubMessage()
        {
            var context = new FudgeContext();
            var msg     = context.NewMessage();
            var subMsg  = context.NewMessage();

            msg.Add("sub", subMsg);
            subMsg.Add("Test", "Bob");
            var bytes = context.ToByteArray(msg);

            var stream = new MemoryStream(bytes);
            var reader = new FudgeEncodedStreamReader(context, stream);

            Assert.True(reader.HasNext);
            Assert.Equal(FudgeStreamElement.MessageStart, reader.MoveNext());
            Assert.True(reader.HasNext);
            Assert.Equal(FudgeStreamElement.SubmessageFieldStart, reader.MoveNext());
            Assert.True(reader.HasNext);
            Assert.Equal(FudgeStreamElement.SimpleField, reader.MoveNext());
            Assert.True(reader.HasNext);
            Assert.Equal(FudgeStreamElement.SubmessageFieldEnd, reader.MoveNext());
            Assert.True(reader.HasNext);
            Assert.Equal(FudgeStreamElement.MessageEnd, reader.MoveNext());
            Assert.False(reader.HasNext);
        }
Exemplo n.º 3
0
        public void GuidsAsSecondaryTypes()
        {
            Guid guid = Guid.NewGuid();
            var  msg  = fudgeContext.NewMessage();;

            msg.Add("guid", guid);

            Assert.Same(ByteArrayFieldType.Length16Instance, msg.GetByName("guid").Type);

            Guid guid2 = msg.GetValue <Guid>("guid");

            Assert.Equal(guid, guid2);
        }
        internal static FudgeMsg CreateMessageAllOrdinals(FudgeContext context)
        {
            FudgeMsg msg = context.NewMessage();

            msg.Add(1, true);
            msg.Add(2, (object)(false));
            msg.Add(3, (sbyte)5);
            msg.Add(4, (object)((sbyte)5));
            short shortValue = ((short)sbyte.MaxValue) + 5;

            msg.Add(5, shortValue);
            msg.Add(6, (object)(shortValue));
            int intValue = ((int)short.MaxValue) + 5;

            msg.Add(7, intValue);
            msg.Add(8, (object)(intValue));
            long longValue = ((long)int.MaxValue) + 5;

            msg.Add(9, longValue);
            msg.Add(10, (object)(longValue));

            msg.Add(11, 0.5f);
            msg.Add(12, (object)(0.5f));
            msg.Add(13, 0.27362);
            msg.Add(14, (object)(0.27362));

            msg.Add(15, "Kirk Wylie");

            msg.Add(16, new float[24]);
            msg.Add(17, new double[273]);

            return(msg);
        }
        internal static FudgeMsg CreateMessageAllNames(FudgeContext context)
        {
            FudgeMsg msg = context.NewMessage();

            msg.Add("boolean", true);
            msg.Add("Boolean", (object)false);
            msg.Add("byte", (sbyte)5);
            msg.Add("Byte", (object)((sbyte)5));
            short shortValue = ((short)sbyte.MaxValue) + 5;
            msg.Add("short", shortValue);
            msg.Add("Short", (object)(shortValue));
            int intValue = ((int)short.MaxValue) + 5;
            msg.Add("int", intValue);
            msg.Add("Integer", (object)(intValue));
            long longValue = ((long)int.MaxValue) + 5;
            msg.Add("long", longValue);
            msg.Add("Long", (object)(longValue));

            msg.Add("float", 0.5f);
            msg.Add("Float", (object)(0.5f));
            msg.Add("double", 0.27362);
            msg.Add("Double", (object)(0.27362));

            msg.Add("String", "Kirk Wylie");

            msg.Add("float array", new float[24]);
            msg.Add("double array", new double[273]);
            msg.Add("short array", new short[32]);
            msg.Add("int array", new int[83]);
            msg.Add("long array", new long[837]);

            msg.Add("indicator", IndicatorType.Instance);

            return msg;
        }
Exemplo n.º 6
0
        public void AllOrdinalsCodecWithTaxonomy()
        {
            FudgeContext context  = new FudgeContext();
            FudgeMsg     inputMsg = context.NewMessage();

            inputMsg.Add(ORDINALS[0], "value1");
            inputMsg.Add(ORDINALS[1], "value2");
            inputMsg.Add(ORDINALS[2], "value3");
            inputMsg.Add(ORDINALS[3], "value4");

            var resolverMap = new Dictionary <int, IFudgeTaxonomy>();

            resolverMap.Add(45, new MapFudgeTaxonomy(ORDINALS, NAMES));
            context.TaxonomyResolver = new ImmutableMapTaxonomyResolver(resolverMap);

            FudgeMsg outputMsg = CycleMessage(inputMsg, context, (short)45);

            Assert.Equal("value1", outputMsg.GetString(NAMES[0]));
            Assert.Equal("value1", outputMsg.GetString(ORDINALS[0]));
            Assert.Equal("value2", outputMsg.GetString(NAMES[1]));
            Assert.Equal("value2", outputMsg.GetString(ORDINALS[1]));
            Assert.Equal("value3", outputMsg.GetString(NAMES[2]));
            Assert.Equal("value3", outputMsg.GetString(ORDINALS[2]));
            Assert.Equal("value4", outputMsg.GetString(NAMES[3]));
            Assert.Equal("value4", outputMsg.GetString(ORDINALS[3]));
        }
Exemplo n.º 7
0
        public void SetViewCycleAccessSupported(bool isViewCycleAccessSupported)
        {
            var msg = FudgeContext.NewMessage(
                new Field("isViewCycleAccessSupported", isViewCycleAccessSupported)
                );

            REST.Resolve("viewCycleAccessSupported").PostFudge(msg);
        }
 internal static FudgeMsg CreateLargeMessage(FudgeContext context)
 {
     FudgeMsg msg = context.NewMessage();
     for (int i = short.MinValue - 1; i <= short.MaxValue + 1; i++)
     {
         msg.Add(string.Format("field{0}", i), "FRN-91");
     }
     return msg;
 }
        internal static FudgeMsg CreateLargeMessage(FudgeContext context)
        {
            FudgeMsg msg = context.NewMessage();

            for (int i = short.MinValue - 1; i <= short.MaxValue + 1; i++)
            {
                msg.Add(string.Format("field{0}", i), "FRN-91");
            }
            return(msg);
        }
Exemplo n.º 10
0
        public void SimpleExample()
        {
            var msg = context.NewMessage(new Field("outer",
                                                   new Field("a", 7),
                                                   new Field("b", "fred")));
            var stringWriter = new StringWriter();
            var writer       = new FudgeJSONStreamWriter(context, stringWriter);

            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            AssertEqualsNoWhiteSpace("{\"outer\" : {\"a\" : 7, \"b\" : \"fred\"} }", s);
        }
Exemplo n.º 11
0
 public static FudgeMsg CreateMessageWithSubMsgs(FudgeContext context)
 {
     FudgeMsg inputMsg = context.NewMessage(
                             new Field("sub1",
                                 new Field("bibble", "fibble"),
                                 new Field(827, "Blibble")),
                             new Field("sub2",
                                 new Field("bibble9", 9837438),
                                 new Field(828, 82.77f)));
     return inputMsg;
 }
Exemplo n.º 12
0
        public static FudgeMsg CreateMessageWithSubMsgs(FudgeContext context)
        {
            FudgeMsg inputMsg = context.NewMessage(
                new Field("sub1",
                          new Field("bibble", "fibble"),
                          new Field(827, "Blibble")),
                new Field("sub2",
                          new Field("bibble9", 9837438),
                          new Field(828, 82.77f)));

            return(inputMsg);
        }
Exemplo n.º 13
0
        internal static FudgeMsg CreateMessageAllByteArrayLengths(FudgeContext context)
        {
            FudgeMsg msg = context.NewMessage();
            msg.Add("byte[4]", new byte[4]);
            msg.Add("byte[8]", new byte[8]);
            msg.Add("byte[16]", new byte[16]);
            msg.Add("byte[20]", new byte[20]);
            msg.Add("byte[32]", new byte[32]);
            msg.Add("byte[64]", new byte[64]);
            msg.Add("byte[128]", new byte[128]);
            msg.Add("byte[256]", new byte[256]);
            msg.Add("byte[512]", new byte[512]);

            msg.Add("byte[28]", new byte[28]);
            return msg;
        }
Exemplo n.º 14
0
        internal static FudgeMsg CreateMessageAllByteArrayLengths(FudgeContext context)
        {
            FudgeMsg msg = context.NewMessage();

            msg.Add("byte[4]", new byte[4]);
            msg.Add("byte[8]", new byte[8]);
            msg.Add("byte[16]", new byte[16]);
            msg.Add("byte[20]", new byte[20]);
            msg.Add("byte[32]", new byte[32]);
            msg.Add("byte[64]", new byte[64]);
            msg.Add("byte[128]", new byte[128]);
            msg.Add("byte[256]", new byte[256]);
            msg.Add("byte[512]", new byte[512]);

            msg.Add("byte[28]", new byte[28]);
            return(msg);
        }
        public void CheckEndOfStreamWithoutHasNext()
        {
            // Same as CheckElementsCorrectForSimpleMessage but without using HasNext
            var context = new FudgeContext();
            var msg     = context.NewMessage();

            msg.Add("Test", "Bob");
            var bytes = context.ToByteArray(msg);

            var stream = new MemoryStream(bytes);
            var reader = new FudgeEncodedStreamReader(context, stream);

            Assert.Equal(FudgeStreamElement.MessageStart, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.SimpleField, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.MessageEnd, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.NoElement, reader.MoveNext());
            Assert.Equal(FudgeStreamElement.NoElement, reader.MoveNext());
        }
Exemplo n.º 16
0
        internal static FudgeMsg CreateMessageAllNames(FudgeContext context)
        {
            FudgeMsg msg = context.NewMessage();

            msg.Add("boolean", true);
            msg.Add("Boolean", (object)false);
            msg.Add("byte", (sbyte)5);
            msg.Add("Byte", (object)((sbyte)5));
            short shortValue = ((short)sbyte.MaxValue) + 5;

            msg.Add("short", shortValue);
            msg.Add("Short", (object)(shortValue));
            int intValue = ((int)short.MaxValue) + 5;

            msg.Add("int", intValue);
            msg.Add("Integer", (object)(intValue));
            long longValue = ((long)int.MaxValue) + 5;

            msg.Add("long", longValue);
            msg.Add("Long", (object)(longValue));

            msg.Add("float", 0.5f);
            msg.Add("Float", (object)(0.5f));
            msg.Add("double", 0.27362);
            msg.Add("Double", (object)(0.27362));

            msg.Add("String", "Kirk Wylie");

            msg.Add("float array", new float[24]);
            msg.Add("double array", new double[273]);
            msg.Add("short array", new short[32]);
            msg.Add("int array", new int[83]);
            msg.Add("long array", new long[837]);

            msg.Add("indicator", IndicatorType.Instance);

            return(msg);
        }
Exemplo n.º 17
0
        public void AllNamesCodecWithTaxonomy()
        {
            FudgeContext context = new FudgeContext();
            FudgeMsg inputMsg = context.NewMessage();
            inputMsg.Add(NAMES[0], "value1");
            inputMsg.Add(NAMES[1], "value2");
            inputMsg.Add(NAMES[2], "value3");
            inputMsg.Add(NAMES[3], "value4");

            var resolverMap = new Dictionary<int, IFudgeTaxonomy>();
            resolverMap.Add(45, new MapFudgeTaxonomy(ORDINALS, NAMES));
            context.TaxonomyResolver = new ImmutableMapTaxonomyResolver(resolverMap);

            FudgeMsg outputMsg = CycleMessage(inputMsg, context, 45);
            Assert.Equal("value1", outputMsg.GetString(NAMES[0]));
            Assert.Equal("value1", outputMsg.GetString(ORDINALS[0]));
            Assert.Equal("value2", outputMsg.GetString(NAMES[1]));
            Assert.Equal("value2", outputMsg.GetString(ORDINALS[1]));
            Assert.Equal("value3", outputMsg.GetString(NAMES[2]));
            Assert.Equal("value3", outputMsg.GetString(ORDINALS[2]));
            Assert.Equal("value4", outputMsg.GetString(NAMES[3]));
            Assert.Equal("value4", outputMsg.GetString(ORDINALS[3]));
        }
Exemplo n.º 18
0
 /// <inheritdoc/>
 public void StartMessage()
 {
     top = context.NewMessage();
     current = top;
 }
Exemplo n.º 19
0
        internal static FudgeMsg CreateMessageAllOrdinals(FudgeContext context)
        {
            FudgeMsg msg = context.NewMessage();

            msg.Add(1, true);
            msg.Add(2, (object)(false));
            msg.Add(3, (sbyte)5);
            msg.Add(4, (object)((sbyte)5));
            short shortValue = ((short)sbyte.MaxValue) + 5;
            msg.Add(5, shortValue);
            msg.Add(6, (object)(shortValue));
            int intValue = ((int)short.MaxValue) + 5;
            msg.Add(7, intValue);
            msg.Add(8, (object)(intValue));
            long longValue = ((long)int.MaxValue) + 5;
            msg.Add(9, longValue);
            msg.Add(10, (object)(longValue));

            msg.Add(11, 0.5f);
            msg.Add(12, (object)(0.5f));
            msg.Add(13, 0.27362);
            msg.Add(14, (object)(0.27362));

            msg.Add(15, "Kirk Wylie");

            msg.Add(16, new float[24]);
            msg.Add(17, new double[273]);

            return msg;
        }