public ComposedScalar(QName name, FASTType type, Scalar[] fields, bool optional, ComposedValueConverter valueConverter)
     : base(name, optional)
 {
     this.fields = fields;
     this.valueConverter = valueConverter;
     this.type = type;
 }
Esempio n. 2
0
 public Sequence(Sequence other)
     : base(other)
 {
     _group = (Group) other._group.Clone();
     _implicitLength = other._implicitLength;
     _length = (Scalar) other._length.Clone();
 }
        public void TestMultipleDictionaryTypes()
        {
            var bid = new Scalar("bid", FastType.Decimal, Operator.Copy, ScalarValue.Undefined, false)
                          {Dictionary = DictionaryFields.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 ComposedScalar(QName name, FastType fastType, Scalar[] fields, bool optional,
                       IComposedValueConverter valueConverter)
     : base(name, optional)
 {
     _fields = fields;
     _valueConverter = valueConverter;
     _fastType = fastType;
 }
 public void TestDecodeValueMandatory()
 {
     _field = new Scalar("", FastType.Ascii, Operator.Delta, ScalarValue.Undefined, false);
     Assert.AreEqual(new StringValue("ABCD"), Decode(Tv(0, "ABCD"), ScalarValue.Undefined));
     Assert.AreEqual(new StringValue("ABCE"), Decode(Tv(1, "E"), new StringValue("ABCD")));
     Assert.AreEqual(new StringValue("ZBCE"), Decode(Tv(-2, "Z"), new StringValue("ABCE")));
     Assert.AreEqual(new StringValue("YZBCE"), Decode(Tv(-1, "Y"), new StringValue("ZBCE")));
     Assert.AreEqual(new StringValue("YZBCEF"), Decode(Tv(0, "F"), new StringValue("YZBCE")));
 }
        public void TestNullValue()
        {
            var scalar = new Scalar("deltaString", FastType.String, Operator.Delta, ScalarValue.Undefined, true);
            var template = new MessageTemplate("template", new Field[] {scalar});
            var bvBuilder = new BitVectorBuilder(7);
            TestUtil.AssertBitVectorEquals("10000000", scalar.Encode(null, template, new Context(), bvBuilder));

            //		assertEquals(null, scalar.decode(bitStream("10000000"), ScalarValue.UNDEFINED));
        }
 public void TestDecodeValueMandatory()
 {
     _field = new Scalar("", FastType.ByteVector, Operator.Delta, ScalarValue.Undefined, false);
     Assert.AreEqual(ByteVector("aabbccdd"), Decode(Tv(0, Byte("aabbccdd")), ScalarValue.Undefined));
     Assert.AreEqual(ByteVector("aabbccee"), Decode(Tv(1, Byte("ee")), ByteVector("aabbccdd")));
     Assert.AreEqual(ByteVector("ffbbccee"), Decode(Tv(-2, Byte("ff")), ByteVector("aabbccee")));
     Assert.AreEqual(ByteVector("11ffbbccee"), Decode(Tv(-1, Byte("11")), ByteVector("ffbbccee")));
     Assert.AreEqual(ByteVector("11ffbbcceeff"), Decode(Tv(0, Byte("ff")), ByteVector("11ffbbccee")));
 }
        private static Field dict(string name, bool optional, string dictionary)
        {
            var scalar = new Scalar(qualify(name), Type.UNICODE, Operator.COPY, null, optional)
            {
                Dictionary = dictionary
            };

            return(scalar);
        }
        public void TestNullsNoInitialValue()
        {
            var field = new Scalar(new QName("mostlyNull"), FastType.I32, Operator.Default, ScalarValue.Undefined, true);
            MessageTemplate template = Template(field);
            FastEncoder encoder = Encoder(template);

            var message = (Message)template.CreateValue(null);
            TestUtil.AssertBitVectorEquals("11000000 10000001", encoder.Encode(message));
            TestUtil.AssertBitVectorEquals("10000000", encoder.Encode(message));
        }
 public void TestDecodeValueOptional()
 {
     _field = new Scalar("", FastType.ByteVector, Operator.Delta, ScalarValue.Undefined, true);
     Assert.AreEqual(ByteVector("aabbccdd"), Decode(Tv(0, Byte("aabbccdd")), ScalarValue.Undefined));
     Assert.AreEqual(ByteVector("aabbccee"), Decode(Tv(1, Byte("ee")), ByteVector("aabbccdd")));
     Assert.AreEqual(ByteVector("ffbbccee"), Decode(Tv(-2, Byte("ff")), ByteVector("aabbccee")));
     Assert.AreEqual(ByteVector("11ffbbccee"), Decode(Tv(-1, Byte("11")), ByteVector("ffbbccee")));
     Assert.AreEqual(ByteVector("11ffbbcceeff"), Decode(Tv(0, Byte("ff")), ByteVector("11ffbbccee")));
     Assert.AreEqual(null, Decode(ScalarValue.Null, String("11ffbbccee")));
 }
Esempio n. 11
0
 public Scalar(Scalar other)
     : base(other)
 {
     _defaultValue = (ScalarValue) other._defaultValue.Clone();
     _fastType = other._fastType;
     _initialValue = (ScalarValue) other._initialValue.Clone();
     _operator = other._operator;
     _operatorCodec = other._operatorCodec;
     _typeCodec = other._typeCodec;
     _dictionary = other._dictionary;
 }
        public void TestNullsWithInitialValue()
        {
            var field = new Scalar(new QName("sometimesNull"), FastType.I32, Operator.Default, new IntegerValue(10), true);
            MessageTemplate template = Template(field);
            FastEncoder encoder = Encoder(template);

            var message = (Message)template.CreateValue(null);
            TestUtil.AssertBitVectorEquals("11100000 10000001 10000000", encoder.Encode(message));
            TestUtil.AssertBitVectorEquals("10100000 10000000", encoder.Encode(message));
            message.SetInteger(1, 10);
            TestUtil.AssertBitVectorEquals("10000000", encoder.Encode(message));
        }
Esempio n. 13
0
        public Sequence(QName name, Scalar length, Field[] fields, bool optional)
            : base(name, optional)
        {
            _group = new Group(name, fields, optional);

            if (length == null)
            {
                _length = CreateLength(name, optional);
                _implicitLength = true;
            }
            else
                _length = length;
        }
 public void TestDecodeForMandatoryFieldAndDefaultValue()
 {
     var field = new Scalar("", FastType.Decimal, Operator.Delta, Decimal(12000),
             false);
     Assert.AreEqual(Decimal(12000),
         OperatorCodec.GetCodec(Operator.Delta, FastType.Decimal).DecodeEmptyValue(ScalarValue.Undefined, field));
     Assert.AreEqual(Decimal(12100),
         OperatorCodec.GetCodec(Operator.Delta, FastType.Decimal).DecodeValue(Decimal(109, -1), Decimal(12000), field));
     Assert.AreEqual(Decimal(12150),
         OperatorCodec.GetCodec(Operator.Delta, FastType.Decimal).DecodeValue(Decimal(1094, -1), Decimal(12100), field));
     Assert.AreEqual(Decimal(12200),
         OperatorCodec.GetCodec(Operator.Delta, FastType.Decimal).DecodeValue(Decimal(-1093, 1), Decimal(12150), field));
 }
 public void TestDecodeSubtractionLengthError()
 {
     _field = new Scalar("", FastType.ByteVector, Operator.Delta, ScalarValue.Undefined, false);
     try
     {
         Decode(Twin(Int(5), Byte(Byte("c0afcd"))), Byte(Byte("123456")));
         Assert.Fail();
     }
     catch (DynErrorException e)
     {
         Assert.AreEqual(DynError.SubtrctnLenLong, e.Error);
     }
 }
 public void TestEncodeDecimalValueWithEmptyPriorValue()
 {
     try
     {
         var field = new Scalar("", FastType.Decimal, Operator.Delta, ScalarValue.Undefined, false);
         field.OperatorCodec
              .GetValueToEncode(null, ScalarValue.Undefined, field);
         Assert.Fail();
     }
     catch (DynErrorException e)
     {
         Assert.AreEqual(DynError.MandatoryFieldNotPresent, e.Error);
     }
 }
        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;
        }
 public void TestDecodeSubtractionLengthError()
 {
     _field = new Scalar("", FastType.Ascii, Operator.Delta, ScalarValue.Undefined, false);
     try
     {
         Decode(Twin(Int(5), new StringValue("abc")), new StringValue("def"));
         Assert.Fail();
     }
     catch (DynErrorException e)
     {
         Assert.AreEqual(DynError.SubtrctnLenLong, e.Error);
         Assert.AreEqual(
                 "The string diff <5, abc> cannot be applied to the base value 'def' because the subtraction length is too long.",
                 e.Message);
     }
 }
Esempio n. 19
0
        public void TestDecode()
        {
            const string message = "11000000 10000010 10000010";
            Stream inp = new MemoryStream(ByteUtil.ConvertBitStringToFastByteArray(message));
            var firstname = new Scalar("firstName", FastType.U32, Operator.Copy,
                                       ScalarValue.Undefined, true);
            var lastName = new Scalar("lastName", FastType.U32, Operator.None,
                                      ScalarValue.Undefined, false);

            // MessageInputStream in = new MessageInputStream(new
            // ByteArrayInputStream(message.getBytes()));
            var group = new Group("person", new Field[] {firstname, lastName}, false);
            var groupValue = (GroupValue) group.Decode(inp, _template, _context, BitVectorReader.InfiniteTrue);
            Assert.AreEqual(1, ((IntegerValue) groupValue.GetValue(0)).Value);
            Assert.AreEqual(2, ((IntegerValue) groupValue.GetValue(1)).Value);
        }
 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 static GroupValue CreateOperator(Scalar scalar)
 {
     MessageTemplate operatorTemplate;
     if (!OperatorTemplateMap.TryGetValue(scalar.Operator, out operatorTemplate))
         return null;
     GroupValue operatorMessage = new Message(operatorTemplate);
     if (!scalar.Dictionary.Equals(DictionaryFields.Global))
         operatorMessage.SetString("Dictionary", scalar.Dictionary);
     if (!scalar.Key.Equals(scalar.QName))
     {
         Group key = operatorTemplate.GetGroup("Key");
         var keyValue = new GroupValue(key);
         keyValue.SetString("Name", scalar.Key.Name);
         keyValue.SetString("Ns", scalar.Key.Namespace);
         operatorMessage.SetFieldValue(key, keyValue);
     }
     return operatorMessage;
 }
        public void TestGetValueToEncodeForMandatory()
        {
            var field = new Scalar("", FastType.Decimal, Operator.Delta, ScalarValue.Undefined, false);
            OperatorCodec operatortemp = field.OperatorCodec;

            var value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(9427.55), ScalarValue.Undefined, field);
            Assert.AreEqual(new decimal(9427.55), value.ToBigDecimal());

            value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(9427.51), Decimal(9427.55), field);
            Assert.AreEqual(-4, value.Mantissa);
            Assert.AreEqual(0, value.Exponent);

            value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(9427.46), Decimal(9427.51), field);
            Assert.AreEqual(-5, value.Mantissa);
            Assert.AreEqual(0, value.Exponent);

            value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(30.6), Decimal(30.6), field);
            Assert.AreEqual(0, value.Exponent);
            Assert.AreEqual(0, value.Mantissa);
        }
Esempio n. 23
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);
        }
Esempio n. 24
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 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);
        }
Esempio n. 26
0
 internal bool Equals(Scalar other)
 {
     bool equals = EqualsPrivate(Name, other.Name);
     equals = equals && EqualsPrivate(_fastType, other._fastType);
     equals = equals && EqualsPrivate(_typeCodec, other._typeCodec);
     equals = equals && EqualsPrivate(_operator, other._operator);
     equals = equals && EqualsPrivate(_operatorCodec, other._operatorCodec);
     equals = equals && EqualsPrivate(_initialValue, other._initialValue);
     equals = equals && EqualsPrivate(_dictionary, other._dictionary);
     equals = equals && EqualsPrivate(Id, other.Id);
     return equals;
 }
        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 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);
        }
        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);
        }
Esempio n. 30
0
 internal bool Equals(Scalar other)
 {
     return name.Equals(other.name) && type.Equals(other.type) && typeCodec.Equals(other.typeCodec) && operator_Renamed.Equals(other.operator_Renamed) && operatorCodec.Equals(other.operatorCodec) && initialValue.Equals(other.initialValue) && dictionary.Equals(other.dictionary);
 }
        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);
        }