node-opcua-binary-stream
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "node-opcua-binary-stream", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "pure nodejs OPCUA SDK - module -binary-stream", | ||
@@ -5,0 +5,0 @@ "main": "src/binaryStream.js", |
@@ -154,12 +154,35 @@ "use strict"; | ||
var my_memcpy = function my_memcpy(target, targetStart, source, sourceStart, sourceEnd) { | ||
assert(target instanceof Buffer || target instanceof Uint8Array); | ||
assert(source instanceof Buffer || source instanceof Uint8Array); | ||
var l = targetStart; | ||
for (var i = sourceStart; i < sourceEnd; i++) { | ||
target[l++] = source[i]; | ||
/** | ||
* @method writeArrayBuffer | ||
* @param arrayBuf {ArrayBuffer} | ||
* @param offset {Number} | ||
* @param length {Number} | ||
*/ | ||
BinaryStream.prototype.writeArrayBuffer = function (arrayBuf, offset, length) { | ||
offset = offset || 0; | ||
assert(arrayBuf instanceof ArrayBuffer); | ||
var byteArr = new Uint8Array(arrayBuf); | ||
var n = (length || byteArr.length) + offset; | ||
for (var i = offset; i < n; i++) { | ||
this._buffer[this.length++] = byteArr[i]; | ||
} | ||
return sourceEnd - sourceStart; | ||
}; | ||
/** | ||
* @method readArrayBuffer | ||
* @param length | ||
* @returns {Uint8Array} | ||
*/ | ||
BinaryStream.prototype.readArrayBuffer = function (length) { | ||
assert(this.length + length <= this._buffer.length, "not enough bytes in buffer"); | ||
var slice = this._buffer.slice(this.length, this.length + length); | ||
assert(slice.length === length); | ||
var byteArr = new Uint8Array(slice); | ||
assert(byteArr.length === length); | ||
this.length += length; | ||
return byteArr; | ||
} | ||
var displayWarnings = false; | ||
@@ -180,5 +203,37 @@ require("colors"); | ||
try { | ||
var my_memcpy = function my_memcpy(target, targetStart, source, sourceStart, sourceEnd) { | ||
//xx assert(target instanceof Buffer || target instanceof Uint8Array); | ||
//xx assert(source instanceof Buffer || source instanceof Uint8Array); | ||
var l = targetStart; | ||
for (var i = sourceStart; i < sourceEnd; i++) { | ||
target[l++] = source[i]; | ||
} | ||
return sourceEnd - sourceStart; | ||
}; | ||
var memcpy = require("memcpy"); // C++ binding if available, else native JS | ||
my_memcpy = memcpy; | ||
console.log("Warning : using memcpy : OK".yellow); | ||
BinaryStream.prototype.writeArrayBuffer = function (arrayBuf, offset, length) { | ||
offset = offset || 0; | ||
assert(arrayBuf instanceof ArrayBuffer); | ||
var byteArr = new Uint8Array(arrayBuf); | ||
length = length || byteArr.length; | ||
if (length === 0) { | ||
return; | ||
} | ||
this.length += my_memcpy(this._buffer, this.length, byteArr, offset, offset + length); | ||
}; | ||
BinaryStream.prototype.readArrayBuffer = function (length) { | ||
assert(this.length + length <= this._buffer.length, "not enough bytes in buffer"); | ||
var byteArr = new Uint8Array(new ArrayBuffer(length)); | ||
my_memcpy(byteArr, 0, this._buffer, this.length, this.length + length); | ||
this.length += length; | ||
return byteArr; | ||
}; | ||
} | ||
@@ -189,22 +244,2 @@ catch (err) { | ||
BinaryStream.prototype.writeArrayBuffer = function (arrayBuf, offset, length) { | ||
offset = offset || 0; | ||
assert(arrayBuf instanceof ArrayBuffer); | ||
var byteArr = new Uint8Array(arrayBuf); | ||
length = length || byteArr.length; | ||
if (length === 0) { | ||
return; | ||
} | ||
this.length += my_memcpy(this._buffer, this.length, byteArr, offset, offset + length); | ||
}; | ||
BinaryStream.prototype.readArrayBuffer = function (length) { | ||
assert(this.length + length <= this._buffer.length, "not enough bytes in buffer"); | ||
var byteArr = new Uint8Array(new ArrayBuffer(length)); | ||
my_memcpy(byteArr, 0, this._buffer, this.length, this.length + length); | ||
this.length += length; | ||
return byteArr; | ||
}; | ||
/** | ||
@@ -430,3 +465,3 @@ * read a single signed byte (8 bits) from the stream. | ||
assert(arrayBuf instanceof ArrayBuffer); | ||
this.length += (byteLength || new Uint8Array(arrayBuf).length); | ||
this.length += (byteLength || arrayBuf.byteLength); | ||
}; | ||
@@ -440,3 +475,2 @@ | ||
this.length += buf.length; | ||
} | ||
@@ -443,0 +477,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15940
3
422