Exemplo n.º 1
0
        public RlpArray EncodeWithJson(JToken item)
        {
            if (this.Nullable && (item == null || item.Type == JTokenType.Null))
            {
                return(new RlpArray());
            }
            RlpArray result = new RlpArray();

            foreach (IRlpKind kind in Properties)
            {
                if (kind is IRlpScalarKind)
                {
                    IRlpItem rlpItem = (kind as IRlpScalarKind).EncodeWithJson(item[kind.Name]);
                    result.Add(rlpItem);
                }
                else if (kind is IRlpArrayKind)
                {
                    RlpArray rArray = (kind as IRlpArrayKind).EncodeWithJson(item[kind.Name]);
                    result.Add(rArray);
                }
                else if (kind is IRplStructKind)
                {
                    RlpArray rArray = (kind as IRplStructKind).EncodeWithJson(item[kind.Name]);
                    result.Add(rArray);
                }
                else if (kind is IRlpCustomKind)
                {
                    IRlpItem rlpItem = (kind as IRlpCustomKind).EncodeWithJson(item[kind.Name]);
                    result.Add(rlpItem);
                }
            }
            return(result);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public RlpArray EncodeWithJson(JToken items)
        {
            if (this.Nullable && (items == null || items.Type == JTokenType.Null))
            {
                return(new RlpArray());
            }
            RlpArray rlpArray = new RlpArray();

            foreach (var item in (items as JArray))
            {
                if (this.ItemKind is IRlpScalarKind)
                {
                    IRlpItem rlpItem = (this.ItemKind as IRlpScalarKind).EncodeWithJson(item as JValue);
                    rlpArray.Add(rlpItem);
                }
                else if (this.ItemKind is IRlpArrayKind)
                {
                    if (item is JArray)
                    {
                        JArray   jArray = item as JArray;
                        RlpArray rArray = (this.ItemKind as IRlpArrayKind).EncodeWithJson(jArray);
                        rlpArray.Add(rArray);
                    }
                    else
                    {
                        throw new ArgumentException("invalid item type");
                    }
                }
                else if (this.ItemKind is IRplStructKind)
                {
                    RlpArray rArray = (this.ItemKind as IRplStructKind).EncodeWithJson(item);
                    rlpArray.Add(rArray);
                }
                else if (this.ItemKind is IRlpCustomKind)
                {
                    IRlpItem rlpItem = (this.ItemKind as IRlpCustomKind).EncodeWithJson(item);
                    rlpArray.Add(rlpItem);
                }
            }
            return(rlpArray);
        }