Top Description Inners Fields Constructors Methods
io.grpc

public final Class Metadata

extends Object
Class Inheritance
Annotations
@NotThreadSafe
Static Imports
com.google.common.base.Charsets.US_ASCII, .Preconditions.checkArgument, .Preconditions.checkNotNull

Provides access to read and write metadata values to be exchanged during a call.

Keys are allowed to be associated with more than one value.

This class is not thread safe, implementations should ensure that header reads and writes do not occur in multiple threads concurrently.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static interface
Metadata.AsciiMarshaller<T>

Marshaller for metadata values that are serialized into ASCII strings.

private static class
public static interface
Metadata.BinaryMarshaller<T>

Marshaller for metadata values that are serialized into raw binary.

public static interface
Metadata.BinaryStreamMarshaller<T>

Marshaller for metadata values that are serialized to an InputStream.

private class
public abstract static class
Metadata.Key<T>

Key for metadata entries.

private static class
Metadata.LazyStreamBinaryKey<T>

A binary key for values which should be serialized lazily to InputStreams.

pack-priv static class
Metadata.LazyValue<T>

Internal holder for values which are serialized/de-serialized lazily.

private static class
pack-priv static interface
Metadata.TrustedAsciiMarshaller<T>

A specialized plain ASCII marshaller.

Field Summary

Modifier and TypeField and Description
public static final Metadata.AsciiMarshaller<String>
ASCII_STRING_MARSHALLER

Simple metadata marshaller that encodes strings as is.

pack-priv static final BaseEncoding
public static final Metadata.BinaryMarshaller<byte[]>
BINARY_BYTE_MARSHALLER

Simple metadata marshaller that encodes bytes as is.

public static final String
BINARY_HEADER_SUFFIX

All binary headers should have this suffix in their names.

private static final Logger
private Object[]
private int

Constructor Summary

AccessConstructor and Description
pack-priv
Metadata(byte[]... binaryValues)

Constructor called by the transport layer when it receives binary metadata.

pack-priv
Metadata(int
the number of names
usedNames
,
byte[]... binaryValues)

Constructor called by the transport layer when it receives binary metadata.

pack-priv
Metadata(int
the number of names
usedNames
,
Object[]
an array of interleaved names and values, with each name (at even indices) represented by a byte array, and values (at odd indices) as described by InternalMetadata#newMetadataWithParsedValues.
namesAndValues
)

Constructor called by the transport layer when it receives partially-parsed metadata.

public
Metadata()

Constructor called by the application layer when it wants to send metadata.

Method Summary

Modifier and TypeMethod and Description
private boolean
bytesEqual(byte[] left, byte[] right)

private int
cap()

public boolean
containsKey(Metadata.Key<?> key)

Returns true if a value is defined for the given key.

public <T> void
discardAll(Metadata.Key<T> key)

Remove all values for the given key without returning them.

private void
expand(int newCapacity)

public <T> T

Returns:

the parsed metadata entry or null if there are none.
get
(Metadata.Key<T> key)

Returns the last metadata entry added with the name 'name' parsed as T.

public <T> Iterable<T>
getAll(final Metadata.Key<T> key)

Returns all the metadata entries named 'name', in the order they were received, parsed as T, or null if there are none.

pack-priv int
headerCount()

Returns the total number of key-value headers in this metadata, including duplicates.

private boolean
isEmpty()

checks when namesAndValues is null or has no elements.

public Set<String>

Returns:

unmodifiable Set of keys
keys
()

Returns set of all keys in store.

private int
len()

private void
public void
merge(Metadata other)

Perform a simple merge of two sets of metadata.

public void
merge(Metadata
The source of the new key values.
other
,
Set<Metadata.Key<?>>
The subset of matching key we want to copy, if they exist in the source.
keys
)

Merge values from the given set of keys into this set of metadata.

private byte[]
name(int i)

private void
name(int i, byte[] name)

public <T> void
put(Metadata.Key<T> key, T value)

Adds the key, value pair.

public <T> boolean

Returns:

true if value removed; false if value was not present
remove
(Metadata.Key<T>
key for value
key
,
T
value
value
)

Removes the first occurrence of value for key.

public <T> Iterable<T>
removeAll(Metadata.Key<T> key)

Remove all values for the given key.

pack-priv byte[][]
serialize()

Serialize all the metadata entries.

pack-priv Object[]
serializePartial()

Serializes all metadata entries, leaving some values as InputStreams.

private static byte[]
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private Object
value(int i)

private void
value(int i, byte[] value)

private void
value(int i, Object value)

private byte[]
valueAsBytes(int i)

private Object
private <T> T
valueAsT(int i, Metadata.Key<T> key)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait