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));
        }
示例#2
0
        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();
 }
示例#4
0
 public Bytes32TypeDecoder()
 {
     this.intTypeDecoder  = new IntTypeDecoder();
     this.boolTypeDecoder = new BoolTypeDecoder();
 }
示例#5
0
 public AddressTypeDecoder()
 {
     _intTypeDecoder = new IntTypeDecoder();
 }
示例#6
0
 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());
 }
示例#8
0
 public IntTypeEncoder()
 {
     intTypeDecoder = new IntTypeDecoder();
 }
示例#9
0
 public BoolTypeDecoder()
 {
     intTypeDecoder = new IntTypeDecoder();
 }
示例#10
0
 public IntTypeEncoder()
 {
     this.intTypeDecoder = new IntTypeDecoder();
 }
示例#11
0
 public Bytes32TypeDecoder()
 {
     intTypeDecoder = new IntTypeDecoder();
     boolTypeDecoder = new BoolTypeDecoder();
 }
示例#12
0
 public Bytes32TypeDecoder()
 {
     this.intTypeDecoder = new IntTypeDecoder();
     this.boolTypeDecoder = new BoolTypeDecoder();    
 }
示例#13
0
 public Bytes32TypeDecoder()
 {
     intTypeDecoder  = new IntTypeDecoder();
     boolTypeDecoder = new BoolTypeDecoder();
 }
示例#14
0
 public AddressTypeDecoder()
 {
     this.intTypeDecoder = new IntTypeDecoder();
 }
示例#15
0
        public AddressTypeDecoder()
        {
            this.intTypeDecoder = new IntTypeDecoder();

        }