Beispiel #1
0
        private static SequenceValue BasicAllocations()
        {
            var value = new SequenceValue(AllocationInstruction.GetSequence("Allocations"));

            value.Add(NewAllocation("general", 101.0, 15.0));
            value.Add(NewAllocation("specific", 103.0, 10.0));
            return(value);
        }
Beispiel #2
0
        public void TestMultipleMessages()
        {
            var outStream = new MemoryStream();
            var output    = new MessageOutputStream(outStream);

            output.RegisterTemplate(ObjectMother.AllocInstrctnTemplateId,
                                    ObjectMother.AllocationInstruction);

            var allocations = new SequenceValue(ObjectMother.AllocationInstruction
                                                .GetSequence("Allocations"));

            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai1 = ObjectMother.NewAllocInstrctn(
                "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            allocations = new SequenceValue(
                ObjectMother.AllocationInstruction.GetSequence("Allocations"));

            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai2 = ObjectMother.NewAllocInstrctn(
                "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            allocations = new SequenceValue(
                ObjectMother.AllocationInstruction.GetSequence("Allocations"));
            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai3 = ObjectMother.NewAllocInstrctn(
                "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            output.WriteMessage(ai1);
            output.WriteMessage(ai2);
            output.WriteMessage(ai3);

            byte[] bytes = outStream.ToArray();
            var    input = new MessageInputStream(new MemoryStream(bytes));

            input.RegisterTemplate(ObjectMother.AllocInstrctnTemplateId,
                                   ObjectMother.AllocationInstruction);

            Message message = input.ReadMessage();

            Assert.AreEqual(ai1, message);
            message = input.ReadMessage();
            Assert.AreEqual(ai2, message);
            Assert.AreEqual(ai3, input.ReadMessage());
        }
        public void TestDecode()
        {
            const string actual = "10000010 11100000 10000001 10000010 11100000 10000011 10000100";
            Stream stream = ByteUtil.CreateByteStream(actual);

            var firstNumber = new Scalar("First Number", FastType.I32, Operator.Copy, ScalarValue.Undefined, false);
            var lastNumber = new Scalar("Second Number", FastType.I32, Operator.Copy, ScalarValue.Undefined, false);
            var sequence1 = new Sequence("Contants", new Field[] {firstNumber, lastNumber}, false);

            var sequenceValue = new SequenceValue(sequence1);
            sequenceValue.Add(new IFieldValue[]
                                  {
                                      new IntegerValue(1), new IntegerValue(2)
                                  });
            sequenceValue.Add(new IFieldValue[]
                                  {
                                      new IntegerValue(3), new IntegerValue(4)
                                  });

            IFieldValue result = sequence1.Decode(stream, _template, _context, BitVectorReader.InfiniteTrue);
            Assert.AreEqual(sequenceValue, result);
        }
Beispiel #4
0
        public void TestEncode()
        {
            var firstName = new Scalar("First Name", FastType.I32, Operator.Copy, ScalarValue.Undefined, false);
            var lastName  = new Scalar("Last Name", FastType.I32, Operator.Copy, ScalarValue.Undefined, false);
            var sequence1 = new Sequence("Contacts", new Field[] { firstName, lastName }, false);

            var sequenceValue = new SequenceValue(sequence1);

            sequenceValue.Add(new IFieldValue[]
            {
                new IntegerValue(1), new IntegerValue(2)
            });
            sequenceValue.Add(new IFieldValue[]
            {
                new IntegerValue(3), new IntegerValue(4)
            });

            byte[] actual = sequence1.Encode(sequenceValue, _template, _context, new BitVectorBuilder(1));

            const string expected = "10000010 11100000 10000001 10000010 11100000 10000011 10000100";

            TestUtil.AssertBitVectorEquals(expected, actual);
        }
Beispiel #5
0
        public void TestDecode()
        {
            const string actual = "10000010 11100000 10000001 10000010 11100000 10000011 10000100";
            Stream       stream = ByteUtil.CreateByteStream(actual);

            var firstNumber = new Scalar("First Number", FastType.I32, Operator.Copy, ScalarValue.Undefined, false);
            var lastNumber  = new Scalar("Second Number", FastType.I32, Operator.Copy, ScalarValue.Undefined, false);
            var sequence1   = new Sequence("Contants", new Field[] { firstNumber, lastNumber }, false);

            var sequenceValue = new SequenceValue(sequence1);

            sequenceValue.Add(new IFieldValue[]
            {
                new IntegerValue(1), new IntegerValue(2)
            });
            sequenceValue.Add(new IFieldValue[]
            {
                new IntegerValue(3), new IntegerValue(4)
            });

            IFieldValue result = sequence1.Decode(stream, _template, _context, BitVectorReader.InfiniteTrue);

            Assert.AreEqual(sequenceValue, result);
        }
        public static Message Convert(Group group, Message groupMsg, ConversionContext context)
        {
            SetNameAndId(group, groupMsg);
            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)SessionControlProtocol11
                        .TypeRef
                        .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            var instructions = new SequenceValue(
                SessionControlProtocol11.TemplateDefinition.GetSequence("Instructions"));

            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)
                        SessionControlProtocol11
                        .TypeRef
                        .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            Field[] fields = group.FieldDefinitions;
            for (int i = group is MessageTemplate ? 1 : 0; i < fields.Length; i++)
            {
                Field field = fields[i];

                IFieldInstructionConverter converter = context.GetConverter(field);
                if (converter == null)
                {
                    throw new InvalidOperationException("No converter found for type " + field.GetType());
                }

                IFieldValue v = converter.Convert(field, context);
                instructions.Add(new[] { v });
            }
            groupMsg.SetFieldValue("Instructions", instructions);
            return(groupMsg);
        }
 public static Message Convert(Group group, Message groupMsg, ConversionContext context)
 {
     SetNameAndId(group, groupMsg);
     var instructions = new SequenceValue(SessionControlProtocol_1_1.TEMPLATE_DEFINITION.GetSequence("Instructions"));
     int i = group is MessageTemplate?1:0;
     Field[] fields = group.FieldDefinitions;
     for (; i < fields.Length; i++)
     {
         Field field = fields[i];
         FieldInstructionConverter converter = context.GetConverter(field);
         if (converter == null)
             throw new System.SystemException("No converter found for type " + field.GetType());
         FieldValue value_Renamed = converter.Convert(field, context);
         instructions.Add(new[]{value_Renamed});
     }
     groupMsg.SetFieldValue("Instructions", instructions);
     return groupMsg;
 }
