# `Utf8Codec`

digraph inheritance5d4ab9e32c { bgcolor=transparent; rankdir=UD; ratio=compress; size="8.0, 12.0"; "Codec" [URL="taurus.core.util.codecs-Codec.html#taurus.core.util.codecs.Codec",color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,target="_top",tooltip="The base class for all codecs"]; "Logger" -> "Codec" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Logger" [URL="taurus-Logger.html#taurus.Logger",color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,target="_top",tooltip="The taurus logger class. All taurus pertinent classes should inherit"]; "Utf8Codec" [URL="#taurus.core.util.codecs.Utf8Codec",color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,target="_top",tooltip="A codec able to encode/decode utf8 strings to/from bytes."]; "Codec" -> "Utf8Codec" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

class Utf8Codec

  A codec able to encode/decode utf8 strings to/from bytes. Useful to adapt i/o encodings in a codec pipe.

  Example:

      >>> from taurus.core.util.codecs import CodecFactory

      >>> cf = CodecFactory()
      >>> codec = cf.getCodec('zip_utf8_json')
      >>>
      >>> # first encode something
      >>> data = { 'hello' : 'world', 'goodbye' : 1000 }
      >>> format, encoded_data = codec.encode(("", data))
      >>>
      >>> # now decode it
      >>> _, decoded_data = codec.decode((format, encoded_data))
      >>> print(decoded_data)

  Import from `taurus.core.util.codecs` as:

      from taurus.core.util.codecs import Utf8Codec

  decode(data, *args, **kwargs)

    decodes the given data from a bytes.

    Parameters:

      data (sequence[str, obj]) – a sequence of two elements where the first item is the encoding format of the second item object

    Returns:

      a sequence of two elements where the first item is the encoding format of the second item object

    Return type:

      sequence[str, obj]

  encode(data, *args, **kwargs)

    Encodes the given utf8 string to bytes.

    Parameters:

      data (sequence[str, obj]) – a sequence of two elements where the first item is the encoding format of the second item object

    Returns:

      a sequence of two elements where the first item is the encoding format of the second item object

    Return type:

      sequence[str, obj]