/// <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 KeyRange ToRange([NotNull] this ITuple tuple, bool includePrefix) { if (tuple == null) { throw new ArgumentNullException(nameof(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 = new TupleWriter(); tuple.PackTo(ref writer); writer.Output.EnsureBytes(writer.Output.Position + 2); if (!includePrefix) { writer.Output.WriteByte(0); } int p0 = writer.Output.Position; tuple.PackTo(ref writer); writer.Output.WriteByte(0xFF); int p1 = writer.Output.Position; return(new KeyRange( new Slice(writer.Output.Buffer, 0, p0), new Slice(writer.Output.Buffer, p0, p1 - p0) )); }
public void PackTo(ref TupleWriter writer) { writer.Output.WriteBytes(m_prefix); m_items.PackTo(ref writer); }