MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / setBegin

Method setBegin

projects/JavaScript/proto/fbe.js:2293–2315  ·  view source on GitHub ↗

* Set the optional value (begin phase) * @this {!FieldModelOptional} * @param {boolean} hasValue Optional has value flag * @returns {!number} Optional begin offset

(hasValue)

Source from the content-addressed store, hash-verified

2291 * @returns {!number} Optional begin offset
2292 */
2293 setBegin (hasValue) {
2294 console.assert(((this._buffer.offset + this.fbeOffset + this.fbeSize) <= this._buffer.size), 'Model is broken!')
2295 if ((this._buffer.offset + this.fbeOffset + this.fbeSize) > this._buffer.size) {
2296 return 0
2297 }
2298
2299 this.writeUInt8(this.fbeOffset, (hasValue ? 1 : 0))
2300 if (!hasValue) {
2301 return 0
2302 }
2303
2304 let fbeOptionalSize = this.value.fbeSize
2305 let fbeOptionalOffset = this._buffer.allocate(fbeOptionalSize) - this._buffer.offset
2306 console.assert(((fbeOptionalOffset > 0) && ((this._buffer.offset + fbeOptionalOffset + fbeOptionalSize) <= this._buffer.size)), 'Model is broken!')
2307 if ((fbeOptionalOffset <= 0) || ((this._buffer.offset + fbeOptionalOffset + fbeOptionalSize) > this._buffer.size)) {
2308 return 0
2309 }
2310
2311 this.writeUInt32(this.fbeOffset + 1, fbeOptionalOffset)
2312
2313 this._buffer.shift(fbeOptionalOffset)
2314 return fbeOptionalOffset
2315 }
2316
2317 /**
2318 * Set the optional value (end phase)

Callers 1

setMethod · 0.95

Calls 4

writeUInt8Method · 0.80
allocateMethod · 0.45
writeUInt32Method · 0.45
shiftMethod · 0.45

Tested by

no test coverage detected