public void SetUp()
 {
     _output = new PipedStream();
     _input = new PipedStream(_output);
     _encodingContext = new Context();
     _decodingContext = new Context();
     _encoder = new FastEncoder(_encodingContext);
     _decoder = new FastDecoder(_decodingContext, _input);
 }
        public void TestEncode()
        {
            var encoder = new FastEncoder(_context);

            //   --PMAP-- --TID--- ---#1--- --PMAP-- --TID--- ------------#1------------ ------------#3------------
            TestUtil.AssertBitVectorEquals(
                "11000000 10000001 10001111 11000000 10000010 01001001 01000010 11001101 10000000 00000000 11100110",
                encoder.Encode(_message));
        }
 public void SetUp()
 {
     output = new PipedStream();
     input = new PipedStream(output);
     encodingContext = new Context();
     decodingContext = new Context();
     encoder = new FastEncoder(encodingContext);
     decoder = new FastDecoder(decodingContext, input);
 }
        public void TestEncodeEmptyMessage()
        {
            var messageTemplate = new MessageTemplate("", new Field[0]);
            var message = new Message(messageTemplate);
            var context = new Context();
            context.RegisterTemplate(113, messageTemplate);

            byte[] encoding = new FastEncoder(context).Encode(message);
            AssertEquals("11000000 11110001", encoding);
        }
 public void TestNullValueDoesntAlterDictionary()
 {
     var copyField = new Scalar(new QName("value"), FastType.I32, Operator.Copy, new IntegerValue(10), true);
     var field = new Scalar(new QName("value"), FastType.I32, Operator.Default, new IntegerValue(10), true);
     MessageTemplate copyTemplate = Template(copyField);
     MessageTemplate template = Template(field);
     var context = new Context();
     var encoder = new FastEncoder(context);
     encoder.RegisterTemplate(1, template);
     encoder.RegisterTemplate(2, copyTemplate);
     var message = (Message)copyTemplate.CreateValue(null);
     message.SetInteger(1, 11);
     encoder.Encode(message);
     Assert.AreEqual(11, context.Lookup("global", copyTemplate, new QName("value")).ToInt());
     message = (Message)template.CreateValue(null);
     encoder.Encode(message);
     Assert.AreEqual(11, context.Lookup("global", copyTemplate, new QName("value")).ToInt());
 }
        public void TestEncodeSimpleMessage()
        {
            var template = new MessageTemplate(
                "",
                new Field[]
                    {
                        new Scalar("1", FastType.U32, Operator.Copy, ScalarValue.Undefined, false)
                    });

            var context = new Context();
            context.RegisterTemplate(113, template);

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

            var encoder = new FastEncoder(context);
            AssertEquals("11100000 11110001 10000001", encoder.Encode(message));
        }
        public void TestEncodeSequentialEmptyMessages()
        {
            var messageTemplate = new MessageTemplate("", new Field[0]);
            var message = new Message(messageTemplate);
            var nextMsg = new Message(messageTemplate);
            var context = new Context();
            context.RegisterTemplate(113, messageTemplate);

            var encoder = new FastEncoder(context);

            // Presence map should show that the only field present is the template id.
            AssertEquals("11000000 11110001",
                         encoder.Encode(message));
            // Presence map should be empty (except for leading stop bit)
            AssertEquals("10000000", encoder.Encode(nextMsg));
        }
        public void TestEncodeMessageWithUnsignedIntegerFieldTypesAndAllOperators()
        {
            var template = new MessageTemplate(
                "",
                new Field[]
                    {
                        new Scalar("1", FastType.U32, Operator.Copy, ScalarValue.Undefined, false),
                        new Scalar("2", FastType.U32, 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)
                    });

            var context = new Context();
            context.RegisterTemplate(113, template);

            var encoder = new FastEncoder(context);

            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);

            //                   --PMAP-- --TID--- ---#1--- ------------#2------------ ---#4---
            const string msg1 = "11101000 11110001 11101101 00000001 01100110 10011110 10000011";
            AssertEquals(msg1, encoder.Encode(message));

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

            //                   --PMAP-- ---#2--- ---#6---
            const string msg2 = "10000100 10000001 10000011";
            AssertEquals(msg2, encoder.Encode(message));

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

            //                   --PMAP-- ---#1--- --------#2------- ---#4--- ---#6---
            const string msg3 = "10101100 11100000 00001000 10000101 10000001 10000011";
            AssertEquals(msg3, encoder.Encode(message));
        }
        public void TestEncodeMessageWithStringFieldTypesAndAllOperators()
        {
            var template = new MessageTemplate(
                "",
                new Field[]
                    {
                        new Scalar("1", FastType.String, Operator.Copy, ScalarValue.Undefined, false),
                        new Scalar("2", FastType.String, Operator.Delta, ScalarValue.Undefined, false),
                        new Scalar("3", FastType.String, Operator.Constant, new StringValue("e"), false),
                        /* NON-TRANSFERRABLE */
                        new Scalar("4", FastType.String, Operator.Default, new StringValue("long"), false)
                    });

            var context = new Context();
            context.RegisterTemplate(113, template);

            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";

            var encoder = new FastEncoder(context);

            AssertEquals(msg1, encoder.Encode(message));

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

            AssertEquals(msg2, encoder.Encode(message));
        }
        public void TestEncodeMessageWithSignedIntegerFieldTypesAndAllOperators()
        {
            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)
                });
            var context = new Context();
            context.RegisterTemplate(113, template);

            var encoder = new FastEncoder(context);

            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);

            //             --PMAP-- --TID--- --------#1------- ------------#2------------ ---#4---
            const string msg1 = "11101000 11110001 00000000 11101101 00000001 01100110 10011110 10000011";
            TestUtil.AssertBitVectorEquals(msg1, encoder.Encode(message));

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

            //             --PMAP-- ---#2--- ---#6---
            const string msg2 = "10000100 11111111 10000011";
            TestUtil.AssertBitVectorEquals(msg2, encoder.Encode(message));

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

            //             --PMAP-- --------#1------- --------#2------- ---#4--- ---#6---
            const string msg3 = "10101100 00000000 11100000 00001000 10000111 10000001 10000011";
            AssertEquals(msg3, encoder.Encode(message));
        }
 public MessageOutputStream(Stream outputStream, Context context)
 {
     _outStream = outputStream;
     _encoder = new FastEncoder(context);
     _context = context;
 }