MCPcopy Create free account
hub / github.com/grpc/grpc-java / LazyStreamBinaryKey

Class LazyStreamBinaryKey

api/src/main/java/io/grpc/Metadata.java:886–916  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

884
885 /** A binary key for values which should be serialized lazily to {@link InputStream}s. */
886 private static class LazyStreamBinaryKey<T> extends Key<T> {
887
888 private final BinaryStreamMarshaller<T> marshaller;
889
890 /** Keys have a name and a stream marshaller used for serialization. */
891 private LazyStreamBinaryKey(String name, BinaryStreamMarshaller<T> marshaller) {
892 super(name, false /* not pseudo */, marshaller);
893 checkArgument(
894 name.endsWith(BINARY_HEADER_SUFFIX),
895 "Binary header is named %s. It must end with %s",
896 name,
897 BINARY_HEADER_SUFFIX);
898 checkArgument(name.length() > BINARY_HEADER_SUFFIX.length(), "empty key name");
899 this.marshaller = checkNotNull(marshaller, "marshaller is null");
900 }
901
902 @Override
903 byte[] toBytes(T value) {
904 return streamToBytes(checkNotNull(marshaller.toStream(value), "null marshaller.toStream()"));
905 }
906
907 @Override
908 T parseBytes(byte[] serialized) {
909 return marshaller.parseStream(new ByteArrayInputStream(serialized));
910 }
911
912 @Override
913 boolean serializesToStreams() {
914 return true;
915 }
916 }
917
918 /** Internal holder for values which are serialized/de-serialized lazily. */
919 static final class LazyValue<T> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected