Exemplo n.º 1
0
 public Sequence(Sequence other)
     : base(other)
 {
     _group = (Group) other._group.Clone();
     _implicitLength = other._implicitLength;
     _length = (Scalar) other._length.Clone();
 }
Exemplo n.º 2
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());
        }
        public override Field Convert(GroupValue fieldDef, ITemplateRegistry templateRegistry, ConversionContext context)
        {
            string name = fieldDef.GetString("Name");
            string ns = fieldDef.GetString("Ns");
            var qname = new QName(name, ns);
            Field[] fields = GroupConverter.ParseFieldInstructions(fieldDef, templateRegistry, context);
            bool optional = fieldDef.GetBool("Optional");
            Scalar length = null;
            IFieldValue retLength;
            if (fieldDef.TryGetValue("Length", out retLength) && retLength!=null)
            {
                GroupValue lengthDef = (GroupValue)retLength;
                QName lengthName;
                string id = null;
                IFieldValue retName;
                if (lengthDef.TryGetValue("Name", out retName) && retName != null)
                {
                    GroupValue nameDef = (GroupValue)retName;
                    lengthName = new QName(nameDef.GetString("Name"), nameDef.GetString("Ns"));
                    IFieldValue retAuxId;
                    if (nameDef.TryGetValue("AuxId", out retAuxId) && retAuxId != null)
                        id = retAuxId.ToString();
                }
                else
                    lengthName = Global.CreateImplicitName(qname);
                Operator op = Operator.None;
                IFieldValue retOperator;
                if (lengthDef.TryGetValue("Operator", out retOperator) && retOperator != null)
                    op = GetOperator(((GroupValue)retOperator).GetGroup(0).Group);
                ScalarValue initialValue = ScalarValue.Undefined;
                IFieldValue retInitialValue;
                if (lengthDef.TryGetValue("InitialValue", out retInitialValue) && retInitialValue != null)
                    initialValue = (ScalarValue) retInitialValue;
                length = new Scalar(lengthName, FastType.U32, op, initialValue, optional) {Id = id};
            }

            var sequence = new Sequence(qname, length, fields, optional);
            IFieldValue retTypeRef;
            if (fieldDef.TryGetValue("TypeRef", out retTypeRef) && retTypeRef != null)
            {
                GroupValue typeRef = (GroupValue)retTypeRef;
                string typeRefName = typeRef.GetString("Name");
                string typeRefNs = ""; // context.getNamespace();
                IFieldValue rettypeRefNs;
                if (typeRef.TryGetValue("Ns", out rettypeRefNs) && rettypeRefNs!=null)
                    typeRefNs = rettypeRefNs.ToString();
                sequence.TypeReference = new QName(typeRefName, typeRefNs);
            }
            return sequence;
        }
Exemplo n.º 4
0
        public static Sequence Allocations()
        {
            if (_allocations == null)
            {
                _allocations = new Sequence("Allocations",
                    new Field[] {
                    new Scalar("Account",       FASTType.ASCII,   Operator.COPY,  ScalarValue.UNDEFINED, false),
                    new Scalar("Price",         FASTType.DECIMAL, Operator.DELTA, ScalarValue.UNDEFINED, false),
                    new Scalar("Quantity",      FASTType.DECIMAL, Operator.DELTA, ScalarValue.UNDEFINED, false),
                    new Scalar("Average Price", FASTType.DECIMAL, Operator.DELTA, ScalarValue.UNDEFINED, false)
                }, false);
            }

            return _allocations;
        }
        public void TestLookup()
        {
            var allocationInstruction =
                new MessageTemplate(ObjectMother.AllocationInstruction)
                    {
                        TypeReference = new QName("AllocationInstruction")
                    };

            var allocations = new Sequence(ObjectMother.Allocations) {TypeReference = new QName("Allocation")};

            var context = new Context();

            context.Store(DictionaryFields.Type, allocationInstruction, new QName("ID"), String("1234"));

            Assert.AreEqual(String("1234"),
                            context.Lookup(DictionaryFields.Type, allocationInstruction, new QName("ID")));
            Assert.AreEqual(ScalarValue.Undefined,
                            context.Lookup(DictionaryFields.Type, allocations.Group, new QName("ID")));
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
 protected static void AssertSequenceLengthField(Sequence sequence, String name, FastType type, Operator op)
 {
     Assert.AreEqual(type, sequence.Length.FastType);
     Assert.AreEqual(name, sequence.Length.Name);
     Assert.AreEqual(op, sequence.Length.Operator);
 }