Ejemplo n.º 1
0
        public override byte[] Encode(FieldValue value_Renamed, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder)
        {
            if (HasTypeReference())
            {
                context.CurrentApplicationType = TypeReference;
            }
            if (value_Renamed == null)
            {
                return(length.Encode(null, encodeTemplate, context, presenceMapBuilder));
            }

            var buffer = new System.IO.MemoryStream();
            var val    = (SequenceValue)value_Renamed;
            int len    = val.Length;

            try
            {
                var temp_byteArray = length.Encode(new IntegerValue(len), encodeTemplate, context, presenceMapBuilder);
                buffer.Write(temp_byteArray, 0, temp_byteArray.Length);

                System.Collections.IEnumerator iter = val.Iterator();

                while (iter.MoveNext())
                {
                    var temp_byteArray2 = group.Encode((FieldValue)iter.Current, encodeTemplate, context);
                    buffer.Write(temp_byteArray2, 0, temp_byteArray2.Length);
                }
            }
            catch (System.IO.IOException e)
            {
                Global.HandleError(Error.FastConstants.IO_ERROR, "An IO error occurred while encoding " + this, e);
            }

            return(buffer.ToArray());
        }
Ejemplo n.º 2
0
        public override byte[] Encode(IFieldValue value, Group encodeTemplate, Context context,
                                      BitVectorBuilder presenceMapBuilder)
        {
            if (HasTypeReference)
            {
                context.CurrentApplicationType = TypeReference;
            }
            if (value == null)
            {
                return(_length.Encode(null, encodeTemplate, context, presenceMapBuilder));
            }

            var buffer = new MemoryStream();
            var val    = (SequenceValue)value;
            int len    = val.Length;

            try
            {
                byte[] tmp = _length.Encode(new IntegerValue(len), encodeTemplate, context, presenceMapBuilder);
                buffer.Write(tmp, 0, tmp.Length);

                foreach (GroupValue v in val.Elements)
                {
                    tmp = _group.Encode(v, encodeTemplate, context);
                    buffer.Write(tmp, 0, tmp.Length);
                }
            }
            catch (IOException e)
            {
                Global.ErrorHandler.OnError(e, DynError.IoError, "An IO error occurred while encoding {0}", this);
            }

            return(buffer.ToArray());
        }
Ejemplo n.º 3
0
        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));
        }