def encode(term, compressed=False):
encoded_term = encode_term(term)<EOL>if compressed:<EOL><INDENT>if compressed is True:<EOL><INDENT>compressed = <NUM_LIT:6><EOL><DEDENT>elif compressed < <NUM_LIT:0> or compressed > <NUM_LIT:9>:<EOL><INDENT>raise ValueError("<STR_LIT>" % (compressed,))<EOL><DEDENT>zlib_term = compress(encoded_term, compressed)<EOL>ln = len(encoded_term)<EOL>if len(zlib_term) + <NUM_LIT:5> <= ln:<EOL><INDENT>return b"<STR_LIT>" + _int4_pack(ln) + zlib_term<EOL><DEDENT><DEDENT>return b"<STR_LIT>" + encoded_term<EOL>
Encode Erlang external term.