Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions api/src/main/java/io/grpc/InternalMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.io.BaseEncoding;
import io.grpc.Metadata.AsciiMarshaller;
import io.grpc.Metadata.BinaryStreamMarshaller;
import io.grpc.Metadata.Key;
import java.nio.charset.Charset;

Expand Down Expand Up @@ -82,4 +83,46 @@ public static byte[][] serialize(Metadata md) {
public static int headerCount(Metadata md) {
return md.headerCount();
}

/**
* Serializes all metadata entries, leaving some values as {@link InputStream}s.
*
* <p>Produces serialized names and values interleaved. result[i*2] are names, while
* result[i*2+1] are values.
*
* <p>Names are byte arrays as described according to the {@link Metadata#serialize}
* method. Values are either byte arrays or {@link InputStream}s.
*/
@Internal
public static Object[] serializePartial(Metadata md) {
return md.serializePartial();
}

/**
* Creates a holder for a pre-parsed value read by the transport.
*
* @param marshaller The {@link Metadata#BinaryStreamMarshaller} associated with this value.
* @param value The value to store.
* @return an object holding the pre-parsed value for this key.
*/
@Internal
public static <T> Object parsedValue(BinaryStreamMarshaller<T> marshaller, T value) {
return new Metadata.LazyValue<>(marshaller, value);
}

/**
* Creates a new {@link Metadata} instance from serialized data,
* with some values pre-parsed. Metadata will mutate the passed in array.
*
* @param usedNames The number of names used.
* @param namesAndValues An array of interleaved names and values,
* with each name (at even indices) represented as a byte array,
* and each value (at odd indices) represented as either a byte
* array or an object returned by the {@link #parsedValue}
* method.
*/
@Internal
public static Metadata newMetadataWithParsedValues(int usedNames, Object[] namesAndValues) {
return new Metadata(usedNames, namesAndValues);
}
}
Loading