| 3785 | // A watching leaf writes the string alone, so watching costs nothing on the |
| 3786 | // wire. |
| 3787 | function encodeString(dict: DictWrite, layout: LeafLayout, value: string, w: Writer) { |
| 3788 | const slot = dictSlot(dict.slots, layout.slot) |
| 3789 | const state = slot.state |
| 3790 | if (state === DICT_GAVE_UP) { |
| 3791 | w.string(value) |
| 3792 | return |
| 3793 | } |
| 3794 | dictMark(dict, slot) |
| 3795 | if (state === DICT_WATCHING) { |
| 3796 | w.string(value) |
| 3797 | dictWatch(slot, value) |
| 3798 | return |
| 3799 | } |
| 3800 | const ref = slot.refs.get(value) |
| 3801 | if (ref !== undefined) { |
| 3802 | w.uvarint(ref * 2 + 1) |
| 3803 | return |
| 3804 | } |
| 3805 | w.byte(0) |
| 3806 | dictAdd(slot, value) |
| 3807 | w.string(value) |
| 3808 | } |
| 3809 | |
| 3810 | function decodeString(dict: DictRead, layout: LeafLayout, r: Reader): string { |
| 3811 | const slot = dictSlot(dict, layout.slot) |