Пример #1
0
        public void TestDictionaryNotInherited()
        {
            const string templateDef = "<template name=\"OptDeltaDec\" id=\"58\" dictionary=\"template\">" +
                                   "    <string name=\"desc\"/>" +
                                   "    <decimal id=\"1\" presence=\"optional\" name=\"Line1\">" +
                                   "         <exponent><copy/></exponent>" +
                                   "         <mantissa><copy/></mantissa>" +
                                   "    </decimal>" +
                                   "    <decimal id=\"1\" presence=\"optional\" name=\"Line2\">" +
                                   "         <exponent><copy/></exponent>" +
                                   "         <mantissa><copy/></mantissa>" +
                                   "    </decimal>    " +
                                   "    <decimal id=\"1\" presence=\"optional\" name=\"Line3\">" +
                                   "         <exponent><copy/></exponent> " +
                                   "         <mantissa><copy/></mantissa>" +
                                   "    </decimal>" +
                                   "</template>";

            MessageTemplate template = Template(templateDef);

            var m = new Message(template);

            m.SetString("desc", "prev");
            m.SetDecimal("Line2", 9427.61 );
            m.SetDecimal("Line3", 9427.6 );

            byte[] bytes = Encoder(template).Encode(m);
            Message m2 = Decoder(template, bytes).ReadMessage();

            Assert.AreEqual(m, m2);
        }
        public void TestDecodeMessageWithAllFieldTypes()
        {
            //               --PMAP-- --TID--- ---#1--- -------#2-------- ------------#3------------ ---#4--- ------------#5------------ ---#6---
            const string msgstr = "11111111 11110001 11001000 10000001 11111111 11111101 00001001 10110001 11111111 01100001 01100010 11100011 10000010";
            Stream input = ByteUtil.CreateByteStream(msgstr);

            var template = new MessageTemplate("",
                    new Field[] {
                    new Scalar("1", FASTType.ASCII, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("2", FASTType.BYTE_VECTOR, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("3", FASTType.DECIMAL, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("4", FASTType.I32, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("5", FASTType.ASCII, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("6", FASTType.U32, Operator.COPY, ScalarValue.UNDEFINED, false),
                });
            var context = new Context();
            context.RegisterTemplate(113, template);

            GroupValue message = new Message(template);
            message.SetString(1, "H");
            message.SetByteVector(2, new[] { (byte)0xFF });
            message.SetDecimal(3, 1.201);
            message.SetInteger(4, -1);
            message.SetString(5, "abc");
            message.SetInteger(6, 2);
            Assert.AreEqual(message, new FastDecoder(context, input).ReadMessage());
        }
        public void TestEncodeMessageWithAllFieldTypes()
        {
            var template = new MessageTemplate("",
                    new Field[] {
                    new Scalar("1", FASTType.STRING, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("2", FASTType.BYTE_VECTOR, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("3", FASTType.DECIMAL, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("4", FASTType.I32, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("5", FASTType.STRING, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("6", FASTType.U32, Operator.COPY, ScalarValue.UNDEFINED, false),
                });
            var context = new Context();
            context.RegisterTemplate(113, template);

            var message = new Message(template);
            message.SetString(1, "H");
            message.SetByteVector(2, new[] { (byte)0xFF });
            message.SetDecimal(3, 1.201);
            message.SetInteger(4, -1);
            message.SetString(5, "abc");
            message.SetInteger(6, 2);

            //               --PMAP-- --TID--- ---#1--- -------#2-------- ------------#3------------ ---#4--- ------------#5------------ ---#6---
            const string msgstr = "11111111 11110001 11001000 10000001 11111111 11111101 00001001 10110001 11111111 01100001 01100010 11100011 10000010";
            AssertEquals(msgstr, new FastEncoder(context).Encode(message));
        }
        public void TestEncodeEmptyMessage()
        {
            var messageTemplate = new MessageTemplate("", new Field[] { });
            var message = new Message(messageTemplate);
            var context = new Context();
            context.RegisterTemplate(113, messageTemplate);

            byte[] encoding = new FastEncoder(context).Encode(message);
            AssertEquals("11000000 11110001", encoding);
        }
Пример #5
0
 public void SendMessage(string symbol)
 {
     var message = new Message(ses.MessageOutputStream.GetTemplateRegistry().get_Renamed("Arbitry"));
     message.SetInteger(1, rnd.Next()%1000);
     message.SetInteger(2, rnd.Next() % 1000);
     message.SetInteger(3, rnd.Next() % 1000);
     message.SetInteger(4, rnd.Next() % 1000);
     message.SetInteger(6, rnd.Next() % 1000);
     ses.MessageOutputStream.WriteMessage(message);
 }
Пример #6
0
        public void TestEncodeDecodeNestedSequence()
        {
            var nestedSequence = new Sequence("nested", new Field[] { new Scalar("string", FASTType.ASCII, Operator.COPY, ScalarValue.UNDEFINED, false) }, true);
            var group = new Group("group", new Field[] { nestedSequence }, true);
            var t = new MessageTemplate("template", new Field[] { group });
            var message = new Message(t);

            FastEncoder encoder = Encoder(t);
            AssertEquals("11000000 10000001", encoder.Encode(message));

            FastDecoder decoder = Decoder("11000000 10000001", t);
            Assert.AreEqual(message, decoder.ReadMessage());
        }
Пример #7
0
        public void TestEquals()
        {
            var template = new MessageTemplate("",
                new Field[] {
                    new Scalar("1", FASTType.U32, Operator.COPY, ScalarValue.UNDEFINED, false)
                });
            GroupValue message = new Message(template);
            message.SetInteger(1, 1);

            GroupValue other = new Message(template);
            other.SetInteger(1, 1);

            Assert.AreEqual(message, other);
        }
        public void NewSession(Session session)
        {
            //session.Listening = true;
            session.ErrorHandler = new TCPServer.FASTServer.ServerErrorHandler();
            session.MessageHandler = new FASTMessageListener();
            //register a template
            TemplateRegistry registry = new BasicTemplateRegistry();
            var template = new MessageTemplate("Arbitry",
               new Field[] {
                    new Scalar("1", FASTType.I32, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("2", FASTType.I32, Operator.DELTA, ScalarValue.UNDEFINED, false),
                    new Scalar("3", FASTType.I32, Operator.INCREMENT,
                        new IntegerValue(10), false),
                    new Scalar("4", FASTType.I32, Operator.INCREMENT,
                        ScalarValue.UNDEFINED, false),
                    new Scalar("5", FASTType.I32, Operator.CONSTANT,
                        new IntegerValue(1), false), /* NON-TRANSFERRABLE */
                new Scalar("6", FASTType.I32, Operator.DEFAULT,
                        new IntegerValue(2), false)
                });
            registry.Register(24, template);

            session.MessageInputStream.RegisterTemplate(24, template);
            //send that template
            session.SendTemplates(registry);

            while (true)
            {
                DateTime startTime = DateTime.Now;
                for (int i = 0; i < 64000; i++)
                {
                    //make a message
                    var message = new Message(template);
                    message.SetInteger(1, 109);
                    message.SetInteger(2, 29470);
                    message.SetInteger(3, 10);
                    message.SetInteger(4, 3);
                    message.SetInteger(5, 1);
                    message.SetInteger(6, 2);

                    //send it to client
                    session.MessageOutputStream.WriteMessage(message);
                }
                double seconds = (DateTime.Now - startTime).TotalSeconds;
                Console.WriteLine(seconds);
                Console.WriteLine("MSG/S:" + (64000 / seconds).ToString("0"));
            }
        }
Пример #9
0
        public void TestNotEquals()
        {
            var template = new MessageTemplate("",
                new Field[] {
                    new Scalar("1", FASTType.U32, Operator.COPY, ScalarValue.UNDEFINED, false)
                });
            var message = new Message(template);
            message.SetInteger(1, 2);

            var other = new Message(template);
            Assert.IsFalse(message.equals(other));
            Assert.IsFalse(other.equals(message));
            other.SetInteger(1, 1);

            Assert.IsFalse(message.equals(other));
            Assert.IsFalse(other.equals(message));
        }
        public void TestConstantOperatorWithMandatoryField()
        {
            var field = new Scalar("", FASTType.U32, Operator.CONSTANT, new IntegerValue(16), false);
            MessageTemplate template = registerTemplate(field);

            var msg1 = new Message(template);
            //        msg1.setInteger(1, 16);

            var msg2 = new Message(template);
            msg2.SetInteger(1, 16);

            //                 --PMAP-- --TID---
            encodeAndAssertEquals("11000000 11110001", msg1);

            //                     --PMAP--
            encodeAndAssertEquals("10000000", msg2);

            GroupValue readMessage = decoder.ReadMessage();
            Assert.AreEqual(msg1, readMessage);
            readMessage = decoder.ReadMessage();
            Assert.AreEqual(msg2, readMessage);
        }
        public void TestConversions()
        {
            MessageTemplate template = Template(
                    "<template>" +
                    "  <string name=\"string\"/>" +
                    "  <uInt32 name=\"uint\"/>" +
                    "  <int8 name=\"byte\"/>" +
                    "  <int16 name=\"short\"/>" +
                    "  <int64 name=\"long\"/>" +
                    "  <byteVector name=\"bytevector\"/>" +
                    "  <decimal name=\"decimal\"/>" +
                    "</template>");

            var message = new Message(template);
            message.SetByteVector("string", byt("7f001a"));
            message.SetDecimal("uint", 150.0);
            message.SetString("byte", "4");
            message.SetString("short", "-5");
            message.SetString("long", "1000000000000000000");
            message.SetString("bytevector", "abcd");
            message.SetString("decimal", "2.3");

            FastEncoder encoder = Encoder(template);

            byte[] encoding = encoder.Encode(message);

            FastDecoder decoder = Decoder(template, encoding);
            Message decodedMessage = decoder.ReadMessage();

            Assert.AreEqual("7f001a", decodedMessage.GetString("string"));
            Assert.AreEqual(150, decodedMessage.GetInt("uint"));
            Assert.AreEqual(150, decodedMessage.GetShort("uint"));
            Assert.AreEqual(4, decodedMessage.GetByte("byte"));
            Assert.AreEqual(-5, decodedMessage.GetShort("short"));
            Assert.AreEqual(1000000000000000000L, decodedMessage.GetLong("long"));
            Assert.AreEqual("61626364", decodedMessage.GetString("bytevector"));
        }
Пример #12
0
        public void TestMultipleDictionaryTypes()
        {
            var bid = new Scalar("bid", FASTType.DECIMAL, Operator.COPY, ScalarValue.UNDEFINED, false)
                      {Dictionary = Dictionary_Fields.TEMPLATE};

            var quote = new MessageTemplate("quote", new Field[] { bid });

            var bidR = new Scalar("bid", FASTType.DECIMAL, Operator.COPY, ScalarValue.UNDEFINED, false);
            var request = new MessageTemplate("request",
                new Field[] { bidR });

            var quote1 = new Message(quote);
            quote1.SetFieldValue(1, new DecimalValue(10.2));

            var request1 = new Message(request);
            request1.SetFieldValue(1, new DecimalValue(10.3));

            var quote2 = new Message(quote);
            quote2.SetFieldValue(1, new DecimalValue(10.2));

            var request2 = new Message(request);
            request2.SetFieldValue(1, new DecimalValue(10.2));

            session.MessageOutputStream.RegisterTemplate(1, request);
            session.MessageOutputStream.RegisterTemplate(2, quote);
            session.MessageOutputStream.WriteMessage(quote1);
            session.MessageOutputStream.WriteMessage(request1);
            session.MessageOutputStream.WriteMessage(quote2);
            session.MessageOutputStream.WriteMessage(request2);

            const string expected = "11100000 10000010 11111111 00000000 11100110 " +
                                "11100000 10000001 11111111 00000000 11100111 " +
                                "11000000 10000010 " +
                                "11100000 10000001 11111111 00000000 11100110";
            TestUtil.AssertBitVectorEquals(expected,TestUtil.ToByte( output));
        }
 public void WriteMessage(Message message)
 {
     WriteMessage(message, false);
 }
Пример #14
0
        public void testDecodeMessageWithStringFieldTypesAndAllOperators()
        {
            var template = new MessageTemplate("",
                    new Field[] {
                    new Scalar("1", FASTType.ASCII, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("2", FASTType.ASCII, Operator.DELTA, ScalarValue.UNDEFINED, false),
                    new Scalar("3", FASTType.ASCII, Operator.CONSTANT,
                        new StringValue("e"), false), /* NON-TRANSFERRABLE */
                new Scalar("4", FASTType.ASCII, Operator.DEFAULT,
                        new StringValue("long"), false)
                });

            var message = new Message(template);
            message.SetString(1, "on");
            message.SetString(2, "DCB32");
            message.SetString(3, "e");
            message.SetString(4, "long");

            //             --PMAP-- --TID--- --------#1------- ---------------------#2---------------------
            const string msg1 = "11100000 11110001 01101111 11101110 10000000 01000100 01000011 01000010 00110011 10110010";

            //             --PMAP-- ------------#2------------ ---------------------#4---------------------
            const string msg2 = "10010000 10000010 00110001 10110110 01110011 01101000 01101111 01110010 11110100";

            Stream input = ByteUtil.CreateByteStream(msg1 + ' ' + msg2);
            var context = new Context();
            context.RegisterTemplate(113, template);

            var decoder = new FastDecoder(context, input);

            Message readMessage = decoder.ReadMessage();
            Assert.AreEqual(message, readMessage);

            message.SetString(2, "DCB16");
            message.SetString(4, "short");

            readMessage = decoder.ReadMessage();
            Assert.AreEqual(message, readMessage);
        }
Пример #15
0
        public void TestMantissaIsntPresentWhenExponentIsNull()
        {
            const string templateXml = "<template name=\"SampleTemplate\">" +
                                   "  <decimal name=\"bid\" presence=\"optional\">" +
                                   "    <mantissa><copy /></mantissa>" +
                                   "    <exponent><copy value=\"-2\" /></exponent>" +
                                   "  </decimal>" +
                                   "</template>";
            MessageTemplate template = Template(templateXml);
            FastEncoder encoder = Encoder(template);

            var message = new Message(template);
            message.SetDecimal(1, 0.63);
            AssertEquals("11010000 10000001 10111111", encoder.Encode(message));

            message = new Message(template);
            AssertEquals("10100000 10000000", encoder.Encode(message));
        }
        public void TestComplexMessage()
        {
            var template = new MessageTemplate("Company",
                new Field[] {
                new Scalar("Name", FASTType.STRING, Operator.NONE, ScalarValue.UNDEFINED, false),
                new Scalar("Id", FASTType.U32, Operator.INCREMENT, ScalarValue.UNDEFINED, false),
                new Sequence("Employees",
                    new Field[] {
                        new Scalar("First Name", FASTType.STRING, Operator.COPY, ScalarValue.UNDEFINED, false),
                        new Scalar("Last Name", FASTType.STRING, Operator.COPY, ScalarValue.UNDEFINED, false),
                        new Scalar("Age", FASTType.U32, Operator.DELTA, ScalarValue.UNDEFINED, false)
                    }, false),
                new Group("Tax Information",
                    new Field[] {
                        new Scalar("EIN", FASTType.STRING, Operator.NONE, ScalarValue.UNDEFINED, false)
                    }, false)
            });
            var aaaInsurance = new Message(template);
            aaaInsurance.SetFieldValue(1, new StringValue("AAA Insurance"));
            aaaInsurance.SetFieldValue(2, new IntegerValue(5));

            var employees = new SequenceValue(template.GetSequence(
                        "Employees"));
            employees.Add(new FieldValue[] {
                new StringValue("John"), new StringValue("Doe"),
                new IntegerValue(45)
            });
            employees.Add(new FieldValue[] {
                new StringValue("Jane"), new StringValue("Doe"),
                new IntegerValue(48)
            });
            aaaInsurance.SetFieldValue(3, employees);
            aaaInsurance.SetFieldValue(4,
                new GroupValue(template.GetGroup("Tax Information"),
                    new FieldValue[] { new StringValue("99-99999999") }));

            var outStream = new MemoryStream();
            var output = new MessageOutputStream(outStream);
            output.RegisterTemplate(1, template);
            output.WriteMessage(aaaInsurance);

            var abcBuilding = new Message(template);
            abcBuilding.SetFieldValue(1, new StringValue("ABC Building"));
            abcBuilding.SetFieldValue(2, new IntegerValue(6));
            employees = new SequenceValue(template.GetSequence("Employees"));
            employees.Add(new FieldValue[] {
                new StringValue("Bob"), new StringValue("Builder"),
                new IntegerValue(3)
            });
            employees.Add(new FieldValue[] {
                new StringValue("Joe"), new StringValue("Rock"),
                new IntegerValue(59)
            });
            abcBuilding.SetFieldValue(3, employees);
            abcBuilding.SetFieldValue(4,
                new GroupValue(template.GetGroup("Tax Information"),
                    new FieldValue[] { new StringValue("99-99999999") }));
            output.WriteMessage(abcBuilding);

            var input = new MessageInputStream(new MemoryStream(
                        outStream.ToArray()));
            input.RegisterTemplate(1, template);

            GroupValue message = input.ReadMessage();
            Assert.AreEqual(aaaInsurance, message);

            message = input.ReadMessage();
            Assert.AreEqual(abcBuilding, message);
        }
Пример #17
0
        public void testDecodeSimpleMessage()
        {
            var template = new MessageTemplate("",
                    new Field[] {
                    new Scalar("1", FASTType.U32, Operator.COPY, ScalarValue.UNDEFINED, false)
                });
            Stream input = ByteUtil.CreateByteStream("11100000 11110001 10000001");
            var context = new Context();
            context.RegisterTemplate(113, template);

            var message = new Message(template);
            message.SetInteger(1, 1);

            var decoder = new FastDecoder(context, input);
            GroupValue readMessage = decoder.ReadMessage();
            Assert.AreEqual(message, readMessage);
            Assert.AreEqual(readMessage, message);
        }
        private void encodeAndAssertEquals(String encoding, Message msg1)
        {
            byte[] encodedMessage = encoder.Encode(msg1);
            TestUtil.AssertBitVectorEquals(encoding, encodedMessage);

            try
            {
                output.Write(encodedMessage);
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
        }
Пример #19
0
        public static Message Quote(double bid, double ask)
        {
            var quote = new Message(QuoteTemplate());
            quote.SetDecimal(1, bid);
            quote.SetDecimal(2, ask);

            return quote;
        }
Пример #20
0
        public void TestDecodeMessageWithSignedIntegerFieldTypesAndAllOperators()
        {
            var template = new MessageTemplate("",
                    new Field[] {
                    new Scalar("1", FASTType.I32, Operator.COPY, ScalarValue.UNDEFINED, false),
                    new Scalar("2", FASTType.I32, Operator.DELTA, ScalarValue.UNDEFINED, false),
                    new Scalar("3", FASTType.I32, Operator.INCREMENT,
                        new IntegerValue(10), false),
                    new Scalar("4", FASTType.I32, Operator.INCREMENT,
                        ScalarValue.UNDEFINED, false),
                    new Scalar("5", FASTType.I32, Operator.CONSTANT,
                        new IntegerValue(1), false), /* NON-TRANSFERRABLE */
                new Scalar("6", FASTType.I32, Operator.DEFAULT,
                        new IntegerValue(2), false)
                });

            GroupValue message = new Message(template);
            message.SetInteger(1, 109);
            message.SetInteger(2, 29470);
            message.SetInteger(3, 10);
            message.SetInteger(4, 3);
            message.SetInteger(5, 1);
            message.SetInteger(6, 2);

            //             --PMAP-- --TID--- --------#1------- ------------#2------------ ---#4---
            const string msg1 = "11101000 11110001 00000000 11101101 00000001 01100110 10011110 10000011";

            //             --PMAP-- ---#2--- ---#6---
            const string msg2 = "10000100 11111111 10000011";

            //             --PMAP-- --------#1------- --------#2------- ---#4--- ---#6---
            const string msg3 = "10101100 00000000 11100000 00001000 10000111 10000001 10000011";

            Stream input = ByteUtil.CreateByteStream(msg1 + ' ' + msg2 + ' ' +
                    msg3);
            var context = new Context();
            context.RegisterTemplate(113, template);

            var decoder = new FastDecoder(context, input);

            Message readMessage = decoder.ReadMessage();
            Assert.AreEqual(message, readMessage);

            message.SetInteger(2, 29469);
            message.SetInteger(3, 11);
            message.SetInteger(4, 4);
            message.SetInteger(6, 3);

            readMessage = decoder.ReadMessage();
            Assert.AreEqual(message, readMessage);

            message.SetInteger(1, 96);
            message.SetInteger(2, 30500);
            message.SetInteger(3, 12);
            message.SetInteger(4, 1);

            readMessage = decoder.ReadMessage();
            Assert.AreEqual(message, readMessage);
        }
 //When the server sends a message this will print that on the console.
 public void OnMessage(Session session, Message message)
 {
     //Console.WriteLine("RCV TID:" + message.Template.Name);//UNCOMMENT
 }
Пример #22
0
 public virtual bool equals(Message message)
 {
     if (FieldCount != message.FieldCount)
         return false;
     for (int i = 1; i < message.FieldCount; i++)
         if (message.GetValue(i) == null)
         {
             if (GetValue(i) == null)
             {
                 continue;
             }
             return false;
         }
         else if (!message.GetValue(i).Equals(GetValue(i)))
         {
             return false;
         }
     return true;
 }
        public void TestDeltaOperatorWithOptionalField()
        {
            var field = new Scalar("", FASTType.U32, Operator.DELTA,
                    new IntegerValue(16), true);
            MessageTemplate template = registerTemplate(field);

            var msg1 = new Message(template);
            msg1.SetInteger(1, 16);

            var msg2 = new Message(template);
            msg2.SetInteger(1, 17);

            var msg3 = new Message(template);

            var msg4 = new Message(template);
            msg4.SetInteger(1, 20);

            //                     --PMAP-- --TID--- ---#1---
            encodeAndAssertEquals("11000000 11110001 10000001", msg1);

            //                     --PMAP-- ---#1---
            encodeAndAssertEquals("10000000 10000010", msg2);

            //                     --PMAP-- ---#1---
            encodeAndAssertEquals("10000000 10000000", msg3);

            //                     --PMAP-- ---#1---
            encodeAndAssertEquals("10000000 10000100", msg4);

            readMessageAndAssertEquals(msg1);
            readMessageAndAssertEquals(msg2);
            readMessageAndAssertEquals(msg3);
            readMessageAndAssertEquals(msg4);
        }
        public void TestEmptyOperatorWithOptionalFieldOnNullValue()
        {
            var field = new Scalar("", FASTType.U32, Operator.NONE,
                    ScalarValue.UNDEFINED, true);
            MessageTemplate template = registerTemplate(field);

            var message = new Message(template);

            //                 --PMAP-- --TID--- ---#1---
            const string encoding = "11000000 11110001 10000000";

            encodeAndAssertEquals(encoding, message);

            GroupValue readMessage = decoder.ReadMessage();

            Assert.AreEqual(message, readMessage);
        }
        public void TestEmptyOperatorWithSequenceOfMessages()
        {
            var field = new Scalar("", FASTType.U32, Operator.NONE,
                    ScalarValue.UNDEFINED, true);
            MessageTemplate template = registerTemplate(field);

            var msg1 = new Message(template);

            var msg2 = new Message(template);
            msg2.SetInteger(1, 15);

            //                 --PMAP-- --TID--- ---#1---
            String encoding = "11000000 11110001 10000000";
            encodeAndAssertEquals(encoding, msg1);

            //          --PMAP-- ---#1---
            encoding = "10000000 10010000";
            byte[] encodedMessage = encoder.Encode(msg2);
            TestUtil.AssertBitVectorEquals(encoding, encodedMessage);
            output.Write(encodedMessage);

            GroupValue readMessage = decoder.ReadMessage();
            Assert.AreEqual(msg1, readMessage);
            readMessage = decoder.ReadMessage();
            Assert.AreEqual(msg2, readMessage);
        }
        public void TestIncrementOperatorWithMandatoryField()
        {
            var field = new Scalar("", FASTType.U32,
                    Operator.INCREMENT, new IntegerValue(16), false);
            MessageTemplate template = registerTemplate(field);

            var msg1 = new Message(template);
            msg1.SetInteger(1, 16);

            var msg2 = new Message(template);
            msg2.SetInteger(1, 17);

            var msg3 = new Message(template);
            msg3.SetInteger(1, 20);

            //                     --PMAP-- --TID---
            encodeAndAssertEquals("11000000 11110001", msg1);

            //                     --PMAP-- ---#1---
            encodeAndAssertEquals("10000000", msg2);

            //                     --PMAP--
            encodeAndAssertEquals("10100000 10010100", msg3);

            readMessageAndAssertEquals(msg1);
            readMessageAndAssertEquals(msg2);
            readMessageAndAssertEquals(msg3);
        }
        public void WriteMessage(Message message, bool flush)
        {
            try
            {
                if (context.TraceEnabled)
                    context.StartTrace();

                if (!(handlers.Count == 0))
                {
                    for (var i = 0; i < handlers.Count; i++)
                    {
                        handlers[i].HandleMessage(message, context, encoder);
                    }
                }
                if (templateHandlers.ContainsKey(message.Template))
                {
                    templateHandlers[message.Template].HandleMessage(message, context, encoder);
                }

                var data = encoder.Encode(message);

                if ((data == null) || (data.Length == 0))
                {
                    return ;
                }

                var temp_byteArray = data;
                out_Renamed.Write(temp_byteArray, 0, temp_byteArray.Length);
                if (flush)
                    out_Renamed.Flush();
            }
            catch (System.IO.IOException e)
            {
                Global.HandleError(Error.FastConstants.IO_ERROR, "An IO error occurred while writing message " + message, e);
            }
        }
Пример #28
0
        public static Message NewAllocInstrctn(String id, int side,
            double quantity, double averagePrice, GroupValue instrument,
            SequenceValue allocations)
        {
            var allocInstrctn = new Message(AllocationInstruction());
            allocInstrctn.SetFieldValue(1, allocations);
            allocInstrctn.SetFieldValue(2, instrument);
            allocInstrctn.SetFieldValue(3, new StringValue(id));
            allocInstrctn.SetFieldValue(4, new IntegerValue(side));
            allocInstrctn.SetFieldValue(5, new DecimalValue(quantity));
            allocInstrctn.SetFieldValue(6, new DecimalValue(averagePrice));

            return allocInstrctn;
        }
        public void TestConstantOperatorWithOptionalField()
        {
            var field = new Scalar("", FASTType.U32, Operator.CONSTANT, new IntegerValue(16), true);
            MessageTemplate template = registerTemplate(field);

            var msg1 = new Message(template);

            var msg2 = new Message(template);
            msg2.SetInteger(1, 16);

            //                     --PMAP-- --TID---
            encodeAndAssertEquals("11000000 11110001", msg1);

            //                     --PMAP--
            encodeAndAssertEquals("10100000", msg2);

            readMessageAndAssertEquals(msg1);
            readMessageAndAssertEquals(msg2);
        }
        public void TestTailOperatorWithOptionalField()
        {
            var field = new Scalar("", FASTType.STRING, Operator.TAIL,
                    new StringValue("abc"), true);
            MessageTemplate template = registerTemplate(field);

            var msg1 = new Message(template);
            msg1.SetString(1, "abc");

            var msg2 = new Message(template);
            msg2.SetString(1, "abd");

            var msg3 = new Message(template);

            var msg4 = new Message(template);
            msg4.SetString(1, "dbef");

            //                     --PMAP-- --TID---
            encodeAndAssertEquals("11000000 11110001", msg1);

            //                     --PMAP-- ---#1---
            encodeAndAssertEquals("10100000 11100100", msg2);

            //                     --PMAP-- ---#1---
            encodeAndAssertEquals("10100000 10000000", msg3);

            //                     --PMAP-- -----------------#1----------------
            encodeAndAssertEquals("10100000 01100100 01100010 01100101 11100110",
                msg4);

            readMessageAndAssertEquals(msg1);
            readMessageAndAssertEquals(msg2);
            readMessageAndAssertEquals(msg3);
            readMessageAndAssertEquals(msg4);
        }