public IRlpItem EncodeToRlp(dynamic obj) { if (this.Nullable && obj == null) { return(null); } if (obj is Reserved) { var reserved = (obj as Reserved); RlpArray result = new RlpArray(); result.Add((new RlpIntKind("", 4, false)).EncodeToRlp(reserved.Features)); if (reserved.Unused != null) { foreach (byte[] item in reserved.Unused) { result.Add((new RlpBytesKind(true).EncodeToRlp(item))); } } return(result); } else { throw new ArgumentException("value type invalid"); } }
public dynamic DecodeFromRlp(IRlpItem rlp, Type type) { if (this.Nullable && (rlp == null || rlp.RlpData.Length == 0)) { return(null); } RlpArray rlpArray = new RlpArray(); if (rlp.RlpType == RlpType.Array) { rlpArray = (rlp as RlpArray); } else { rlpArray = ((new RlpArray()).Decode(rlp.RlpData) as RlpArray); } if (rlpArray != null && rlpArray.Count != 0) { if (rlpArray[rlpArray.Count - 1].RlpData.Length == 0) { throw new ArgumentException("invalid reserved fields: not trimmed"); } Reserved reserved = new Reserved(); reserved.Features = new RlpIntKind().DecodeFromRlp(rlpArray[0]); if (rlpArray.Count > 1) { reserved.Unused = new List <byte[]>(); for (int index = 1; index < rlpArray.Count; index++) { reserved.Unused.Add(new RlpBytesKind(true).DecodeFromRlp(rlpArray[index])); } } return(reserved); } else { return(null); } }
public dynamic DecodeFromRlp(IRlpItem rlp, Type type) { if (this.Nullable && (rlp == null || rlp.RlpData.Length == 0)) { return(null); } RlpArray rlpArray = new RlpArray(); if (rlp.RlpType == RlpType.Array) { rlpArray = rlp as RlpArray; } else { rlpArray = new RlpArray().Decode(rlp.RlpData) as RlpArray; } if (rlpArray != null && rlpArray.Count != 0) { if (rlpArray[^ 1].RlpData.Length == 0)