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 classProduce a collection ofWritableBufferinstances from the data written to anOutputStream.private classOutputStream whose write()s are passed to the framer.static interfaceSink implemented by the transport layer to receive frames and forward them to their destination. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate WritableBufferprivate final WritableBufferAllocatorprivate booleanprivate static final byteprivate Compressorprivate intprivate longprivate static final intprivate final ByteBufferprivate intprivate booleanprivate intprivate static final intprivate final MessageFramer.OutputStreamAdapterprivate final MessageFramer.Sinkprivate final StatsTraceContextprivate static final byte -
Constructor Summary
ConstructorsConstructorDescriptionMessageFramer(MessageFramer.Sink sink, WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx) Creates aMessageFramer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Flushes and closes the framer and releases any buffers.private voidcommitToSink(boolean endOfStream, boolean flush) voiddispose()Closes the framer and releases any buffers, but does not flush.voidflush()Flushes any buffered data in the framer to the sink.private intgetKnownLength(InputStream inputStream) booleanisClosed()private voidsetCompressor(Compressor compressor) Set the compressor used for compression.voidsetMaxOutboundMessageSize(int maxSize) Set a size limit for each outbound message.setMessageCompression(boolean enable) Enable or disable compression.private voidprivate voidwriteBufferChain(MessageFramer.BufferChainOutputStream bufferChain, boolean compressed) Write a message that has been serialized to a sequence of buffers.private intwriteCompressed(InputStream message, int unusedMessageLength) private intwriteKnownLengthUncompressed(InputStream message, int messageLength) Write an unserialized message with a known length, uncompressed.voidwritePayload(InputStream message) Writes out a payload message.private voidwriteRaw(byte[] b, int off, int len) private static intwriteToOutputStream(InputStream message, OutputStream outputStream) private intwriteUncompressed(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:FramerSet the compressor used for compression.- Specified by:
setCompressorin interfaceFramer
-
setMessageCompression
Description copied from interface:FramerEnable or disable compression.- Specified by:
setMessageCompressionin interfaceFramer
-
setMaxOutboundMessageSize
public void setMaxOutboundMessageSize(int maxSize) Description copied from interface:FramerSet a size limit for each outbound message.- Specified by:
setMaxOutboundMessageSizein interfaceFramer
-
writePayload
Writes out a payload message.- Specified by:
writePayloadin 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()
-