Exemplo n.º 1
0
        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));
        }
Exemplo n.º 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 Bytes32TypeDecoder()
 {
     _intTypeDecoder  = new IntTypeDecoder();
     _boolTypeDecoder = new BoolTypeDecoder();
 }
Exemplo n.º 4
0
 public BoolTypeDecoder()
 {
     _intTypeDecoder = new IntTypeDecoder();
 }
Exemplo n.º 5
0
 public AddressTypeDecoder()
 {
     _intTypeDecoder = new IntTypeDecoder();
 }