fix formatting of typeInfoNotState + image lines

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
development
kim (grufwub) 4 years ago
parent f8718ad1b6
commit f9c81b5ffd

@ -25,19 +25,14 @@ func formatName(name string) string {
// formatSelector formats a gopher line selector string
func formatSelector(selector string) string {
if len(selector) > maxSelectorLen {
return errorSelector + "\t"
return errorSelector
}
return selector + "\t"
}
// formatHostPort formats a gopher line host + port
func formatHostPort(host, port string) string {
return host + "\t" + port
return selector
}
// replacePlacementStrs replaces any placement strings found in the line (e.g $hostname, $port)
func replacePlacementStrs(line string) string {
split := strings.Split(line, "\t")
split := strings.SplitN(line, "\t", 4)
// Either invalid line, or information line without host + port
if len(split) != 4 {
@ -53,12 +48,12 @@ func replacePlacementStrs(line string) string {
// buildLine builds a gopher line string
func buildLine(t ItemType, name, selector, host, port string) []byte {
return []byte(string(t) + formatName(name) + formatSelector(selector) + formatHostPort(host, port) + "\r\n")
return []byte(string(t) + formatName(name) + formatSelector(selector) + "\t" + host + "\t" + port + "\r\n")
}
// buildInfoLine builds a gopher info line string
func buildInfoLine(line string) []byte {
return []byte(string(typeInfo) + formatName(line) + formatHostPort(nullHost, nullPort) + "\r\n")
return []byte(string(typeInfo) + formatName(line) + "\t" + nullHost + "\t" + nullPort + "\r\n")
}
// buildErrorLine builds a gopher error line string

@ -52,7 +52,7 @@ const (
// Internal item types
const (
typeDefault = typeBin
typeInfoNotStated = ItemType('I')
typeInfoNotStated = ItemType('\x00')
typeUnknown = ItemType('?')
)
@ -166,7 +166,6 @@ func parseLineType(line string) ItemType {
if lineLen == 1 {
// The only accepted types for length 1 line below:
t := ItemType(line[0])
if t == typeEnd ||
t == typeEndBeginList ||
t == typeComment ||
@ -191,5 +190,6 @@ func parseLineType(line string) ItemType {
return typeInfoNotStated
}
// Return as-is
return t
}

Loading…
Cancel
Save