Example #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());
        }
Example #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());
        }
Example #3
0
        public void TestEncode()
        {
            var firstName = new Scalar("First Name", FastType.U32, Operator.Copy,
                                       ScalarValue.Undefined, true);
            var lastName = new Scalar("Last Name", FastType.U32, Operator.None,
                                      ScalarValue.Undefined, false);
            var theGroup = new Group("guy", new Field[] {firstName, lastName}, false);

            byte[] actual = theGroup.Encode(
                new GroupValue(
                    new Group("", new Field[0], false),
                    new IFieldValue[] {new IntegerValue(1), new IntegerValue(2)}),
                _template, _context);

            const string expected = "11000000 10000010 10000010";

            TestUtil.AssertBitVectorEquals(expected, actual);
        }