Class GrpcStreamMessageEncoder

java.lang.Object
org.mockserver.grpc.GrpcStreamMessageEncoder

public final class GrpcStreamMessageEncoder extends Object
Transport-neutral helper that encodes a single gRPC stream message (JSON) into a gRPC length-prefixed frame, ready to be written as an HTTP/2 DATA frame or an HTTP/3 DATA frame.

Shared by the HTTP/2 server-streaming handler (GrpcStreamResponseActionHandler) and the HTTP/3 server-streaming writer so the encoding semantics are identical across transports:

  • empty / null JSON -> an empty gRPC frame (5-byte header, zero-length payload);
  • JSON with a resolvable method descriptor -> protobuf-encoded then gRPC-framed;
  • JSON without a descriptor -> the raw UTF-8 bytes gRPC-framed (best-effort passthrough so raw expectations still produce a valid gRPC frame).
  • Method Details

    • encode

      public static byte[] encode(String json, com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor, GrpcJsonMessageConverter converter)
      Encode the given message JSON to a gRPC length-prefixed frame.
      Parameters:
      json - the message JSON (may be null/empty)
      methodDescriptor - the resolved gRPC method descriptor (may be null)
      converter - the JSON/protobuf converter (may be null)
      Returns:
      the gRPC-framed bytes
    • encode

      public static byte[] encode(String json, com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor, GrpcProtoDescriptorStore descriptorStore)
      Encode the given message JSON to a gRPC length-prefixed frame, resolving the converter from the descriptor store.
    • encode

      public static byte[] encode(GrpcStreamMessage message, com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor, GrpcProtoDescriptorStore descriptorStore)
      Encode a GrpcStreamMessage to a gRPC length-prefixed frame.