LengthFieldPrepender

public final class LengthFieldPrepender : ChannelOutboundHandler

An encoder that takes a ByteBuffer message and prepends the number of bytes in the message. The length field is always the same fixed length specified on construction. These bytes contain a binary specification of the message size.

For example, if you received a packet with the 3 byte length (BCD)… Given that the specified header length is 1 byte, there would be a single byte prepended which contains the number 3 +—+—–+ | A | BCD | (‘A’ contains 0x03) +—+—–+ This initial prepended byte is called the ‘length field’.

  • An enumeration to describe the length of a piece of data in bytes. It is constrained to lengths that can be converted to integer types.

    See more

    Declaration

    Swift

    public enum ByteLength
  • Declaration

    Swift

    public typealias OutboundIn = ByteBuffer
  • Declaration

    Swift

    public typealias OutboundOut = ByteBuffer
  • Create LengthFieldPrepender with a given length field length.

    Declaration

    Swift

    public init(lengthFieldLength: ByteLength, lengthFieldEndianness: Endianness = .big)

    Parameters

    lengthFieldLength

    The length of the field specifying the remaining length of the frame.

    lengthFieldEndianness

    The endianness of the field specifying the remaining length of the frame.

  • Declaration

    Swift

    public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?)