func()

in model/marshal.go [238:297]


func (v *URL) marshalFullURL(w *fastjson.Writer, scheme []byte) bool {
	w.RawByte('"')
	before := w.Size()
	w.RawBytes(scheme)
	w.RawString("://")

	const maxRunes = 1024
	runes := w.Size() - before // scheme is known to be all single-byte runes
	if runes >= maxRunes {
		// Pathological case, scheme >= 1024 runes.
		w.Rewind(before + maxRunes)
		w.RawByte('"')
		return true
	}

	// Track how many runes we encode, and stop once we've hit the limit.
	rawByte := func(v byte) {
		if runes == maxRunes {
			return
		}
		w.RawByte(v)
		runes++
	}
	stringContents := func(v string) {
		remaining := maxRunes - runes
		truncated, n := apmstrings.Truncate(v, remaining)
		if n > 0 {
			w.StringContents(truncated)
			runes += n
		}
	}

	if strings.IndexByte(v.Hostname, ':') == -1 {
		stringContents(v.Hostname)
	} else {
		rawByte('[')
		stringContents(v.Hostname)
		rawByte(']')
	}
	if v.Port != "" {
		rawByte(':')
		stringContents(v.Port)
	}
	if v.Path != "" {
		if !strings.HasPrefix(v.Path, "/") {
			rawByte('/')
		}
		stringContents(v.Path)
	}
	if v.Search != "" {
		rawByte('?')
		stringContents(v.Search)
	}
	if v.Hash != "" {
		rawByte('#')
		stringContents(v.Hash)
	}
	w.RawByte('"')
	return true
}