Example #1
0
        public static string DecodeToString(this RlpItem item)
        {
            if (item.RlpData != null && item.RlpData.Length != 0)
            {
                return(item.RlpData.ToStringFromRLPDecoded());
            }

            return("");
        }
Example #2
0
        public static int DecodeToInt(this RlpItem item)
        {
            if (item.RlpData != null && item.RlpData.Length != 0)
            {
                return(item.RlpData.ToIntFromRLPDecoded());
            }

            return(0);
        }
Example #3
0
        public static bool DecodeToBoolean(this RlpItem item)
        {
            if (item.RlpData != null && item.RlpData.Length != 0)
            {
                return(item.RlpData.SequenceEqual(new byte[] { 01 }));
            }

            return(false);
        }
Example #4
0
        public static BigInteger DecodeToBigInteger(this RlpItem item)
        {
            if (item.RlpData != null && item.RlpData.Length != 0)
            {
                return(item.RlpData.ToBigIntegerFromRLPDecoded());
            }

            return(BigInteger.Zero);
        }
 public static long DecodeToLong(this RlpItem item)
 {
     if (item.RlpData != null && item.RlpData.Length != 0)
     {
         return((item as RlpItem).RlpData.ToLongFromRLPDecoded());
     }
     else
     {
         return(0);
     }
 }
 public static Boolean DecodeToBoolean(this RlpItem item)
 {
     if (item.RlpData != null && item.RlpData.Length != 0)
     {
         return(item.RlpData.SequenceEqual(new byte[1] {
             01
         }) ?  true : false);
     }
     else
     {
         return(false);
     }
 }
Example #7
0
        public IRlpItem Decode(byte[] bytes)
        {
            RlpArray      rlpArray      = new RlpArray();
            RLPCollection rlpCollection = new RLPCollection();

            rlpCollection = RLP.Decode(bytes) as RLPCollection;
            this.RlpData  = rlpCollection.RLPData;
            foreach (IRLPElement item in rlpCollection)
            {
                if (item.RLPData == null || item.RLPData[0] == 0x0)
                {
                    rlpArray.Add(new RlpItem());
                    continue;
                }

                var rlpItem = new RlpItem(item.RLPData);
                rlpArray.Add(rlpItem);
            }
            return(rlpArray);
        }
Example #8
0
        public static dynamic Decode(IRlpKind kind, byte[] data, Type type)
        {
            dynamic  result  = null;
            IRlpItem rlpItem = new RlpItem(data);

            if (kind is IRlpScalarKind)
            {
                result = (kind as IRlpScalarKind).DecodeFromRlp(rlpItem);
            }
            else if (kind is IRlpArrayKind)
            {
                result = (kind as IRlpArrayKind).DecodeFromRlp(rlpItem, type);
            }
            else if (kind is IRplStructKind)
            {
                result = (kind as IRplStructKind).DecodeFromRlp(rlpItem, type);
            }
            else if (kind is IRlpCustomKind)
            {
                result = (kind as IRlpCustomKind).DecodeFromRlp(rlpItem, type);
            }
            return(result);
        }