code: def BoolEncoder(field_number, is_repeated, is_packed):
      """Returns an encoder for a boolean field."""
  
      false_byte = b"\x00"
      true_byte = b"\x01"
      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
  
imports: import struct
  import six
  from google.protobuf.internal import wire_format
label_desc: Use image node_id 21 for calling a global function with example usage: BoolEncoder(field_number, is_repeated, is_packed) and returns: EncodePackedField, EncodeRepeatedField, EncodeField, write, write