public override byte[] EncodeList(IList l)
        {
            if (_elementType.IsDynamic())
            {
                var elems = new byte[l.Count + 1 + l.Count][];
                elems[0] = _intTypeEncoder.EncodeInt(l.Count);

                var currentSize = 0;
                for (var i = 0; i < l.Count; i++)
                {
                    elems[i + 1]           = _intTypeEncoder.EncodeInt((l.Count * 32) + currentSize); //location element
                    elems[i + 1 + l.Count] = _elementType.Encode(l[i]);
                    currentSize            = currentSize + elems[i + 1 + l.Count].Length;
                }
                return(ByteUtil.Merge(elems));
            }
            else
            {
                var elems = new byte[l.Count + 1][];
                elems[0] = _intTypeEncoder.EncodeInt(l.Count);
                for (var i = 0; i < l.Count; i++)
                {
                    elems[i + 1] = _elementType.Encode(l[i]);
                }
                return(ByteUtil.Merge(elems));
            }
        }
Ejemplo n.º 2
0
        public override byte[] EncodeList(IList l)
        {
            if (l.Count != arraySize)
            {
                throw new Exception("List size (" + l.Count + ") != " + arraySize);
            }

            if (elementType.IsDynamic())
            {
                var elems       = new byte[arraySize + arraySize][];
                var currentSize = 0;
                for (var i = 0; i < l.Count; i++)
                {
                    elems[i]           = intTypeEncoder.EncodeInt((l.Count * 32) + currentSize);
                    elems[i + l.Count] = elementType.Encode(l[i]);
                    currentSize        = currentSize + elems[i + l.Count].Length;
                }
                return(ByteUtil.Merge(elems));
            }
            else
            {
                var elems = new byte[arraySize][];
                for (var i = 0; i < l.Count; i++)
                {
                    elems[i] = elementType.Encode(l[i]);
                }
                return(ByteUtil.Merge(elems));
            }
        }