human
Complete this python program:
def BoolEncoder(field_number, is_repeated, is_packed):
assistant
#Here is the Python code you requested.

    """Returns an encoder for a boolean field.
    """
    false_byte = chr(0)
    true_byte = chr(1)
    if is_packed:
        tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
        local_EncodeVarint = _EncodeVarint
        def EncodePackedField(write, value):
            write(tag_bytes)
            local_EncodeVarint(write, len(value))
            for element in value:
                if element:
                    write(true_byte)
                else:
                    write(false_byte)
        return EncodePackedField
    elif is_repeated:
        tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
        def EncodeRepeatedField(write, value):
            for element in value:
                write(tag_bytes)
                if element:
                    write(true_byte)
                else:
                    write(false_byte)
        return EncodeRepeatedField
    else:
        tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
        def EncodeField(write, value):
            write(tag_bytes)
            if value:
                return write(true_byte)
            return write(false_byte)
        return EncodeField