Class PrefixedStringCodecFactory

    • Constructor Detail

      • PrefixedStringCodecFactory

        public PrefixedStringCodecFactory​(java.nio.charset.Charset charset)
        Creates a new PrefixedStringCodecFactory instance
        Parameters:
        charset - The Charset to use for encoding or decoding
      • PrefixedStringCodecFactory

        public PrefixedStringCodecFactory()
        Creates a new PrefixedStringCodecFactory instance
    • Method Detail

      • setEncoderMaxDataLength

        public void setEncoderMaxDataLength​(int maxDataLength)
        Sets the allowed maximum size of an encoded String. If the size of the encoded String exceeds this value, the encoder will throw a IllegalArgumentException. The default value is PrefixedStringEncoder.DEFAULT_MAX_DATA_LENGTH.

        This method does the same job as PrefixedStringEncoder.getMaxDataLength().

        Parameters:
        maxDataLength - allowed maximum size of an encoded String.
      • setDecoderMaxDataLength

        public void setDecoderMaxDataLength​(int maxDataLength)
        Sets the maximum allowed value specified as data length in the decoded data

        Useful for preventing an OutOfMemory attack by the peer. The decoder will throw a BufferDataException when data length specified in the incoming data is greater than maxDataLength The default value is PrefixedStringDecoder.DEFAULT_MAX_DATA_LENGTH.

        This method does the same job as PrefixedStringDecoder.setMaxDataLength(int).

        Parameters:
        maxDataLength - maximum allowed value specified as data length in the incoming data
      • setDecoderPrefixLength

        public void setDecoderPrefixLength​(int prefixLength)
        Sets the length of the prefix used by the decoder
        Parameters:
        prefixLength - the length of the length prefix (1, 2, or 4)
      • getDecoderPrefixLength

        public int getDecoderPrefixLength()
        Gets the length of the length prefix (1, 2, or 4) used by the decoder
        Returns:
        length of the length prefix
      • setEncoderPrefixLength

        public void setEncoderPrefixLength​(int prefixLength)
        Sets the length of the prefix used by the encoder
        Parameters:
        prefixLength - the length of the length prefix (1, 2, or 4)
      • getEncoderPrefixLength

        public int getEncoderPrefixLength()
        Gets the length of the length prefix (1, 2, or 4) used by the encoder
        Returns:
        length of the length prefix
      • getEncoder

        public ProtocolEncoder getEncoder​(IoSession session)
                                   throws java.lang.Exception
        Returns a new (or reusable) instance of ProtocolEncoder which encodes message objects into binary or protocol-specific data.
        Specified by:
        getEncoder in interface ProtocolCodecFactory
        Parameters:
        session - The current session
        Returns:
        The encoder instance
        Throws:
        java.lang.Exception - If an error occurred while retrieving the encoder
      • getDecoder

        public ProtocolDecoder getDecoder​(IoSession session)
                                   throws java.lang.Exception
        Returns a new (or reusable) instance of ProtocolDecoder which decodes binary or protocol-specific data into message objects.
        Specified by:
        getDecoder in interface ProtocolCodecFactory
        Parameters:
        session - The current session
        Returns:
        The decoder instance
        Throws:
        java.lang.Exception - If an error occurred while retrieving the decoder