Exemplo n.º 1
0
        private static                               T[] BatchDecode <T>(IEnumerable <Slice> packed, IFdbSubspace subspace, IDynamicKeyEncoder encoder, Func <Slice, IDynamicKeyEncoder, T> decode)
        {
            var coll = packed as ICollection <Slice>;

            if (coll != null)
            {
                var res = new T[coll.Count];
                int p   = 0;
                foreach (var data in packed)
                {
                    res[p++] = decode(subspace.ExtractKey(data), encoder);
                }
                Contract.Assert(p == res.Length);
                return(res);
            }
            else
            {
                var res = new List <T>();
                foreach (var data in packed)
                {
                    res.Add(decode(subspace.ExtractKey(data), encoder));
                }
                return(res.ToArray());
            }
        }
        public static async Task DumpSubspace([NotNull] IFdbReadOnlyTransaction tr, [NotNull] IFdbSubspace subspace)
        {
            Assert.That(tr, Is.Not.Null);

            Console.WriteLine("Dumping content of subspace " + subspace.ToString() + " :");
            int count = 0;
            await tr
            .GetRange(KeyRange.StartsWith(subspace.Key))
            .ForEachAsync((kvp) =>
            {
                var key = subspace.ExtractKey(kvp.Key, boundCheck: true);
                ++count;
                string keyDump = null;
                try
                {
                    // attemps decoding it as a tuple
                    keyDump = key.ToTuple().ToString();
                }
                catch (Exception)
                {
                    // not a tuple, dump as bytes
                    keyDump = "'" + key.ToString() + "'";
                }

                Console.WriteLine("- " + keyDump + " = " + kvp.Value.ToString());
            });

            if (count == 0)
            {
                Console.WriteLine("> empty !");
            }
            else
            {
                Console.WriteLine("> Found " + count + " values");
            }
        }
Exemplo n.º 3
0
 private Slice Decode(Slice key)
 {
     return(m_prefix.ExtractKey(key));
 }