fix topic length check (#89)

This commit is contained in:
Paul Wells
2024-03-12 04:02:12 -07:00
committed by GitHub
parent 28644f0103
commit 8ae8bd90c4
+9 -1
View File
@@ -115,7 +115,7 @@ func formatServerChannel(service string, topic []string, queue bool) string {
defer scratch.Put(p)
b := append(*p, "SRV."...)
b = append(b, service...)
if channelPartsLen(topic) > 0 {
if stringSliceLen(topic) > 0 {
b = append(b, '.')
b = appendChannelParts(b, '.', topic...)
}
@@ -125,6 +125,14 @@ func formatServerChannel(service string, topic []string, queue bool) string {
return string(b)
}
func stringSliceLen(s []string) int {
var n int
for i := range s {
n += len(s[i])
}
return n
}
func formatChannel(delim byte, parts ...any) string {
buf := make([]byte, 0, 4*channelPartsLen(parts...)/3)
return string(appendChannelParts(buf, delim, parts...))