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

Class BinaryKey

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

Source from the content-addressed store, hash-verified

857 }
858
859 private static class BinaryKey<T> extends Key<T> {
860 private final BinaryMarshaller<T> marshaller;
861
862 /** Keys have a name and a binary marshaller used for serialization. */
863 private BinaryKey(String name, BinaryMarshaller<T> marshaller) {
864 super(name, false /* not pseudo */, marshaller);
865 checkArgument(
866 name.endsWith(BINARY_HEADER_SUFFIX),
867 "Binary header is named %s. It must end with %s",
868 name,
869 BINARY_HEADER_SUFFIX);
870 checkArgument(name.length() > BINARY_HEADER_SUFFIX.length(), "empty key name");
871 this.marshaller = checkNotNull(marshaller, "marshaller is null");
872 }
873
874 @Override
875 byte[] toBytes(T value) {
876 return Preconditions.checkNotNull(marshaller.toBytes(value), "null marshaller.toBytes()");
877 }
878
879 @Override
880 T parseBytes(byte[] serialized) {
881 return marshaller.parseBytes(serialized);
882 }
883 }
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> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected