code: func dnsBinaryTruncate(resp *dns.Msg, maxSize int, index map[string]dns.RR, hasExtra bool) int {
  	originalAnswser := resp.Answer
  	startIndex := 0
  	endIndex := len(resp.Answer) + 1
  	for endIndex-startIndex > 1 {
  		median := startIndex + (endIndex-startIndex)/2
  
  		resp.Answer = originalAnswser[:median]
  		if hasExtra {
  			syncExtra(index, resp)
  		}
  		aLen := resp.Len()
  		if aLen <= maxSize {
  			if maxSize-aLen < 10 {
  				// We are good, increasing will go out of bounds
  				return median
  			}
  			startIndex = median
  		} else {
  			endIndex = median
  		}
  	}
  	return startIndex
  }
docs: // dnsBinaryTruncate find the optimal number of records using a fast binary search and return
  // it in order to return a DNS answer lower than maxSize parameter.