Beispiel #1
0
        /// <summary>
        /// Reads metadata from pointer to grpc_metadata_array
        /// </summary>
        public static Metadata ReadMetadataFromPtrUnsafe(IntPtr metadataArray)
        {
            if (metadataArray == IntPtr.Zero)
            {
                return(null);
            }

            ulong count = pinvoke.grpcsharp_metadata_array_count(metadataArray).ToUInt64();

            var metadata = new Metadata();

            for (ulong i = 0; i < count; i++)
            {
                var    index = new UIntPtr(i);
                string key   = Marshal.PtrToStringAnsi(pinvoke.grpcsharp_metadata_array_get_key(metadataArray, index));
                var    bytes = new byte[pinvoke.grpcsharp_metadata_array_get_value_length(metadataArray, index).ToUInt64()];
                Marshal.Copy(pinvoke.grpcsharp_metadata_array_get_value(metadataArray, index), bytes, 0, bytes.Length);
                metadata.Add(Metadata.Entry.CreateUnsafe(key, bytes));
            }
            return(metadata);
        }