Decodes a single string to a list of strings.
(strs string)
| 22 | |
| 23 | // Decodes a single string to a list of strings. |
| 24 | func (codec *Codec) Decode(strs string) []string { |
| 25 | s := make([]string, 0) |
| 26 | for i := 0; i < len(strs); i++ { |
| 27 | var b bytes.Buffer |
| 28 | |
| 29 | // read string header until an underscore is seen |
| 30 | charCnt := 0 |
| 31 | for string(strs[i]) != "_" { |
| 32 | l, _ := strconv.Atoi(string(strs[i])) |
| 33 | charCnt = (charCnt + l) * 10 |
| 34 | i++ |
| 35 | } |
| 36 | charCnt /= 10 |
| 37 | |
| 38 | // add charCnt characters to the buffer |
| 39 | for j := 1; j <= charCnt; j++ { |
| 40 | b.WriteByte(strs[i+j]) |
| 41 | } |
| 42 | s = append(s, b.String()) |
| 43 | |
| 44 | // move i forward over the last read string |
| 45 | i += charCnt |
| 46 | } |
| 47 | |
| 48 | return s |
| 49 | } |
no outgoing calls