(writer: Writer, strings: readonly string[])
| 105 | }; |
| 106 | |
| 107 | const writeStrings = (writer: Writer, strings: readonly string[]): void => { |
| 108 | const lengths: number[] = [], |
| 109 | suffixes: string[] = []; |
| 110 | let previous = ""; |
| 111 | for (const value of strings) { |
| 112 | let prefix = 0, |
| 113 | offset = 0, |
| 114 | prefixBytes = 0; |
| 115 | while ( |
| 116 | offset < previous.length && |
| 117 | offset < value.length && |
| 118 | previous.codePointAt(offset) === value.codePointAt(offset) |
| 119 | ) { |
| 120 | const point = value.codePointAt(offset)!; |
| 121 | prefixBytes += point < 128 ? 1 : point < 2048 ? 2 : point < 65536 ? 3 : 4; |
| 122 | offset += point > 65535 ? 2 : 1; |
| 123 | prefix++; |
| 124 | } |
| 125 | writer.accountText(prefixBytes); |
| 126 | lengths.push(prefix); |
| 127 | suffixes.push(value.slice(offset)); |
| 128 | previous = value; |
| 129 | } |
| 130 | writer.uint(strings.length); |
| 131 | writer.vector(lengths); |
| 132 | for (const suffix of suffixes) writer.text(suffix); |
| 133 | }; |
| 134 | |
| 135 | const readStrings = (reader: Reader): string[] => { |
| 136 | const count = reader.count(reader.limits.maxEntries), |
no test coverage detected