Class GrpcHeadersUtil

java.lang.Object
io.helidon.grpc.core.GrpcHeadersUtil

public class GrpcHeadersUtil extends Object
Utility class for gRPC metadata and timeout headers.
  • Method Details

    • encodeTimeout

      public static String encodeTimeout(long timeoutNanos)
      Encodes a timeout as a gRPC grpc-timeout header value. The value uses at most eight decimal digits and the finest unit that fits, rounding up when conversion to a coarser unit is necessary.
      Parameters:
      timeoutNanos - nonnegative timeout in nanoseconds
      Returns:
      encoded timeout
      Throws:
      IllegalArgumentException - if the timeout is negative
    • decodeTimeout

      public static long decodeTimeout(String timeout)
      Decodes a gRPC grpc-timeout header value. The value must contain one to eight ASCII decimal digits followed by H, M, S, m, u, or n. Timeouts exceeding the nanosecond range are saturated at Long.MAX_VALUE.
      Parameters:
      timeout - encoded timeout
      Returns:
      nonnegative timeout in nanoseconds
      Throws:
      IllegalArgumentException - if the timeout is malformed
    • updateHeaders

      public static void updateHeaders(WritableHeaders<?> headers, io.grpc.Metadata metadata)
      Updates headers with metadata.
      Parameters:
      headers - the headers to update
      metadata - the metadata
    • toMetadata

      public static io.grpc.Metadata toMetadata(Http2Headers headers)
      Converts a set of HTTP/2 headers into a Metadata instance.
      Parameters:
      headers - the headers to convert
      Returns:
      the new metadata