public sealed class Metadata : IList<Metadata.Entry>, ICollection<Metadata.Entry>, IEnumerable<Metadata.Entry>, IEnumerable
A collection of metadata entries that can be exchanged during a call. gRPC supports these types of metadata:
- Request headers are sent by the client at the beginning of a remote call before any request messages are sent.
- Response headers are sent by the server at the beginning of a remote call handler before any response messages are sent.
- Response trailers are sent by the server at the end of a remote call along with resulting call status.
Implements
IList Metadata Entry , ICollection Metadata Entry , IEnumerable Metadata Entry , IEnumerableNamespace
Grpc.CoreAssembly
Grpc.Core.Api.dll
Constructors
Metadata()
public Metadata()
Initializes a new instance of Metadata
.
Fields
BinaryHeaderSuffix
public
const
string
BinaryHeaderSuffix
=
"-bin"
All binary headers should have this suffix.
Empty
public static readonly Metadata Empty
An read-only instance of metadata containing no entries.
Properties
Count
public int Count { get; }
IsReadOnly
public bool IsReadOnly { get; }
this[int]
public
Metadata
.
Entry
this
[
int
index
]
{
get
;
set
;
}
Methods
Add(Entry)
public void Add(Metadata.Entry item)
Add(string, byte[])
public void Add(string key, byte[] valueBytes)
Adds a new binary-valued metadata entry.
key
string
Metadata key. Gets converted to lowercase. Needs to have -bin
suffix indicating a binary-valued metadata entry. The binary header suffix can be added to the key with BinaryHeaderSuffix
. Can only contain lowercase alphanumeric characters, underscores, hyphens, and dots.
valueBytes
Add(string, string)
public void Add(string key, string value)
Adds a new ASCII-valued metadata entry.
Clear()
public void Clear()
Contains(Entry)
public bool Contains(Metadata.Entry item)
CopyTo(Entry[], int)
public void CopyTo(Metadata.Entry[] array, int arrayIndex)
Get(string)
public Metadata.Entry? Get(string key)
Gets the last metadata entry with the specified key.
If there are no matching entries then null
is returned.
GetAll(string)
public IEnumerable<Metadata.Entry> GetAll(string key)
Gets all metadata entries with the specified key.
GetEnumerator()
public IEnumerator<Metadata.Entry> GetEnumerator()
GetValue(string)
public string? GetValue(string key)
Gets the string value of the last metadata entry with the specified key.
If the metadata entry is binary then an exception is thrown.
If there are no matching entries then null
is returned.
GetValueBytes(string)
public byte[]? GetValueBytes(string key)
Gets the bytes value of the last metadata entry with the specified key.
If the metadata entry is not binary the string value will be returned as ASCII encoded bytes.
If there are no matching entries then null
is returned.
IndexOf(Entry)
public int IndexOf(Metadata.Entry item)
Insert(int, Entry)
public void Insert(int index, Metadata.Entry item)
Remove(Entry)
public bool Remove(Metadata.Entry item)
RemoveAt(int)
public void RemoveAt(int index)