private void WriteMetricMetadataIndex(BinaryWriter writer, IMetricMetadata value)
        {
            uint index;

            if (!this.metadataIndexes.TryGetValue(value, out index))
            {
                index = this.nextMetadataIndex++;
                this.metadataIndexes.Add(value, index);
                this.metadatas.Add(value);

                if (this.estimatePacketSize)
                {
                    // In versions 0-2 Metric Namespace was part of the Metric data, from version 3 it became a part of Metric Metadata
                    if (this.version >= 3)
                    {
                        this.currentMetadataDictionaryBlockSize += SerializationUtils.EstimateUInt32InBase128Size(this.RegisterString(value.MetricNamespace));
                    }

                    this.currentMetadataDictionaryBlockSize += SerializationUtils.EstimateUInt32InBase128Size(this.RegisterString(value.MetricName));
                    this.currentMetadataDictionaryBlockSize += SerializationUtils.EstimateUInt32InBase128Size((uint)value.DimensionsCount);
                    for (int i = 0; i < value.DimensionsCount; ++i)
                    {
                        this.currentMetadataDictionaryBlockSize += SerializationUtils.EstimateUInt32InBase128Size(this.RegisterString(value.GetDimensionName(i)));
                    }
                }
            }

            SerializationUtils.WriteUInt32AsBase128(writer, index);
        }
 private long EstimateStringSize(string value)
 {
     // Assuming 50 % characters are non-ascii
     return((int)(value.Length * this.stringCharEstimatedSizeInBytes) + SerializationUtils.EstimateUInt32InBase128Size((uint)value.Length));
 }