예제 #1
0
        public override (object, int) Decode(byte[] data, int position, bool packed)
        {
            (BigInteger length, int currentPosition) = UInt.DecodeUInt(data, position, packed);
            int paddingSize = packed ? (int)length : (1 + (int)length / PaddingMultiple) * PaddingMultiple;

            return(data.Slice(currentPosition, (int)length), currentPosition + paddingSize);
        }
예제 #2
0
        public override (object, int) Decode(byte[] data, int position)
        {
            Array result = Array.CreateInstance(_elementType.CSharpType, Length);

            if (_elementType.IsDynamic)
            {
                BigInteger currentOffset   = (Length - 1) * UInt.LengthInBytes;
                int        lengthsPosition = position;
                for (int i = 0; i < Length; i++)
                {
                    if (i != 0)
                    {
                        (currentOffset, lengthsPosition) = UInt.DecodeUInt(data, lengthsPosition);
                    }

                    object element;
                    (element, currentOffset) = _elementType.Decode(data, position + (int)currentOffset);
                    result.SetValue(element, i);
                }

                position = (int)currentOffset;
            }
            else
            {
                for (int i = 0; i < Length; i++)
                {
                    (object element, int newPosition) = _elementType.Decode(data, position);
                    result.SetValue(element, i);
                    position = newPosition;
                }
            }

            return(result, position);
        }
예제 #3
0
        public override (object, int) Decode(byte[] data, int position, bool packed)
        {
            BigInteger length;

            (length, position) = UInt.DecodeUInt(data, position, packed);

            Array result = Array.CreateInstance(_elementType.CSharpType, (int)length);

            for (int i = 0; i < length; i++)
            {
                object element;
                (element, position) = _elementType.Decode(data, position, packed);

                result.SetValue(element, i);
            }

            return(result, position);
        }