def serialize(data, measurement=None, tag_columns=None, **extra_tags):
if isinstance(data, bytes):<EOL><INDENT>return data<EOL><DEDENT>elif isinstance(data, str):<EOL><INDENT>return data.encode('<STR_LIT:utf-8>')<EOL><DEDENT>elif hasattr(data, '<STR_LIT>'):<EOL><INDENT>return data.to_lineprotocol()<EOL><DEDENT>elif pd is not None and isinstance(data, pd.DataFrame):<EOL><INDENT>return dataframe.serialize(data, measurement, tag_columns, **extra_tags)<EOL><DEDENT>elif isinstance(data, dict):<EOL><INDENT>return mapping.serialize(data, measurement, **extra_tags)<EOL><DEDENT>elif hasattr(data, '<STR_LIT>'):<EOL><INDENT>return b'<STR_LIT:\n>'.join([serialize(i, measurement, tag_columns, **extra_tags) for i in data])<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>', data)<EOL><DEDENT>
Converts input data into line protocol format