public override (object, int) Decode(byte[] data, int position, bool packed) { (BigInteger length, int currentPosition) = UInt256.DecodeUInt(data, position, packed); int paddingSize = packed ? (int)length : (1 + (int)length / PaddingMultiple) * PaddingMultiple; return(data.Slice(currentPosition, (int)length), currentPosition + paddingSize); }
public override (object, int) Decode(byte[] data, int position, bool packed) { UInt256 length; (length, position) = UInt256.DecodeUInt(data, position, packed); return(DecodeSequence(ElementType.CSharpType, (int)length, ElementTypes, data, packed, position)); }
internal static (Array, int) DecodeSequence(Type elementType, int length, IEnumerable <AbiType> types, byte[] data, bool packed, int startPosition) { Array sequence = Array.CreateInstance(elementType, length); int position = startPosition; int dynamicPosition = 0; using IEnumerator <AbiType> typesEnumerator = types.GetEnumerator(); object?item; for (int i = 0; i < length; i++) { typesEnumerator.MoveNext(); AbiType type = typesEnumerator.Current; if (type.IsDynamic) { (UInt256 offset, int nextPosition) = UInt256.DecodeUInt(data, position, packed); (item, dynamicPosition) = type.Decode(data, startPosition + (int)offset, packed); position = nextPosition; } else { (item, position) = type.Decode(data, position, packed); } sequence.SetValue(item, i); } return(sequence, Math.Max(position, dynamicPosition)); }
public override (object, int) Decode(byte[] data, int position, bool packed) { BigInteger length; (length, position) = UInt256.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); }