NIOSingleStepByteToMessageDecoder
public protocol NIOSingleStepByteToMessageDecoder : ByteToMessageDecoder
A simplified version of ByteToMessageDecoder
that can generate zero or one messages for each invocation of decode
or decodeLast
.
Having decode
and decodeLast
return an optional message avoids re-entrancy problems, since the functions relinquish exclusive access
to the ByteBuffer
when returning. This allows for greatly simplified processing.
Many ByteToMessageDecoder
‘s can trivially be translated to NIOSingleStepByteToMessageDecoder
’s. You should not implement
ByteToMessageDecoder
’s decodeand
decodeLast` methods.
-
The decoded type this
NIOSingleStepByteToMessageDecoder
decodes to. To conform toByteToMessageDecoder
it must be calledInboundOut
- see https://bugs.swift.org/browse/SR-11868.Declaration
Swift
associatedtype InboundOut
-
Decode from a
ByteBuffer
.This method will be called in a loop until either the input
ByteBuffer
has nothing to read left ornil
is returned. If non-nil
is returned and theByteBuffer
contains more readable bytes, this method will immediately be invoked again, unlessdecodeLast
needs to be invoked instead.Declaration
Swift
mutating func decode(buffer: inout ByteBuffer) throws -> InboundOut?
Parameters
buffer
The
ByteBuffer
from which we decode.Return Value
A message if one can be decoded or
nil
if it should be called again once more data is present in theByteBuffer
. -
Decode from a
ByteBuffer
when no more data is incoming.Like with
decode
, this method will be called in a loop until eithernil
is returned from the method or until the inputByteBuffer
has no more readable bytes. If non-nil
is returned and theByteBuffer
contains more readable bytes, this method will immediately be invoked again.Once
nil
is returned, neitherdecode
nordecodeLast
will be called again. If there are no bytes left,decodeLast
will be called once with an empty buffer.Declaration
Swift
mutating func decodeLast(buffer: inout ByteBuffer, seenEOF: Bool) throws -> InboundOut?
Parameters
buffer
The
ByteBuffer
from which we decode.seenEOF
true
if EOF has been seen.Return Value
A message if one can be decoded or
nil
if no more messages can be produced.
-
decode(context:
Extension methodbuffer: ) Declaration
Swift
public mutating func decode(context: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState
-
decodeLast(context:
Extension methodbuffer: seenEOF: ) Declaration
Swift
public mutating func decodeLast(context: ChannelHandlerContext, buffer: inout ByteBuffer, seenEOF: Bool) throws -> DecodingState