Encodes a list of strings to a single string.
(strs []string)
| 11 | |
| 12 | // Encodes a list of strings to a single string. |
| 13 | func (codec *Codec) Encode(strs []string) string { |
| 14 | var b bytes.Buffer |
| 15 | for _, s := range strs { |
| 16 | // encode string using length and underscore header |
| 17 | l := len(s) |
| 18 | b.WriteString(fmt.Sprintf("%d_%s", l, s)) |
| 19 | } |
| 20 | return b.String() |
| 21 | } |
| 22 | |
| 23 | // Decodes a single string to a list of strings. |
| 24 | func (codec *Codec) Decode(strs string) []string { |
no outgoing calls