Module jls.util.Codec
Represents an encoder/decoder for string or stream.
Available codecs are base64
, deflate
, gzip
, hex
.
Class Codec
codec:decode (value) | Decodes the specified string. |
codec:encode (value) | Encodes the specified string. |
codec:decodeStream (sh) | Returns a decoding jls.io.StreamHandler. |
codec:encodeStream (sh) | Returns a encoding jls.io.StreamHandler. |
codec:getName () | Returns the name of the codec. |
Codec.getCodec (name) | Returns the Codec class corresponding to the specified name. |
Codec.getInstance (name) | Returns a new Codec. |
Class Codec
The Codec class.
The Codec decodes or encodes a string or a stream.
- codec:decode (value)
-
Decodes the specified string.
Parameters:
- value string the data to decode
Returns:
-
string
the decoded string
Raises:
codec dependent message in case of decoding failure - codec:encode (value)
-
Encodes the specified string.
Parameters:
- value string the data to encode
Returns:
-
string
the encoded string
Raises:
codec dependent message in case of encoding failure - codec:decodeStream (sh)
-
Returns a decoding jls.io.StreamHandler.
The default implentation consists in using the decode method.
Parameters:
- sh StreamHandler the wrapped stream that will handle the decoded data
Returns:
-
StreamHandler
the stream handler that will decode data
- codec:encodeStream (sh)
-
Returns a encoding jls.io.StreamHandler.
The default implentation consists in using the encode method.
Parameters:
- sh StreamHandler the wrapped stream that will handle the encoded data
Returns:
-
StreamHandler
the stream handler that will encode data
- codec:getName ()
-
Returns the name of the codec.
Returns:
-
string
the name of the codec
- Codec.getCodec (name)
-
Returns the Codec class corresponding to the specified name.
Parameters:
- name string The name of the codec
Returns:
-
The Codec class
- Codec.getInstance (name)
-
Returns a new Codec.
Parameters:
- name string The name of the codec
Returns:
-
Codec
a new Codec
Usage:
local codec = Codec.getInstance('Base64') codec:encode('Hello !')