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

Class Metadata

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

Provides access to read and write metadata values to be exchanged during a call. Keys are allowed to be associated with more than one value. This class is not thread safe, implementations should ensure that header reads and writes do not occur in multiple threads concurrently.

Source from the content-addressed store, hash-verified

55 * not occur in multiple threads concurrently.
56 */
57@NotThreadSafe
58public final class Metadata {
59 private static final Logger logger = Logger.getLogger(Metadata.class.getName());
60
61 /**
62 * All binary headers should have this suffix in their names. Vice versa.
63 *
64 * <p>Its value is {@code "-bin"}. An ASCII header's name must not end with this.
65 */
66 public static final String BINARY_HEADER_SUFFIX = "-bin";
67
68 /**
69 * Simple metadata marshaller that encodes bytes as is.
70 *
71 * <p>This should be used when raw bytes are favored over un-serialized version of object. Can be
72 * helpful in situations where more processing to bytes is needed on application side, avoids
73 * double encoding/decoding.
74 *
75 * <p>Both {@link BinaryMarshaller#toBytes} and {@link BinaryMarshaller#parseBytes} methods do not
76 * return a copy of the byte array. Do _not_ modify the byte arrays of either the arguments or
77 * return values.
78 */
79 public static final BinaryMarshaller<byte[]> BINARY_BYTE_MARSHALLER =
80 new BinaryMarshaller<byte[]>() {
81
82 @Override
83 public byte[] toBytes(byte[] value) {
84 return value;
85 }
86
87 @Override
88 public byte[] parseBytes(byte[] serialized) {
89 return serialized;
90 }
91 };
92
93 /**
94 * Simple metadata marshaller that encodes strings as is.
95 *
96 * <p>This should be used with ASCII strings that only contain the characters listed in the class
97 * comment of {@link AsciiMarshaller}. Otherwise the output may be considered invalid and
98 * discarded by the transport, or the call may fail.
99 */
100 public static final AsciiMarshaller<String> ASCII_STRING_MARSHALLER =
101 new AsciiMarshaller<String>() {
102
103 @Override
104 public String toAsciiString(String value) {
105 return value;
106 }
107
108 @Override
109 public String parseAsciiString(String serialized) {
110 return serialized;
111 }
112 };
113
114 static final BaseEncoding BASE64_ENCODING_OMIT_PADDING = BaseEncoding.base64().omitPadding();

Callers

nothing calls this directly

Calls 1

getNameMethod · 0.65

Tested by

no test coverage detected