Interface CodecService

    • Method Detail

      • forType

        <T> EncoderDecoder<T> forType​(Class<T> type,
                                      EncodeFunction<T> encode,
                                      DecodeFunction<T> decode)
        Returns encoder/decoder for the specified type and encoding/decoding functions.
        Type Parameters:
        T - Data type.
        Parameters:
        type - Data type.
        encode - Encode function.
        decode - Decode function.
        Returns:
        Encoder/decoder.
      • forFactory

        <T> EncoderDecoder<T> forFactory​(CodecFactory<T> codecFactory)
        Returns encoder/decoder for the codec factory.
        Type Parameters:
        T - Data type.
        Parameters:
        codecFactory - Codec factory.
        Returns:
        Encoder/decoder for the specified factory.
      • encode

        <T> byte[] encode​(T obj,
                          EncodeFunction<T> encoder)
                   throws CodecException
        Encodes the specified object via the specified function and returns a byte array of encoded data.
        Type Parameters:
        T - Object type.
        Parameters:
        obj - Object to encode (can be null, in such case the encoder function's parameter will be null too).
        encoder - Encoder function.
        Returns:
        Byte array of encoded data.
        Throws:
        CodecException - If object couldn't be decoded.
        See Also:
        decode(byte[], DecodeFunction)
      • decode

        <T> T decode​(byte[] bytes,
                     DecodeFunction<T> decoder)
              throws CodecException
        Decodes an object from the specified byte array by using the supplied decode function.
        Type Parameters:
        T - Decoded object type.
        Parameters:
        bytes - Bytes.
        decoder - Decode function.
        Returns:
        Decoded object.
        Throws:
        CodecException - If object couldn't be decoded.
        See Also:
        encode(Object, EncodeFunction)
      • decode

        Object decode​(byte[] bytes,
                      int offset,
                      int limit)
               throws CodecException
        Decodes an object from the specified array of bytes.
        Parameters:
        bytes - Bytes.
        offset - Offset of the first byte to read.
        limit - Maximum number of bytes to read.
        Returns:
        Decoded object.
        Throws:
        CodecException - Signals decoding failure.
      • decode

        Object decode​(byte[] bytes)
               throws CodecException
        Decodes an object from the specified array of bytes.
        Parameters:
        bytes - Bytes.
        Returns:
        Decoded object.
        Throws:
        CodecException - Signals decoding failure.
        See Also:
        encode(Object)
      • decode

        <T> T decode​(byte[] bytes,
                     int offset,
                     int limit,
                     DecodeFunction<T> decoder)
              throws CodecException
        Decodes an object from the specified byte array by using the supplied decode function.
        Type Parameters:
        T - Decoded object type.
        Parameters:
        bytes - Bytes.
        offset - Offset to
        limit - Maximum number of bytes to read.
        decoder - Decode function.
        Returns:
        Decoded object.
        Throws:
        CodecException - If object couldn't be decoded.