Common utilities for GRPC.
| 77 | * Common utilities for GRPC. |
| 78 | */ |
| 79 | public final class GrpcUtil { |
| 80 | |
| 81 | private static final Logger log = Logger.getLogger(GrpcUtil.class.getName()); |
| 82 | |
| 83 | private static final Set<Status.Code> INAPPROPRIATE_CONTROL_PLANE_STATUS |
| 84 | = Collections.unmodifiableSet(EnumSet.of( |
| 85 | Status.Code.OK, |
| 86 | Status.Code.INVALID_ARGUMENT, |
| 87 | Status.Code.NOT_FOUND, |
| 88 | Status.Code.ALREADY_EXISTS, |
| 89 | Status.Code.FAILED_PRECONDITION, |
| 90 | Status.Code.ABORTED, |
| 91 | Status.Code.OUT_OF_RANGE, |
| 92 | Status.Code.DATA_LOSS)); |
| 93 | |
| 94 | public static final Charset US_ASCII = Charset.forName("US-ASCII"); |
| 95 | |
| 96 | /** |
| 97 | * {@link io.grpc.Metadata.Key} for the timeout header. |
| 98 | */ |
| 99 | public static final Metadata.Key<Long> TIMEOUT_KEY = |
| 100 | Metadata.Key.of(GrpcUtil.TIMEOUT, new TimeoutMarshaller()); |
| 101 | |
| 102 | /** |
| 103 | * {@link io.grpc.Metadata.Key} for the message encoding header. |
| 104 | */ |
| 105 | public static final Metadata.Key<String> MESSAGE_ENCODING_KEY = |
| 106 | Metadata.Key.of(GrpcUtil.MESSAGE_ENCODING, Metadata.ASCII_STRING_MARSHALLER); |
| 107 | |
| 108 | /** |
| 109 | * {@link io.grpc.Metadata.Key} for the accepted message encodings header. |
| 110 | */ |
| 111 | public static final Metadata.Key<byte[]> MESSAGE_ACCEPT_ENCODING_KEY = |
| 112 | InternalMetadata.keyOf(GrpcUtil.MESSAGE_ACCEPT_ENCODING, new AcceptEncodingMarshaller()); |
| 113 | |
| 114 | /** |
| 115 | * {@link io.grpc.Metadata.Key} for the stream's content encoding header. |
| 116 | */ |
| 117 | public static final Metadata.Key<String> CONTENT_ENCODING_KEY = |
| 118 | Metadata.Key.of(GrpcUtil.CONTENT_ENCODING, Metadata.ASCII_STRING_MARSHALLER); |
| 119 | |
| 120 | /** |
| 121 | * {@link io.grpc.Metadata.Key} for the stream's accepted content encoding header. |
| 122 | */ |
| 123 | public static final Metadata.Key<byte[]> CONTENT_ACCEPT_ENCODING_KEY = |
| 124 | InternalMetadata.keyOf(GrpcUtil.CONTENT_ACCEPT_ENCODING, new AcceptEncodingMarshaller()); |
| 125 | |
| 126 | static final Metadata.Key<String> CONTENT_LENGTH_KEY = |
| 127 | Metadata.Key.of("content-length", Metadata.ASCII_STRING_MARSHALLER); |
| 128 | |
| 129 | private static final class AcceptEncodingMarshaller implements TrustedAsciiMarshaller<byte[]> { |
| 130 | @Override |
| 131 | public byte[] toAsciiString(byte[] value) { |
| 132 | return value; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public byte[] parseAsciiString(byte[] serialized) { |