Esempio n. 1
0
func frame(data string, json bool) string {
	utf8str := utf8string.NewString(data)
	if json {
		return fmt.Sprintf("~m~%d~m~~j~%s", 3+utf8str.RuneCount(), data)
	}
	return fmt.Sprintf("~m~%d~m~%s", utf8str.RuneCount(), data)
}
func streamingFrame(data string, typ int, json bool) string {
	utf8str := utf8string.NewString(data)
	switch typ {
	case 0:
		return "0:0:,"

	case 2, 3:
		return fmt.Sprintf("%d:%d:%s,", typ, utf8str.RuneCount(), data)
	}

	if json {
		return fmt.Sprintf("%d:%d:j\n:%s,", typ, 3+utf8str.RuneCount(), data)
	}
	return fmt.Sprintf("%d:%d::%s,", typ, 1+utf8str.RuneCount(), data)
}