public static TItem Get <TItem>(this IDb db, Keccak key, IRlpDecoder <TItem> decoder, ICache <Keccak, TItem> cache = null, bool shouldCache = true) where TItem : class { TItem item = cache?.Get(key); if (item == null) { if (db is IDbWithSpan spanDb && decoder is IRlpValueDecoder <TItem> valueDecoder) { Span <byte> data = spanDb.GetSpan(key); if (data.IsNullOrEmpty()) { return(null); } try { var rlpValueContext = data.AsRlpValueContext(); item = valueDecoder.Decode(ref rlpValueContext, RlpBehaviors.AllowExtraData); } finally { spanDb.DangerousReleaseMemory(data); } } else { byte[] data = db.Get(key); if (data == null) { return(null); } item = decoder.Decode(data.AsRlpStream(), RlpBehaviors.AllowExtraData); } }
public static T[] DecodeArray <T>(this IRlpDecoder <T> decoder, RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { int checkPosition = rlpStream.ReadSequenceLength() + rlpStream.Position; T[] result = new T[rlpStream.ReadNumberOfItemsRemaining(checkPosition)]; for (int i = 0; i < result.Length; i++) { result[i] = decoder.Decode(rlpStream, rlpBehaviors); } return(result); }
public static T[] DecodeArray <T>(DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (Decoders.ContainsKey(typeof(T))) { IRlpDecoder <T> decoder = (IRlpDecoder <T>)Decoders[typeof(T)]; int checkPosition = context.ReadSequenceLength() + context.Position; T[] result = new T[context.ReadNumberOfItemsRemaining(checkPosition)]; for (int i = 0; i < result.Length; i++) { result[i] = decoder.Decode(context, rlpBehaviors); } return(result); } throw new RlpException($"{nameof(Rlp)} does not support decoding {typeof(T).Name}"); }
private DepositApproval Decode(byte[] bytes) => bytes is null ? null : _rlpDecoder.Decode(bytes.AsRlpStream());
private DepositDetails Decode(byte[] bytes) => _rlpDecoder.Decode(bytes.AsRlpStream());
private DataDeliveryReceiptDetails Decode(byte[] bytes) => _rlpDecoder.Decode(bytes.AsRlpStream());
private DepositDetails Decode(byte[] bytes) => bytes is null ? null : _rlpDecoder.Decode(bytes.AsRlpContext());
private NdmConfig Decode(byte[] bytes) => bytes is null ? null : _rlpDecoder.Decode(bytes.AsRlpContext());
private EthRequest Decode(byte[] bytes) => bytes is null ? null : _rlpDecoder.Decode(bytes.AsRlpContext());
private DataDeliveryReceiptDetails Decode(byte[] bytes) => bytes is null ? null : _rlpDecoder.Decode(bytes.AsRlpContext());
private EthRequest Decode(byte[] bytes) => bytes is null ? null : _rlpDecoder.Decode(bytes.AsRlpStream());
private EthRequest Decode(byte[] bytes) => _rlpDecoder.Decode(bytes.AsRlpStream());
private ConsumerSession Decode(byte[] bytes) => _rlpDecoder.Decode(bytes.AsRlpStream());
private DepositApproval Decode(byte[] bytes) => _rlpDecoder.Decode(bytes.AsRlpStream());
private NdmConfig Decode(byte[] bytes) => bytes is null ? null : _rlpDecoder.Decode(bytes.AsRlpStream());
private ConsumerSession Decode(byte[] bytes) => bytes is null ? null : _rlpDecoder.Decode(bytes.AsRlpStream());