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

Class Key

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

Key for metadata entries. Allows for parsing and serialization of metadata. Valid characters in key names Only the following ASCII characters are allowed in the names of keys: digits: 0-9 uppercase letters: A-Z (normalized to lower) lowercase letters:

Source from the content-addressed store, hash-verified

668 * @see <a href="https://tools.ietf.org/html/rfc5234#appendix-B.1">RFC5234</a>
669 */
670 @Immutable
671 public abstract static class Key<T> {
672
673 /** Valid characters for field names as defined in RFC7230 and RFC5234. */
674 private static final BitSet VALID_T_CHARS = generateValidTChars();
675
676 /**
677 * Creates a key for a binary header.
678 *
679 * @param name Must contain only the valid key characters as defined in the class comment. Must
680 * end with {@link #BINARY_HEADER_SUFFIX}.
681 */
682 public static <T> Key<T> of(String name, BinaryMarshaller<T> marshaller) {
683 return new BinaryKey<>(name, marshaller);
684 }
685
686 /**
687 * Creates a key for a binary header, serializing to input streams.
688 *
689 * @param name Must contain only the valid key characters as defined in the class comment. Must
690 * end with {@link #BINARY_HEADER_SUFFIX}.
691 */
692 @ExperimentalApi("https://github.com/grpc/grpc-java/issues/6575")
693 public static <T> Key<T> of(String name, BinaryStreamMarshaller<T> marshaller) {
694 return new LazyStreamBinaryKey<>(name, marshaller);
695 }
696
697 /**
698 * Creates a key for an ASCII header.
699 *
700 * @param name Must contain only the valid key characters as defined in the class comment. Must
701 * <b>not</b> end with {@link #BINARY_HEADER_SUFFIX}
702 */
703 public static <T> Key<T> of(String name, AsciiMarshaller<T> marshaller) {
704 return of(name, false, marshaller);
705 }
706
707 static <T> Key<T> of(String name, boolean pseudo, AsciiMarshaller<T> marshaller) {
708 return new AsciiKey<>(name, pseudo, marshaller);
709 }
710
711 static <T> Key<T> of(String name, boolean pseudo, TrustedAsciiMarshaller<T> marshaller) {
712 return new TrustedAsciiKey<>(name, pseudo, marshaller);
713 }
714
715 private final String originalName;
716
717 private final String name;
718 private final byte[] nameBytes;
719 private final Object marshaller;
720
721 private static BitSet generateValidTChars() {
722 BitSet valid = new BitSet(0x7f);
723 valid.set('-');
724 valid.set('_');
725 valid.set('.');
726 for (char c = '0'; c <= '9'; c++) {
727 valid.set(c);

Callers

nothing calls this directly

Calls 1

generateValidTCharsMethod · 0.95

Tested by

no test coverage detected