/// <summary>
            /// Helper to convert from legacy persisted data format to the current. The key array is a set of kvp's where the value
            /// is an offset in the value buffer. These all need to be recalculated with new value buffer VLE format
            /// </summary>
            private void TranscodeBuffers(RecyclableMemoryStreamManager memoryStreamManager, Stream destinationStream)
            {
                using (var intermediateValueStream = memoryStreamManager.GetStream("transcoding value-buffer"))
                {
                    uint currentOffset = 0;
                    var  buffer        = new byte[sizeof(uint)];
                    foreach (var kvp in this.keys)
                    {
                        // write the current key and then the offset in fixed length
                        kvp.Key.Serialize(destinationStream);
                        ByteConverter.FixedLengthEncoding.Encode(currentOffset, buffer, destinationStream);

                        var dict       = new Dictionary <long, uint>();
                        var newEntries = this.values.ReadValuesInto(dict, kvp.Value);

                        currentOffset += BufferedValueArray.WriteVariableLengthEncodedDictionary(
                            dict,
                            newEntries,
                            intermediateValueStream);
                    }

                    // now dump the values at the end of the key array
                    destinationStream.Write(intermediateValueStream.GetBuffer(), 0, (int)intermediateValueStream.Length);
                }
            }
 public uint WriteToPersistedData(MemoryStream writeStream)
 {
     return(BufferedValueArray.WriteVariableLengthEncodedDictionary(this.samples, (uint)this.SampleCount,
                                                                    writeStream));
 }