Exemplo n.º 1
0
 public async Task <Snapshot> Load(string emitterId)
 {
     return(env.Read(txn =>
     {
         using (var owner = MemoryPool <byte> .Shared.Rent(MaxBufferSize))
         {
             var key = new DirectBuffer(Encoding.UTF8.GetBytes(emitterId));
             var data = new DirectBuffer(owner.Memory.Span);
             using (var cursor = db.OpenReadOnlyCursor(txn))
             {
                 if (cursor.TryGet(ref key, ref data, CursorGetOption.Last))
                 {
                     return (Snapshot)snapshotSerializer.FromBinary(owner.Memory.ToArray(), typeof(Snapshot));
                 }
                 else
                 {
                     return default(Snapshot);
                 }
             }
         }
     }));
 }