public void TestGetValueToEncodeForOptional()
        {
            var           field        = new Scalar("", FastType.Decimal, Operator.Delta, ScalarValue.Undefined, true);
            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, (int)value.Mantissa);
            Assert.AreEqual(0, (int)value.Exponent);

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

            value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(30.6), Decimal(30.6), field);
            Assert.AreEqual(0, (int)value.Exponent);
            Assert.AreEqual(0, (int)value.Mantissa);

            Assert.AreEqual(ScalarValue.Null,
                            operatortemp.GetValueToEncode(null, Decimal(30.6), field));
        }
Exemple #2
0
        public void TestCopyOperator()
        {
            var           field = new Scalar("", FastType.U32, Operator.Copy, ScalarValue.Undefined, true);
            OperatorCodec copy  = Operator.Copy.GetCodec(FastType.U32);

            Assert.AreEqual(new IntegerValue(1), copy.GetValueToEncode(new IntegerValue(1), null, field));
            Assert.AreEqual(new IntegerValue(2), copy.GetValueToEncode(new IntegerValue(2), new IntegerValue(1), field));
            //newly added implementation
            Assert.AreEqual(null, copy.GetValueToEncode(ScalarValue.Null, ScalarValue.Null, field));
        }
Exemple #3
0
        public override byte[] Encode(IFieldValue fieldValue, Group encodeTemplate, Context context,
                                      BitVectorBuilder presenceMapBuilder)
        {
            IDictionary dict = context.GetDictionary(Dictionary);

            ScalarValue priorValue = context.Lookup(dict, encodeTemplate, Key);
            var         value      = (ScalarValue)fieldValue;

            if (!_operatorCodec.CanEncode(value, this))
            {
                Global.ErrorHandler.OnError(null, DynError.CantEncodeValue,
                                            "The scalar {0} cannot encode the value {1}", this, value);
            }
            ScalarValue valueToEncode = _operatorCodec.GetValueToEncode(value, priorValue, this,
                                                                        presenceMapBuilder);

            if (_operator.ShouldStoreValue(value))
            {
                context.Store(dict, encodeTemplate, Key, value);
            }
            if (valueToEncode == null)
            {
                return(ByteUtil.EmptyByteArray);
            }
            byte[] encoding = _typeCodec.Encode(valueToEncode);
            if (context.TraceEnabled && encoding.Length > 0)
            {
                context.EncodeTrace.Field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.Index);
            }
            return(encoding);
        }
Exemple #4
0
        public void TestDeltaOperatorForOptionalUnsignedInteger()
        {
            var           field = new Scalar("", FastType.U32, Operator.Delta, ScalarValue.Undefined, true);
            OperatorCodec delta = field.OperatorCodec;

            Assert.AreEqual(ScalarValue.Null, delta.GetValueToEncode(null, ScalarValue.Undefined, field));
        }