/// <summary>Creates a key range containing all children of tuple, optionally including the tuple itself.</summary>
        /// <param name="tuple">Tuple that is the prefix of all keys</param>
        /// <param name="includePrefix">If true, the tuple key itself is included, if false only the children keys are included</param>
        /// <returns>Range of all keys suffixed by the tuple. The tuple itself will be included if <paramref name="includePrefix"/> is true</returns>
        public static FdbKeyRange ToRange([NotNull] this IFdbTuple tuple, bool includePrefix)
        {
            if (tuple == null)
            {
                throw new ArgumentNullException("tuple");
            }

            // We want to allocate only one byte[] to store both keys, and map both Slice to each chunk
            // So we will serialize the tuple two times in the same writer

            var writer = SliceWriter.Empty;

            tuple.PackTo(ref writer);
            writer.EnsureBytes(writer.Position + 2);
            if (!includePrefix)
            {
                writer.WriteByte(0);
            }
            int p0 = writer.Position;

            tuple.PackTo(ref writer);
            writer.WriteByte(0xFF);
            int p1 = writer.Position;

            return(new FdbKeyRange(
                       new Slice(writer.Buffer, 0, p0),
                       new Slice(writer.Buffer, p0, p1 - p0)
                       ));
        }
 public void PackTo(ref TupleWriter writer)
 {
     writer.Output.WriteBytes(m_prefix);
     m_items.PackTo(ref writer);
 }
Пример #3
0
 public void PackTo(ref SliceWriter writer)
 {
     writer.WriteBytes(m_prefix);
     m_items.PackTo(ref writer);
 }