Skip to content

Commit 5910760

Browse files
committed
Support for lazily serialized values in gRPC Metadata.
First add a new a Metadata.BinaryStreamMarshaller interface which serializes to/from instances of InputStream, and a corresponding Key.of() factory method. Values set with this type of key will be kept unserialized internally, alongside a reference to the Marshaller.x A new method InternalMetadata.serializePartial(), returns values which are either byte[] or InputStream, and allows transport-specific handling of lazily-serialized values. For the regular serialize() method, stream-marshalled values will be converted to byte[] via an InputStreams.
1 parent 09d5093 commit 5910760

3 files changed

Lines changed: 412 additions & 23 deletions

File tree

api/src/main/java/io/grpc/InternalMetadata.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.common.io.BaseEncoding;
2020
import io.grpc.Metadata.AsciiMarshaller;
2121
import io.grpc.Metadata.Key;
22+
import java.io.InputStream;
2223
import java.nio.charset.Charset;
2324

2425
/**
@@ -82,4 +83,19 @@ public static byte[][] serialize(Metadata md) {
8283
public static int headerCount(Metadata md) {
8384
return md.headerCount();
8485
}
86+
87+
@Internal
88+
public static Object[] serializePartial(Metadata md) {
89+
return md.serializePartial();
90+
}
91+
92+
@Internal
93+
public static <T> Metadata.LazyValue<T> parsedValue(Key<T> key, T value) {
94+
return Metadata.LazyValue.create(key, value);
95+
}
96+
97+
@Internal
98+
public static Metadata newMetadataWithStreamValues(int usedNames, Object[] namesAndValues) {
99+
return new Metadata(usedNames, namesAndValues);
100+
}
85101
}

0 commit comments

Comments
 (0)