@param {string} str
(str)
| 324 | |
| 325 | /** @param {string} str */ |
| 326 | writeString(str) { |
| 327 | str = String(str); |
| 328 | this.realloc(str.length * 4); |
| 329 | |
| 330 | this.pos++; // reserve 1 byte for short string length |
| 331 | |
| 332 | const startPos = this.pos; |
| 333 | // write the string directly to the buffer and see how much was written |
| 334 | this.pos = writeUtf8(this.buf, str, this.pos); |
| 335 | const len = this.pos - startPos; |
| 336 | |
| 337 | if (len >= 0x80) makeRoomForExtraLength(startPos, len, this); |
| 338 | |
| 339 | // finally, write the message length in the reserved place and restore the position |
| 340 | this.pos = startPos - 1; |
| 341 | this.writeVarint(len); |
| 342 | this.pos += len; |
| 343 | } |
| 344 | |
| 345 | /** @param {number} val */ |
| 346 | writeFloat(val) { |
no test coverage detected