docs: def write_segment(buff, segment, ver, ver_range, eci=False):
      """\
      Writes a segment.
  
      :param buff: The byte buffer.
      :param _Segment segment: The segment to serialize.
      :param ver: ``None`` if a QR Code is written, "M1", "M2", "M3", or "M4" if a
              Micro QR Code is written.
      :param ver_range: "M1", "M2", "M3", or "M4" if a Micro QR Code is written,
              otherwise a constant representing a range of QR Code versions.
      """
      mode = segment.mode
      append_bits = buff.append_bits
      # Write ECI header if requested
      if eci and mode == consts.MODE_BYTE \
              and segment.encoding != consts.DEFAULT_BYTE_ENCODING:
          append_bits(consts.MODE_ECI, 4)
          append_bits(get_eci_assignment_number(segment.encoding), 8)
      if ver is None:  # QR Code
          append_bits(mode, 4)
      elif ver > consts.VERSION_M1:  # Micro QR Code (M1 has no mode indicator)
          append_bits(consts.MODE_TO_MICRO_MODE_MAPPING[mode], ver + 3)
      # Character count indicator
      append_bits(segment.char_count,
                  consts.CHAR_COUNT_INDICATOR_LENGTH[mode][ver_range])
      buff.extend(segment.bits)