func (t Version) serialize(minPlaces int, quoted bool) []byte {
	var idx, lastNonZero, bytesNeeded int

	if quoted {
		bytesNeeded = 2
	}

	for idx, elem := range t.version {
		if elem != 0 {
			lastNonZero = idx
		}
	}

	// Determine how much target space is needed (i.e. the string length).
	for idx = 0; idx < len(t.version); idx += 5 {
		switch {
		case t.version[idx+3] != 0 || minPlaces >= idx+4:
			bytesNeeded += 1 + numDecimalPlaces(t.version[idx+3])
			fallthrough
		case t.version[idx+2] != 0 || minPlaces >= idx+3:
			bytesNeeded += 1 + numDecimalPlaces(t.version[idx+2])
			fallthrough
		case t.version[idx+1] != 0 || minPlaces >= idx+2:
			bytesNeeded += 1 + numDecimalPlaces(t.version[idx+1])
			fallthrough
		default:
			bytesNeeded += numDecimalPlaces(t.version[idx])
		}
		if idx+4 >= len(t.version) {
			break
		}

		if idx+4 <= lastNonZero { // X.Y.Z.N - ?a.b.c.d
			bytesNeeded++
		}
		if t.version[idx+4] != 0 { // alpha, beta, …
			bytesNeeded += len(releaseDesc[int(t.version[idx+4])])
		}

		if lastNonZero <= idx+4 { // We're done if the remainder is empty.
			break
		}
	}
	if t.build != 0 {
		bytesNeeded += len("+build") + numDecimalPlaces(t.build)
	}

	// Build the string representation
	target := make([]byte, 0, bytesNeeded)

	if quoted {
		target = append(target, '"')
	}

	for idx = 0; idx < len(t.version); idx += 5 {
		switch {
		case t.version[idx+3] != 0 || minPlaces >= 4:
			target = strconv.AppendUint(target, uint64(t.version[idx]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+1]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+2]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+3]), 10)
		case t.version[idx+2] != 0 || minPlaces >= 3:
			target = strconv.AppendUint(target, uint64(t.version[idx]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+1]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+2]), 10)
		case t.version[idx+1] != 0 || minPlaces >= 2:
			target = strconv.AppendUint(target, uint64(t.version[idx]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+1]), 10)
		default:
			target = strconv.AppendUint(target, uint64(t.version[idx]), 10)
		}
		if idx+4 >= len(t.version) {
			break
		}

		if idx+4 <= lastNonZero {
			target = append(target, '-')
		}
		if t.version[idx+4] != 0 {
			target = append(target, []byte(releaseDesc[int(t.version[idx+4])])...)
		}

		if lastNonZero <= idx+4 {
			break
		}
		minPlaces -= 5
	}
	if t.build != 0 {
		target = append(target, buildsuffix...)
		target = strconv.AppendUint(target, uint64(t.build), 10)
	}
	if quoted {
		target = append(target, '"')
	}

	return target
}
// Serialize builds a minimal human-readable representation of this Version,
// and returns it as slice.
// Set |minPlaces| to how many columns the prefix must contain.
Serialize builds a minimal human-readable representation of this Version,
and returns it as slice.
Set |minPlaces| to how many columns the prefix must contain.
// Serialize builds a minimal human - readable representation of this Version // and returns it as slice . // Set |minPlaces| to how many columns the prefix must contain .
func (t Version) serialize(minPlaces int, quoted bool) []byte {
	var idx, lastNonZero, bytesNeeded int
	if quoted {
		bytesNeeded = 2
	}
	for idx, elem := range t.version {
		if elem != 0 {
			lastNonZero = idx
		}
	}
	for idx = 0; idx < len(t.version); idx += 5 {
		switch {
		case t.version[idx+3] != 0 || minPlaces >= idx+4:
			bytesNeeded += 1 + numDecimalPlaces(t.version[idx+3])
			fallthrough
		case t.version[idx+2] != 0 || minPlaces >= idx+3:
			bytesNeeded += 1 + numDecimalPlaces(t.version[idx+2])
			fallthrough
		case t.version[idx+1] != 0 || minPlaces >= idx+2:
			bytesNeeded += 1 + numDecimalPlaces(t.version[idx+1])
			fallthrough
		default:
			bytesNeeded += numDecimalPlaces(t.version[idx])
		}
		if idx+4 >= len(t.version) {
			break
		}
		if idx+4 <= lastNonZero { 
			bytesNeeded++
		}
		if t.version[idx+4] != 0 { 
			bytesNeeded += len(releaseDesc[int(t.version[idx+4])])
		}
		if lastNonZero <= idx+4 { 
			break
		}
	}
	if t.build != 0 {
		bytesNeeded += len("+build") + numDecimalPlaces(t.build)
	}
	target := make([]byte, 0, bytesNeeded)
	if quoted {
		target = append(target, '"')
	}
	for idx = 0; idx < len(t.version); idx += 5 {
		switch {
		case t.version[idx+3] != 0 || minPlaces >= 4:
			target = strconv.AppendUint(target, uint64(t.version[idx]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+1]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+2]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+3]), 10)
		case t.version[idx+2] != 0 || minPlaces >= 3:
			target = strconv.AppendUint(target, uint64(t.version[idx]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+1]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+2]), 10)
		case t.version[idx+1] != 0 || minPlaces >= 2:
			target = strconv.AppendUint(target, uint64(t.version[idx]), 10)
			target = append(target, '.')
			target = strconv.AppendUint(target, uint64(t.version[idx+1]), 10)
		default:
			target = strconv.AppendUint(target, uint64(t.version[idx]), 10)
		}
		if idx+4 >= len(t.version) {
			break
		}
		if idx+4 <= lastNonZero {
			target = append(target, '-')
		}
		if t.version[idx+4] != 0 {
			target = append(target, []byte(releaseDesc[int(t.version[idx+4])])...)
		}
		if lastNonZero <= idx+4 {
			break
		}
		minPlaces -= 5
	}
	if t.build != 0 {
		target = append(target, buildsuffix...)
		target = strconv.AppendUint(target, uint64(t.build), 10)
	}
	if quoted {
		target = append(target, '"')
	}
	return target
}
func ( t Version ) serialize ( minPlaces int , quoted bool ) [ ] byte { var idx , lastNonZero , bytesNeeded int if quoted { bytesNeeded = 2 } for idx , elem := range t . version { if elem != 0 { lastNonZero = idx } } for idx = 0 ; idx < len ( t . version ) ; idx += 5 { switch { case t . version [ idx + 3 ] != 0 || minPlaces >= idx + 4 : bytesNeeded += 1 + numDecimalPlaces ( t . version [ idx + 3 ] ) fallthrough case t . version [ idx + 2 ] != 0 || minPlaces >= idx + 3 : bytesNeeded += 1 + numDecimalPlaces ( t . version [ idx + 2 ] ) fallthrough case t . version [ idx + 1 ] != 0 || minPlaces >= idx + 2 : bytesNeeded += 1 + numDecimalPlaces ( t . version [ idx + 1 ] ) fallthrough default : bytesNeeded += numDecimalPlaces ( t . version [ idx ] ) } if idx + 4 >= len ( t . version ) { break } if idx + 4 <= lastNonZero { bytesNeeded ++ } if t . version [ idx + 4 ] != 0 { bytesNeeded += len ( releaseDesc [ int ( t . version [ idx + 4 ] ) ] ) } if lastNonZero <= idx + 4 { break } } if t . build != 0 { bytesNeeded += len ( " " ) + numDecimalPlaces ( t . build ) } target := make ( [ ] byte , 0 , bytesNeeded ) if quoted { target = append ( target , '"' ) } for idx = 0 ; idx < len ( t . version ) ; idx += 5 { switch { case t . version [ idx + 3 ] != 0 || minPlaces >= 4 : target = strconv . AppendUint ( target , uint64 ( t . version [ idx ] ) , 10 ) target = append ( target , '.' ) target = strconv . AppendUint ( target , uint64 ( t . version [ idx + 1 ] ) , 10 ) target = append ( target , '.' ) target = strconv . AppendUint ( target , uint64 ( t . version [ idx + 2 ] ) , 10 ) target = append ( target , '.' ) target = strconv . AppendUint ( target , uint64 ( t . version [ idx + 3 ] ) , 10 ) case t . version [ idx + 2 ] != 0 || minPlaces >= 3 : target = strconv . AppendUint ( target , uint64 ( t . version [ idx ] ) , 10 ) target = append ( target , '.' ) target = strconv . AppendUint ( target , uint64 ( t . version [ idx + 1 ] ) , 10 ) target = append ( target , '.' ) target = strconv . AppendUint ( target , uint64 ( t . version [ idx + 2 ] ) , 10 ) case t . version [ idx + 1 ] != 0 || minPlaces >= 2 : target = strconv . AppendUint ( target , uint64 ( t . version [ idx ] ) , 10 ) target = append ( target , '.' ) target = strconv . AppendUint ( target , uint64 ( t . version [ idx + 1 ] ) , 10 ) default : target = strconv . AppendUint ( target , uint64 ( t . version [ idx ] ) , 10 ) } if idx + 4 >= len ( t . version ) { break } if idx + 4 <= lastNonZero { target = append ( target , '-' ) } if t . version [ idx + 4 ] != 0 { target = append ( target , [ ] byte ( releaseDesc [ int ( t . version [ idx + 4 ] ) ] ) ... ) } if lastNonZero <= idx + 4 { break } minPlaces -= 5 } if t . build != 0 { target = append ( target , buildsuffix ... ) target = strconv . AppendUint ( target , uint64 ( t . build ) , 10 ) } if quoted { target = append ( target , '"' ) } return target }
Serialize builds a minimal human-readable representation of this Version,
and returns it as slice.
Serialize builds a minimal human - readable representation of this Version and returns it as slice .
// Determine how much target space is needed (i.e. the string length). // X.Y.Z.N - ?a.b.c.d // alpha, beta, … // We're done if the remainder is empty. // Build the string representation