Beispiel #8
0
        public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader pmapReader)
        {
            var        sequenceValue = new SequenceValue(this);
            FieldValue lengthValue   = length.Decode(in_Renamed, decodeTemplate, context, pmapReader);

            if ((lengthValue == ScalarValue.NULL) || (lengthValue == null))
            {
                return(null);
            }

            int len = ((IntegerValue)lengthValue).value_Renamed;

            for (var i = 0; i < len; i++)
            {
                sequenceValue.Add((GroupValue)group.Decode(in_Renamed, decodeTemplate, context, BitVectorReader.INFINITE_TRUE));
            }

            return(sequenceValue);
        }
Beispiel #9
0
        public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context,
                                           BitVectorReader pmapReader)
        {
            var         sequenceValue = new SequenceValue(this);
            IFieldValue lengthValue   = _length.Decode(inStream, decodeTemplate, context, pmapReader);

            if ((lengthValue == ScalarValue.Null) || (lengthValue == null))
            {
                return(null);
            }

            int len = ((IntegerValue)lengthValue).Value;

            for (int i = 0; i < len; i++)
            {
                sequenceValue.Add(
                    (GroupValue)_group.Decode(inStream, decodeTemplate, context, BitVectorReader.InfiniteTrue));
            }

            return(sequenceValue);
        }
