Class Framing$
- java.lang.Object
-
- akka.stream.javadsl.Framing$
-
public class Framing$ extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Framing$()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Flow<ByteString,ByteString,NotUsed>
delimiter(ByteString delimiter, int maximumFrameLength)
Creates a Flow that handles decoding a stream of unstructured byte chunks into a stream of frames where the incoming chunk stream uses a specific byte-sequence to mark frame boundaries.Flow<ByteString,ByteString,NotUsed>
delimiter(ByteString delimiter, int maximumFrameLength, FramingTruncation allowTruncation)
Creates a Flow that handles decoding a stream of unstructured byte chunks into a stream of frames where the incoming chunk stream uses a specific byte-sequence to mark frame boundaries.Flow<ByteString,ByteString,NotUsed>
lengthField(int fieldLength, int fieldOffset, int maximumFrameLength)
Creates a Flow that decodes an incoming stream of unstructured byte chunks into a stream of frames, assuming that incoming frames have a field that encodes their length.Flow<ByteString,ByteString,NotUsed>
lengthField(int fieldLength, int fieldOffset, int maximumFrameLength, java.nio.ByteOrder byteOrder)
Creates a Flow that decodes an incoming stream of unstructured byte chunks into a stream of frames, assuming that incoming frames have a field that encodes their length.Flow<ByteString,ByteString,NotUsed>
lengthField(int fieldLength, int fieldOffset, int maximumFrameLength, java.nio.ByteOrder byteOrder, Function2<byte[],java.lang.Integer,java.lang.Integer> computeFrameSize)
Creates a Flow that decodes an incoming stream of unstructured byte chunks into a stream of frames, assuming that incoming frames have a field that encodes their length.BidiFlow<ByteString,ByteString,ByteString,ByteString,NotUsed>
simpleFramingProtocol(int maximumMessageLength)
Returns a BidiFlow that implements a simple framing protocol.
-
-
-
Field Detail
-
MODULE$
public static final Framing$ MODULE$
Static reference to the singleton instance of this Scala object.
-
-
Method Detail
-
delimiter
public Flow<ByteString,ByteString,NotUsed> delimiter(ByteString delimiter, int maximumFrameLength)
Creates a Flow that handles decoding a stream of unstructured byte chunks into a stream of frames where the incoming chunk stream uses a specific byte-sequence to mark frame boundaries.The decoded frames will not include the separator sequence.
If there are buffered bytes (an incomplete frame) when the input stream finishes and ''allowTruncation'' is set to false then this Flow will fail the stream reporting a truncated frame.
Default truncation behavior is: when the last frame being decoded contains no valid delimiter this Flow fails the stream instead of returning a truncated frame.
- Parameters:
delimiter
- The byte sequence to be treated as the end of the frame.maximumFrameLength
- The maximum length of allowed frames while decoding. If the maximum length is exceeded this Flow will fail the stream.
-
delimiter
public Flow<ByteString,ByteString,NotUsed> delimiter(ByteString delimiter, int maximumFrameLength, FramingTruncation allowTruncation)
Creates a Flow that handles decoding a stream of unstructured byte chunks into a stream of frames where the incoming chunk stream uses a specific byte-sequence to mark frame boundaries.The decoded frames will not include the separator sequence.
If there are buffered bytes (an incomplete frame) when the input stream finishes and ''allowTruncation'' is set to false then this Flow will fail the stream reporting a truncated frame.
- Parameters:
delimiter
- The byte sequence to be treated as the end of the frame.allowTruncation
- If set toDISALLOW
, then when the last frame being decoded contains no valid delimiter this Flow fails the stream instead of returning a truncated frame.maximumFrameLength
- The maximum length of allowed frames while decoding. If the maximum length is exceeded this Flow will fail the stream.
-
lengthField
public Flow<ByteString,ByteString,NotUsed> lengthField(int fieldLength, int fieldOffset, int maximumFrameLength)
Creates a Flow that decodes an incoming stream of unstructured byte chunks into a stream of frames, assuming that incoming frames have a field that encodes their length.If the input stream finishes before the last frame has been fully decoded, this Flow will fail the stream reporting a truncated frame.
The byte order used for when decoding the field defaults to little-endian.
- Parameters:
fieldLength
- The length of the "size" field in bytesfieldOffset
- The offset of the field from the beginning of the frame in bytesmaximumFrameLength
- The maximum length of allowed frames while decoding. If the maximum length is exceeded this Flow will fail the stream. This length *includes* the header (i.e the offset and the length of the size field)
-
lengthField
public Flow<ByteString,ByteString,NotUsed> lengthField(int fieldLength, int fieldOffset, int maximumFrameLength, java.nio.ByteOrder byteOrder)
Creates a Flow that decodes an incoming stream of unstructured byte chunks into a stream of frames, assuming that incoming frames have a field that encodes their length.If the input stream finishes before the last frame has been fully decoded, this Flow will fail the stream reporting a truncated frame.
- Parameters:
fieldLength
- The length of the "size" field in bytesfieldOffset
- The offset of the field from the beginning of the frame in bytesmaximumFrameLength
- The maximum length of allowed frames while decoding. If the maximum length is exceeded this Flow will fail the stream. This length *includes* the header (i.e the offset and the length of the size field)byteOrder
- The ''ByteOrder'' to be used when decoding the field
-
lengthField
public Flow<ByteString,ByteString,NotUsed> lengthField(int fieldLength, int fieldOffset, int maximumFrameLength, java.nio.ByteOrder byteOrder, Function2<byte[],java.lang.Integer,java.lang.Integer> computeFrameSize)
Creates a Flow that decodes an incoming stream of unstructured byte chunks into a stream of frames, assuming that incoming frames have a field that encodes their length.If the input stream finishes before the last frame has been fully decoded, this Flow will fail the stream reporting a truncated frame.
- Parameters:
fieldLength
- The length of the "size" field in bytesfieldOffset
- The offset of the field from the beginning of the frame in bytesmaximumFrameLength
- The maximum length of allowed frames while decoding. If the maximum length is exceeded this Flow will fail the stream. This length *includes* the header (i.e the offset and the length of the size field)byteOrder
- The ''ByteOrder'' to be used when decoding the fieldcomputeFrameSize
- This function can be supplied if frame size is varied or needs to be computed in a special fashion. For example, frame can have a shape like this:[offset bytes][body size bytes][body bytes][footer bytes]
. Then computeFrameSize can be used to compute the frame size:(offset bytes, computed size) => (actual frame size)
. ''Actual frame size'' must be equal or bigger than sum offieldOffset
andfieldLength
, the operator fails otherwise.
-
simpleFramingProtocol
public BidiFlow<ByteString,ByteString,ByteString,ByteString,NotUsed> simpleFramingProtocol(int maximumMessageLength)
Returns a BidiFlow that implements a simple framing protocol. This is a convenience wrapper overFraming.lengthField(int, int, int)
and simply attaches a length field header of four bytes (using big endian encoding) to outgoing messages, and decodes such messages in the inbound direction. The decoded messages do not contain the header.
This BidiFlow is useful if a simple message framing protocol is needed (for example when TCP is used to send individual messages) but no compatibility with existing protocols is necessary.+--------------------------------+ | Framing BidiFlow | | | | +--------------------------+ | in2 ~~> | Decoding | ~~> out2 | +--------------------------+ | | | | +--------------------------+ | out1 <~~ |Encoding(Add length field)| <~~ in1 | +--------------------------+ | +--------------------------------+
The encoded frames have the layout
The length field encodes the length of the user payload excluding the header itself.[4 bytes length field, Big Endian][User Payload]
- Parameters:
maximumMessageLength
- Maximum length of allowed messages. If sent or received messages exceed the configured limit this BidiFlow will fail the stream. The header attached by this BidiFlow are not included in this limit.
-
-