MCPcopy Create free account
hub / github.com/Effect-TS/effect / encodeString

Function encodeString

packages/effect/src/encoding/SchemaBinary.ts:3787–3808  ·  view source on GitHub ↗
(dict: DictWrite, layout: LeafLayout, value: string, w: Writer)

Source from the content-addressed store, hash-verified

3785// A watching leaf writes the string alone, so watching costs nothing on the
3786// wire.
3787function 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
3810function decodeString(dict: DictRead, layout: LeafLayout, r: Reader): string {
3811 const slot = dictSlot(dict, layout.slot)

Callers 1

encodeValueFunction · 0.70

Calls 8

dictSlotFunction · 0.85
dictMarkFunction · 0.85
dictWatchFunction · 0.85
dictAddFunction · 0.85
getMethod · 0.65
stringMethod · 0.45
uvarintMethod · 0.45
byteMethod · 0.45

Tested by

no test coverage detected