Beispiel #10
0
        public static Message Convert(Group group, Message groupMsg, ConversionContext context)
        {
            SetNameAndId(group, groupMsg);
            var instructions = new SequenceValue(SessionControlProtocol_1_1.TEMPLATE_DEFINITION.GetSequence("Instructions"));
            int i            = group is MessageTemplate?1:0;

            Field[] fields = group.FieldDefinitions;
            for (; i < fields.Length; i++)
            {
                Field field = fields[i];
                FieldInstructionConverter converter = context.GetConverter(field);
                if (converter == null)
                {
                    throw new System.SystemException("No converter found for type " + field.GetType());
                }
                FieldValue value_Renamed = converter.Convert(field, context);
                instructions.Add(new[] { value_Renamed });
            }
            groupMsg.SetFieldValue("Instructions", instructions);
            return(groupMsg);
        }
        public void TestEncode()
        {
            var firstName = new Scalar("First Name", FastType.I32, Operator.Copy, ScalarValue.Undefined, false);
            var lastName = new Scalar("Last Name", FastType.I32, Operator.Copy, ScalarValue.Undefined, false);
            var sequence1 = new Sequence("Contacts", new Field[] {firstName, lastName}, false);

            var sequenceValue = new SequenceValue(sequence1);
            sequenceValue.Add(new IFieldValue[]
                                  {
                                      new IntegerValue(1), new IntegerValue(2)
                                  });
            sequenceValue.Add(new IFieldValue[]
                                  {
                                      new IntegerValue(3), new IntegerValue(4)
                                  });

            byte[] actual = sequence1.Encode(sequenceValue, _template, _context, new BitVectorBuilder(1));

            const string expected = "10000010 11100000 10000001 10000010 11100000 10000011 10000100";
            TestUtil.AssertBitVectorEquals(expected, actual);
        }
Beispiel #12
0
        public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader pmapReader)
        {
            var sequenceValue = new SequenceValue(this);
            FieldValue lengthValue = length.Decode(in_Renamed, decodeTemplate, context, pmapReader);

            if ((lengthValue == ScalarValue.NULL) || (lengthValue == null))
            {
                return null;
            }

            int len = ((IntegerValue) lengthValue).value_Renamed;

            for (var i = 0; i < len; i++)
                sequenceValue.Add((GroupValue) group.Decode(in_Renamed, decodeTemplate, context, BitVectorReader.INFINITE_TRUE));

            return sequenceValue;
        }
Beispiel #13
0
        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 IFieldValue[]
            {
                new StringValue("John"), new StringValue("Doe"),
                new IntegerValue(45)
            });
            employees.Add(new IFieldValue[]
            {
                new StringValue("Jane"), new StringValue("Doe"),
                new IntegerValue(48)
            });
            aaaInsurance.SetFieldValue(3, employees);
            aaaInsurance.SetFieldValue(4,
                                       new GroupValue(template.GetGroup("Tax Information"),
                                                      new IFieldValue[] { new StringValue("99-99999999") }));

            var outStream = new MemoryStream();
            var output    = new MessageOutputStream(outStream);

            output.RegisterTemplate(2, 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 IFieldValue[]
            {
                new StringValue("Bob"), new StringValue("Builder"),
                new IntegerValue(3)
            });
            employees.Add(new IFieldValue[]
            {
                new StringValue("Joe"), new StringValue("Rock"),
                new IntegerValue(59)
            });
            abcBuilding.SetFieldValue(3, employees);
            abcBuilding.SetFieldValue(4,
                                      new GroupValue(template.GetGroup("Tax Information"),
                                                     new IFieldValue[] { new StringValue("99-99999999") }));
            output.WriteMessage(abcBuilding);

            var input = new MessageInputStream(new MemoryStream(outStream.ToArray()));

            input.RegisterTemplate(2, template);

            GroupValue message = input.ReadMessage();

            Assert.AreEqual(aaaInsurance, message);

            message = input.ReadMessage();
            Assert.AreEqual(abcBuilding, message);
        }
