Package io.grpc.internal
Class MessageFramer
java.lang.Object
io.grpc.internal.MessageFramer
- All Implemented Interfaces:
Framer
Encodes gRPC messages to be delivered via the transport layer which implements
MessageFramer.Sink
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
Produce a collection ofWritableBuffer
instances from the data written to anOutputStream
.private class
OutputStream whose write()s are passed to the framer.static interface
Sink implemented by the transport layer to receive frames and forward them to their destination. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate WritableBuffer
private final WritableBufferAllocator
private boolean
private static final byte
private Compressor
private int
private long
private static final int
private final ByteBuffer
private int
private boolean
private int
private static final int
private final MessageFramer.OutputStreamAdapter
private final MessageFramer.Sink
private final StatsTraceContext
private static final byte
-
Constructor Summary
ConstructorsConstructorDescriptionMessageFramer
(MessageFramer.Sink sink, WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx) Creates aMessageFramer
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Flushes and closes the framer and releases any buffers.private void
commitToSink
(boolean endOfStream, boolean flush) void
dispose()
Closes the framer and releases any buffers, but does not flush.void
flush()
Flushes any buffered data in the framer to the sink.private int
getKnownLength
(InputStream inputStream) boolean
isClosed()
private void
setCompressor
(Compressor compressor) Set the compressor used for compression.void
setMaxOutboundMessageSize
(int maxSize) Set a size limit for each outbound message.setMessageCompression
(boolean enable) Enable or disable compression.private void
private void
writeBufferChain
(MessageFramer.BufferChainOutputStream bufferChain, boolean compressed) Write a message that has been serialized to a sequence of buffers.private int
writeCompressed
(InputStream message, int unusedMessageLength) private int
writeKnownLengthUncompressed
(InputStream message, int messageLength) Write an unserialized message with a known length, uncompressed.void
writePayload
(InputStream message) Writes out a payload message.private void
writeRaw
(byte[] b, int off, int len) private static int
writeToOutputStream
(InputStream message, OutputStream outputStream) private int
writeUncompressed
(InputStream message, int messageLength)
-
Field Details
-
NO_MAX_OUTBOUND_MESSAGE_SIZE
private static final int NO_MAX_OUTBOUND_MESSAGE_SIZE- See Also:
-
HEADER_LENGTH
private static final int HEADER_LENGTH- See Also:
-
UNCOMPRESSED
private static final byte UNCOMPRESSED- See Also:
-
COMPRESSED
private static final byte COMPRESSED- See Also:
-
sink
-
maxOutboundMessageSize
private int maxOutboundMessageSize -
buffer
-
compressor
-
messageCompression
private boolean messageCompression -
outputStreamAdapter
-
headerScratch
-
bufferAllocator
-
statsTraceCtx
-
closed
private boolean closed -
messagesBuffered
private int messagesBuffered -
currentMessageSeqNo
private int currentMessageSeqNo -
currentMessageWireSize
private long currentMessageWireSize
-
-
Constructor Details
-
MessageFramer
public MessageFramer(MessageFramer.Sink sink, WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx) Creates aMessageFramer
.- Parameters:
sink
- the sink used to deliver frames to the transportbufferAllocator
- allocates buffers that the transport can commit to the wire.
-
-
Method Details
-
setCompressor
Description copied from interface:Framer
Set the compressor used for compression.- Specified by:
setCompressor
in interfaceFramer
-
setMessageCompression
Description copied from interface:Framer
Enable or disable compression.- Specified by:
setMessageCompression
in interfaceFramer
-
setMaxOutboundMessageSize
public void setMaxOutboundMessageSize(int maxSize) Description copied from interface:Framer
Set a size limit for each outbound message.- Specified by:
setMaxOutboundMessageSize
in interfaceFramer
-
writePayload
Writes out a payload message.- Specified by:
writePayload
in interfaceFramer
- Parameters:
message
- contains the message to be written out. It will be completely consumed.
-
writeUncompressed
- Throws:
IOException
-
writeCompressed
- Throws:
IOException
-
getKnownLength
- Throws:
IOException
-
writeKnownLengthUncompressed
Write an unserialized message with a known length, uncompressed.- Throws:
IOException
-
writeBufferChain
private void writeBufferChain(MessageFramer.BufferChainOutputStream bufferChain, boolean compressed) Write a message that has been serialized to a sequence of buffers. -
writeToOutputStream
private static int writeToOutputStream(InputStream message, OutputStream outputStream) throws IOException - Throws:
IOException
-
writeRaw
private void writeRaw(byte[] b, int off, int len) -
flush
public void flush()Flushes any buffered data in the framer to the sink. -
isClosed
public boolean isClosed() -
close
public void close()Flushes and closes the framer and releases any buffers. After the framer is closed or disposed, additional calls to this method will have no affect. -
dispose
public void dispose()Closes the framer and releases any buffers, but does not flush. After the framer is closed or disposed, additional calls to this method will have no affect. -
releaseBuffer
private void releaseBuffer() -
commitToSink
private void commitToSink(boolean endOfStream, boolean flush) -
verifyNotClosed
private void verifyNotClosed()
-