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

Method set

projects/JavaScript/proto/fbe.js:4145–4190  ·  view source on GitHub ↗

* Set the decimal value * @this {!FieldModelDecimal} * @param {!Big} value Value * @returns {!number} Final model size

(value)

Source from the content-addressed store, hash-verified

4143 * @returns {!number} Final model size
4144 */
4145 set (value) {
4146 console.assert(((this._buffer.offset + this.fbeOffset + this.fbeSize) <= this._buffer.size), 'Model is broken!')
4147 if ((this._buffer.offset + this.fbeOffset + this.fbeSize) > this._buffer.size) {
4148 return 0
4149 }
4150
4151 // Extract decimal parts
4152 let negative = value.s < 0
4153 let scale = Math.max(0, value.c.length - 1 - value.e)
4154 let number = value.mul(Math.pow(10, scale)).abs()
4155
4156 // Check for decimal scale overflow
4157 if ((scale < 0) || (scale > 28)) {
4158 // Value scale exceeds .NET Decimal limit of [0, 28]
4159 this.writeCount(this.fbeOffset, 0, this.fbeSize)
4160 return this.fbeSize
4161 }
4162
4163 // Write unscaled value to bytes 0-11
4164 let index = 0
4165 while (number > 0) {
4166 // Check for decimal number overflow
4167 if (index > 11) {
4168 // Value too big for .NET Decimal (bit length is limited to [0, 96])
4169 this.writeCount(this.fbeOffset, 0, this.fbeSize)
4170 return this.fbeSize
4171 }
4172 let byte = parseInt(number.mod(256))
4173 this.writeByte(this.fbeOffset + index, byte)
4174 number = number.div(256).round(0, 0)
4175 index++
4176 }
4177
4178 // Fill remaining bytes with zeros
4179 while (index < 12) {
4180 this.writeByte(this.fbeOffset + index, 0)
4181 index++
4182 }
4183
4184 // Write scale at byte 14
4185 this.writeByte(this.fbeOffset + 14, scale)
4186
4187 // Write signum at byte 15
4188 this.writeByte(this.fbeOffset + 15, (negative ? 0x80 : 0))
4189 return this.fbeSize
4190 }
4191}
4192
4193exports.FinalModelDecimal = FinalModelDecimal

Callers

nothing calls this directly

Calls 5

writeCountMethod · 0.80
writeByteMethod · 0.80
mulMethod · 0.45
modMethod · 0.45
divMethod · 0.45

Tested by

no test coverage detected