Beispiel #14
0
        public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context,
                                           BitVectorReader pmapReader)
        {
            var sequenceValue = new SequenceValue(this);
            IFieldValue lengthValue = _length.Decode(inStream, decodeTemplate, context, pmapReader);

            if ((lengthValue == ScalarValue.Null) || (lengthValue == null))
            {
                return null;
            }

            int len = ((IntegerValue) lengthValue).Value;

            for (int i = 0; i < len; i++)
                sequenceValue.Add(
                    (GroupValue) _group.Decode(inStream, decodeTemplate, context, BitVectorReader.InfiniteTrue));

            return sequenceValue;
        }
        public void TestMultipleMessages()
        {
            var outStream = new MemoryStream();
            var output = new MessageOutputStream(outStream);
            output.RegisterTemplate(ObjectMother.AllocInstrctnTemplateId,
                                    ObjectMother.AllocationInstruction);

            var allocations = new SequenceValue(ObjectMother.AllocationInstruction
                                                    .GetSequence("Allocations"));
            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai1 = ObjectMother.NewAllocInstrctn(
                "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            allocations = new SequenceValue(
                ObjectMother.AllocationInstruction.GetSequence("Allocations"));

            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai2 = ObjectMother.NewAllocInstrctn(
                "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            allocations = new SequenceValue(
                ObjectMother.AllocationInstruction.GetSequence("Allocations"));
            allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0));
            allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0));

            Message ai3 = ObjectMother.NewAllocInstrctn(
                "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations);

            output.WriteMessage(ai1);
            output.WriteMessage(ai2);
            output.WriteMessage(ai3);

            byte[] bytes = outStream.ToArray();
            var input = new MessageInputStream(new MemoryStream(bytes));
            input.RegisterTemplate(ObjectMother.AllocInstrctnTemplateId,
                                   ObjectMother.AllocationInstruction);

            Message message = input.ReadMessage();
            Assert.AreEqual(ai1, message);
            message = input.ReadMessage();
            Assert.AreEqual(ai2, message);
            Assert.AreEqual(ai3, input.ReadMessage());
        }
        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 IFieldValue[]
                              {
                                  new StringValue("John"), new StringValue("Doe"),
                                  new IntegerValue(45)
                              });
            employees.Add(new IFieldValue[]
                              {
                                  new StringValue("Jane"), new StringValue("Doe"),
                                  new IntegerValue(48)
                              });
            aaaInsurance.SetFieldValue(3, employees);
            aaaInsurance.SetFieldValue(4,
                                       new GroupValue(template.GetGroup("Tax Information"),
                                                      new IFieldValue[] {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 IFieldValue[]
                              {
                                  new StringValue("Bob"), new StringValue("Builder"),
                                  new IntegerValue(3)
                              });
            employees.Add(new IFieldValue[]
                              {
                                  new StringValue("Joe"), new StringValue("Rock"),
                                  new IntegerValue(59)
                              });
            abcBuilding.SetFieldValue(3, employees);
            abcBuilding.SetFieldValue(4,
                                      new GroupValue(template.GetGroup("Tax Information"),
                                                     new IFieldValue[] {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);
        }
 private static SequenceValue BasicAllocations()
 {
     var value = new SequenceValue(AllocationInstruction.GetSequence("Allocations"));
     value.Add(NewAllocation("general", 101.0, 15.0));
     value.Add(NewAllocation("specific", 103.0, 10.0));
     return value;
 }
        public static Message Convert(Group group, Message groupMsg, ConversionContext context)
        {
            SetNameAndId(group, groupMsg);
            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group) SessionControlProtocol11
                                    .TypeRef
                                    .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            var instructions = new SequenceValue(
                SessionControlProtocol11.TemplateDefinition.GetSequence("Instructions"));

            if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference))
            {
                var typeRef =
                    new GroupValue(
                        (Group)
                        SessionControlProtocol11
                            .TypeRef
                            .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace)));

                SetName(typeRef, group.TypeReference);
                groupMsg.SetFieldValue("TypeRef", typeRef);
            }

            Field[] fields = group.FieldDefinitions;
            for (int i = group is MessageTemplate ? 1 : 0; i < fields.Length; i++)
            {
                Field field = fields[i];

                IFieldInstructionConverter converter = context.GetConverter(field);
                if (converter == null)
                    throw new InvalidOperationException("No converter found for type " + field.GetType());

                IFieldValue v = converter.Convert(field, context);
                instructions.Add(new[] {v});
            }
            groupMsg.SetFieldValue("Instructions", instructions);
            return groupMsg;
        }