Skip to content

Commit 34cc46c

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 34cc46c

3 files changed

Lines changed: 410 additions & 22 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,19 @@ public static byte[][] serialize(Metadata md) {
8282
public static int headerCount(Metadata md) {
8383
return md.headerCount();
8484
}
85+
86+
@Internal
87+
public static Object[] serializePartial(Metadata md) {
88+
return md.serializePartial();
89+
}
90+
91+
@Internal
92+
public static <T> Metadata.LazyValue<T> parsedValue(Key<T> key, T value) {
93+
return Metadata.LazyValue.create(key, value);
94+
}
95+
96+
@Internal
97+
public static Metadata newMetadataWithStreamValues(int usedNames, Object[] namesAndValues) {
98+
return new Metadata(usedNames, namesAndValues);
99+
}
85100
}

0 commit comments

Comments
 (0)