public static MetadataArraySafeHandle Create(Metadata metadata)
 {
     using (Profilers.ForCurrentThread().NewScope("MetadataArraySafeHandle.Create"))
     {
         // TODO(jtattermusch): we might wanna check that the metadata is readonly
         var metadataArray = pinvoke.grpcsharp_metadata_array_create(new UIntPtr((ulong)metadata.Count));
         for (int i = 0; i < metadata.Count; i++)
         {
             var valueBytes = metadata[i].GetSerializedValueUnsafe();
             pinvoke.grpcsharp_metadata_array_add(metadataArray, metadata[i].Key, valueBytes, new UIntPtr((ulong)valueBytes.Length));
         }
         return(metadataArray);
     }
 }