MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / _writeUInt16

Function _writeUInt16

MathBox/mathbox-core.js:1618–1636  ·  view source on GitHub ↗
(buf, value, offset, littleEndian, noAssert)

Source from the content-addressed store, hash-verified

1616}
1617
1618function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
1619 if (!noAssert) {
1620 assert(value !== undefined && value !== null, 'missing value')
1621 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1622 assert(offset !== undefined && offset !== null, 'missing offset')
1623 assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
1624 verifuint(value, 0xffff)
1625 }
1626
1627 var len = buf.length
1628 if (offset >= len)
1629 return
1630
1631 for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) {
1632 buf[offset + i] =
1633 (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1634 (littleEndian ? i : 1 - i) * 8
1635 }
1636}
1637
1638Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
1639 _writeUInt16(this, value, offset, true, noAssert)

Callers 2

mathbox-core.jsFile · 0.70
_writeInt16Function · 0.70

Calls 2

assertFunction · 0.70
verifuintFunction · 0.70

Tested by

no test coverage detected