enc encodes z as a string.
()
| 58 | |
| 59 | // enc encodes z as a string. |
| 60 | func (z *nstate) enc() string { |
| 61 | var buf []byte |
| 62 | var v [10]byte |
| 63 | last := ^uint32(0) |
| 64 | n := binary.PutUvarint(v[:], uint64(z.partial)) |
| 65 | buf = append(buf, v[:n]...) |
| 66 | n = binary.PutUvarint(v[:], uint64(z.flag)) |
| 67 | buf = append(buf, v[:n]...) |
| 68 | dense := z.q.Dense() |
| 69 | ids := make([]int, 0, len(dense)) |
| 70 | for _, id := range z.q.Dense() { |
| 71 | ids = append(ids, int(id)) |
| 72 | } |
| 73 | sort.Ints(ids) |
| 74 | for _, id := range ids { |
| 75 | n := binary.PutUvarint(v[:], uint64(uint32(id)-last)) |
| 76 | buf = append(buf, v[:n]...) |
| 77 | last = uint32(id) |
| 78 | } |
| 79 | return string(buf) |
| 80 | } |
| 81 | |
| 82 | // dec decodes the encoding s into z. |
| 83 | func (z *nstate) dec(s string) { |