public KeyValuePair <TKey, TValue>[] Decode <TKey, TValue>([NotNull] FdbSubspace subspace, [NotNull] IKeyEncoder <TKey> keyEncoder, [NotNull] IValueEncoder <TValue> valueEncoder)
        {
            if (subspace == null)
            {
                throw new ArgumentNullException("subspace");
            }
            if (keyEncoder == null)
            {
                throw new ArgumentNullException("keyEncoder");
            }
            if (valueEncoder == null)
            {
                throw new ArgumentNullException("valueEncoder");
            }

            var chunk   = this.Chunk;
            var results = new KeyValuePair <TKey, TValue> [chunk.Length];

            for (int i = 0; i < chunk.Length; i++)
            {
                results[i] = new KeyValuePair <TKey, TValue>(
                    keyEncoder.DecodeKey(subspace.ExtractAndCheck(chunk[i].Key)),
                    valueEncoder.DecodeValue(chunk[i].Value)
                    );
            }

            return(results);
        }
        public static IFdbTuple Unpack(this FdbSubspace subspace, Slice key)
        {
            // We special case 'Slice.Nil' because it is returned by GetAsync(..) when the key does not exist
            // This is to simplifiy decoding logic where the caller could do "var foo = FdbTuple.Unpack(await tr.GetAsync(...))" and then only have to test "if (foo != null)"
            if (key.IsNull)
            {
                return(null);
            }

            return(new FdbPrefixedTuple(subspace.Key, FdbTuple.Unpack(subspace.ExtractAndCheck(key))));
        }
        public static T[] UnpackSingle <T>(this FdbSubspace subspace, [NotNull] Slice[] keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException("keys");
            }

            var values = new T[keys.Length];

            if (keys.Length > 0)
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    values[i] = FdbTuple.UnpackSingle <T>(subspace.ExtractAndCheck(keys[i]));
                }
            }

            return(values);
        }
        public T[] DecodeKeys <T>([NotNull] FdbSubspace subspace, [NotNull] IKeyEncoder <T> keyEncoder)
        {
            if (subspace == null)
            {
                throw new ArgumentNullException("subspace");
            }
            if (keyEncoder == null)
            {
                throw new ArgumentNullException("keyEncoder");
            }

            var results = new T[this.Count];

            for (int i = 0; i < results.Length; i++)
            {
                results[i] = keyEncoder.DecodeKey(subspace.ExtractAndCheck(this.Chunk[i].Key));
            }
            return(results);
        }
        public static IFdbTuple[] Unpack(this FdbSubspace subspace, [NotNull] Slice[] keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException("keys");
            }

            var prefix = subspace.Key;
            var tuples = new IFdbTuple[keys.Length];

            if (keys.Length > 0)
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    if (keys[i].HasValue)
                    {
                        tuples[i] = new FdbPrefixedTuple(prefix, FdbTuple.Unpack(subspace.ExtractAndCheck(keys[i])));
                    }
                }
            }

            return(tuples);
        }
 /// <summary>Unpack a key into a singleton tuple, and return the single element</summary>
 /// <typeparam name="T">Expected type of the only element</typeparam>
 /// <param name="key">Packed version of a key that should fit inside this subspace</param>
 /// <returns>Converted value of the only element in the tuple. Throws an exception if the tuple is empty or contains more than one element</returns>
 /// <example>new Subspace([FE]).UnpackSingle&lt;int&gt;([FE 02 'H' 'e' 'l' 'l' 'o' 00]) => (string) "Hello"</example>
 public static T UnpackSingle <T>(this FdbSubspace subspace, Slice key)
 {
     return(FdbTuple.UnpackSingle <T>(subspace.ExtractAndCheck(key)));
 }