public override object Decode(byte[] encoded, Type type) { var size = new IntTypeDecoder().DecodeInt(encoded.Take(32).ToArray()); //Skip the length of the array, just pass the array values return(Decode(encoded.Skip(32).ToArray(), type, size)); }
protected virtual object DecodeDynamicElementType(byte[] encoded, Type type, int size) { var decodedListOutput = (IList)Activator.CreateInstance(type); if (decodedListOutput == null) { throw new Exception("Only types that implement IList<T> are supported to decode Array Types"); } var elementType = GetIListElementType(type); if (elementType == null) { throw new Exception("Only types that implement IList<T> are supported to decode Array Types"); } var intDecoder = new IntTypeDecoder(); var dataIndexes = new List <int>(); var currentIndex = 0; while (currentIndex < size) { dataIndexes.Add(intDecoder.DecodeInt(encoded.Skip(currentIndex * 32).Take(32).ToArray())); currentIndex++; } currentIndex = 0; while (currentIndex < size) { var currentDataIndex = dataIndexes[currentIndex]; var nextDataIndex = encoded.Length; if (currentIndex + 1 < dataIndexes.Count) { nextDataIndex = dataIndexes[currentIndex + 1]; } var encodedElement = encoded.Skip(currentDataIndex).Take(nextDataIndex - currentDataIndex).ToArray(); DecodeAndAddElement(elementType, decodedListOutput, encodedElement); currentIndex++; } return(decodedListOutput); }
public BoolTypeDecoder() { intTypeDecoder = new IntTypeDecoder(); }
public Bytes32TypeDecoder() { this.intTypeDecoder = new IntTypeDecoder(); this.boolTypeDecoder = new BoolTypeDecoder(); }
public AddressTypeDecoder() { _intTypeDecoder = new IntTypeDecoder(); }
public IntType(string name) : base(name) { Decoder = new IntTypeDecoder(); Encoder = new IntTypeEncoder(); }
public static int GetNumberOfBytes(byte[] encoded) { var intDecoder = new IntTypeDecoder(); var numberOfBytesEncoded = encoded.Take(32); return intDecoder.DecodeInt(numberOfBytesEncoded.ToArray()); }
public IntTypeEncoder() { intTypeDecoder = new IntTypeDecoder(); }
public IntTypeEncoder() { this.intTypeDecoder = new IntTypeDecoder(); }
public Bytes32TypeDecoder() { intTypeDecoder = new IntTypeDecoder(); boolTypeDecoder = new BoolTypeDecoder(); }
public AddressTypeDecoder() { this.intTypeDecoder = new IntTypeDecoder(); }