Class GrpcMetadata
java.lang.Object
com.codename1.backend.grpc.GrpcMetadata
The encodings gRPC layers on top of HTTP/2 headers: the grpc-timeout
deadline, the percent-encoded grpc-message, and binary metadata in
headers whose name ends in -bin.
Each is small and each has been gotten wrong by somebody: a timeout whose
unit letter is case sensitive (M minutes, m milliseconds), a status
message that must survive any UTF-8 a handler puts in it, and base64 that a
sender may or may not pad.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe suffix that marks a header as binary metadata. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decodeBinary(String value) Decodes binary metadata, padded or not.static StringdecodeMessage(String value) Decodes agrpc-message.static StringencodeBinary(byte[] value) Encodes binary metadata.static StringencodeMessage(String message) Percent-encodes a status message forgrpc-message: every byte of its UTF-8 form outside printable ASCII, and%itself, becomes%XX.static StringformatTimeoutMillis(long millis) Formats a timeout forgrpc-timeout, choosing the finest unit that keeps the value within eight digits.static booleanWhether a header name carries binary metadata.static longparseTimeoutNanos(String value) Parsesgrpc-timeout: at most eight ASCII digits and a unit, one ofH M S m u n.
-
Field Details
-
BINARY_SUFFIX
The suffix that marks a header as binary metadata.- See Also:
-
-
Method Details
-
parseTimeoutNanos
Parsesgrpc-timeout: at most eight ASCII digits and a unit, one ofH M S m u n. The unit is case sensitive.- Parameters:
value- the header value, may be null- Returns:
- the timeout in nanoseconds, or -1 when the header is absent or malformed (a malformed timeout is ignored, as grpc-java does)
-
formatTimeoutMillis
Formats a timeout forgrpc-timeout, choosing the finest unit that keeps the value within eight digits. A coarser unit rounds up, so the advertised deadline is never earlier than the real one.- Parameters:
millis- the remaining time in milliseconds, at least 1- Returns:
- the header value
-
encodeMessage
-
decodeMessage
-
isBinary
Whether a header name carries binary metadata.- Parameters:
name- a header name- Returns:
- true for a name ending in
-bin, compared without case
-
encodeBinary
Encodes binary metadata. gRPC senders omit the padding; receivers accept either.- Parameters:
value- the bytes- Returns:
- unpadded base64
-
decodeBinary
Decodes binary metadata, padded or not.- Parameters:
value- the header value- Returns:
- the bytes, or null when the value is not base64
-