MCPcopy Create free account
hub / github.com/mapbox/pbf / writeString

Method writeString

index.js:326–343  ·  view source on GitHub ↗

@param {string} str

(str)

Source from the content-addressed store, hash-verified

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) {

Callers 2

writeStringFieldMethod · 0.95
pbf.test.jsFile · 0.80

Calls 4

reallocMethod · 0.95
writeVarintMethod · 0.95
writeUtf8Function · 0.85
makeRoomForExtraLengthFunction · 0.85

Tested by

no test coverage detected