Exemple #1
0
        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);
                }
            }
Exemple #2
0
        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);
        }
Exemple #3
0
        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());
Exemple #6
0
 private DataDeliveryReceiptDetails Decode(byte[] bytes)
 => _rlpDecoder.Decode(bytes.AsRlpStream());
Exemple #7
0
 private DepositDetails Decode(byte[] bytes)
 => bytes is null
         ? null
         : _rlpDecoder.Decode(bytes.AsRlpContext());
Exemple #8
0
 private NdmConfig Decode(byte[] bytes)
 => bytes is null
         ? null
         : _rlpDecoder.Decode(bytes.AsRlpContext());
Exemple #9
0
 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());
Exemple #11
0
 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());
Exemple #15
0
 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());