Class GrpcFrames
java.lang.Object
com.codename1.backend.grpc.GrpcFrames
The gRPC length-prefixed message framing: every message on a gRPC stream is one byte of flags (bit 0 set when the message is compressed), a four-byte big-endian length, and that many bytes of payload.
HTTP/2 DATA frames and gRPC messages are unrelated: one DATA frame may hold
several messages, and one message may span many DATA frames. GrpcFrames.Decoder is
fed whatever arrived and hands back the messages that are complete, which is
the only correct way to read a stream.
Rules a decoder must keep, and why:
- The length is checked against a ceiling before anything is allocated. Four bytes from the peer would otherwise be a 2 GB allocation on demand.
- A compressed flag with no negotiated encoding is a protocol error
(
INTERNAL), never a guess at the codec. - Any flag bit other than bit 0 is reserved; a set one is an error too.
- A gzip message is bounded by the same ceiling after inflation, or a small message becomes a decompression bomb.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classReassembles messages from bytes as they arrive. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default largest message accepted, as in grpc-java and grpc-go: 4 MB.static final intThe prefix in front of every message. -
Method Summary
-
Field Details
-
PREFIX_LENGTH
public static final int PREFIX_LENGTHThe prefix in front of every message.- See Also:
-
DEFAULT_MAX_MESSAGE
public static final int DEFAULT_MAX_MESSAGEThe default largest message accepted, as in grpc-java and grpc-go: 4 MB.- See Also:
-
-
Method Details
-
frame
public static byte[] frame(byte[] message) Frames one message, uncompressed.- Parameters:
message- the serialized message- Returns:
- prefix and payload
-
frame
public static byte[] frame(byte[] message, boolean gzip) Frames one message, gzip-compressed when asked.- Parameters:
message- the serialized messagegzip- whether to compress it (only when the peer accepts gzip)- Returns:
- prefix and payload
-