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 decodeanddecodeLast` methods.

  • The decoded type this NIOSingleStepByteToMessageDecoder decodes to. To conform to ByteToMessageDecoder it must be called InboundOut - 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 or nil is returned. If non-nil is returned and the ByteBuffer contains more readable bytes, this method will immediately be invoked again, unless decodeLast 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 the ByteBuffer.

  • Decode from a ByteBuffer when no more data is incoming.

    Like with decode, this method will be called in a loop until either nil is returned from the method or until the input ByteBuffer has no more readable bytes. If non-nil is returned and the ByteBuffer contains more readable bytes, this method will immediately be invoked again.

    Once nil is returned, neither decode nor decodeLast 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.

NIOSingleStepByteToMessageDecoder: ByteToMessageDecoder