def object_to_bytes(obj):
if isinstance(obj, str):<EOL><INDENT>return bytearray(obj, "<STR_LIT>")<EOL><DEDENT>elif isinstance(obj, bool):<EOL><INDENT>return bytearray()<EOL><DEDENT>elif isinstance(obj, int):<EOL><INDENT>return pack("<STR_LIT>", obj)<EOL><DEDENT>elif obj == None:<EOL><INDENT>return bytearray()<EOL><DEDENT>elif isinstance(obj, bytearray):<EOL><INDENT>return obj<EOL><DEDENT>else:<EOL><INDENT>return obj.get_raw()<EOL><DEDENT>
Convert a object to a bytearray or call get_raw() of the object
if no useful type was found.