本文整理汇总了TypeScript中node-opcua-assert.assert函数的典型用法代码示例。如果您正苦于以下问题:TypeScript assert函数的具体用法?TypeScript assert怎么用?TypeScript assert使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: resolveDataTypeName
function resolveDataTypeName(
addressSpace: AddressSpacePrivate,
dataType: string | NodeId
): QualifiedName {
let dataTypeNode = null;
// istanbul ignore next
if (_.isString(dataType)) {
dataTypeNode = addressSpace.findDataType(dataType);
} else {
assert(dataType instanceof NodeId);
const o = addressSpace.findNode(dataType.toString());
dataTypeNode = o ? o : null;
}
if (!dataTypeNode) {
throw new Error("Cannot find dataTypeName " + dataType);
}
return dataTypeNode.browseName;
}
示例2: dumpReferencedNodesOld
function dumpReferencedNodesOld(
xw: XmlWriter,
node: BaseNode,
forward: boolean
) {
assert(_.isBoolean(forward));
xw.visitedNode[_hash(node)] = 1;
const nodesToVisit: any = {};
visitUANode(node, nodesToVisit, forward);
for (const el of nodesToVisit.elements) {
if (!xw.visitedNode[_hash(el)]) {
el.dumpXML(xw);
}
}
}
示例3: _post_process_current_chunk
private _post_process_current_chunk() {
let extraEncryptionBytes = 0;
// add padding bytes if needed
if (this.plainBlockSize > 0) {
// write padding ( if encryption )
// let's calculate curLength = the length of the block to encrypt without padding yet
// +---------------+---------------+-------------+---------+--------------+------------+
// |SequenceHeader | data | paddingByte | padding | extraPadding | signature |
// +---------------+---------------+-------------+---------+--------------+------------+
let curLength = this.sequenceHeaderSize + this.cursor + this.signatureLength;
if (this.plainBlockSize > 256) {
curLength += 2; // account for extraPadding Byte Number;
} else {
curLength += 1;
}
// let's calculate the required number of padding bytes
const n = (curLength % this.plainBlockSize);
const nbPaddingByteTotal = (this.plainBlockSize - n) % this.plainBlockSize;
this._write_padding_bytes(nbPaddingByteTotal);
const adjustedLength = this.sequenceHeaderSize + this.cursor + this.signatureLength;
assert(adjustedLength % this.plainBlockSize === 0);
const nbBlock = adjustedLength / this.plainBlockSize;
extraEncryptionBytes = nbBlock * (this.cipherBlockSize - this.plainBlockSize);
}
this.dataEnd = this.dataOffset + this.cursor;
// calculate the expected length of the chunk, once encrypted if encryption apply
const expectedLength = this.dataEnd + this.signatureLength + extraEncryptionBytes;
this.pendingChunk = this.chunk!.slice(0, expectedLength);
// note :
// - this.pending_chunk has the correct size but is not signed nor encrypted yet
// as we don't know what to write in the header yet
// - as a result,
this.chunk = null;
this.cursor = 0;
}
示例4: assert
this.withSession(endpointUrl, (session: ClientSession, done: (err?: Error) => void) => {
assert(_.isFunction(done));
const subscription = new ClientSubscriptionImpl(session as ClientSessionImpl, subscriptionParameters);
try {
innerFunc(session, subscription, (err?: Error) => {
subscription.terminate((err1?: Error) => {
done(err1);
});
});
} catch (err) {
debugLog(err);
done(err);
}
}, callback);
示例5: _historyReadRawAsync
function _historyReadRawAsync(
this: UAVariable,
historyReadRawModifiedDetails: ReadRawModifiedDetails,
maxNumberToExtract: number,
isReversed: boolean,
reverseDataValue: boolean,
callback: Callback<DataValue[]>
) {
assert(callback instanceof Function);
const node = this;
node.varHistorian!.extractDataValues(
historyReadRawModifiedDetails,
maxNumberToExtract,
isReversed,
reverseDataValue,
callback);
}
示例6: getMiniAddressSpace
export function getMiniAddressSpace(...args: any[]): any {
const callback = args[0] as (err: Error | null, addressSpace?: AddressSpace) => void;
const addressSpace = AddressSpace.create();
// register namespace 1 (our namespace);
const serverNamespace = addressSpace.registerNamespace("http://MYNAMESPACE");
assert(serverNamespace.index === 1);
generateAddressSpace(addressSpace, get_mini_nodeset_filename(), (err?: Error) => {
// istanbul ignore next
if (err) {
// tslint:disable:no-console
console.log("err =", err);
}
callback(err || null, addressSpace);
});
}
示例7: debugLog
this._mockTransport.server.on("data", (data: Buffer) => {
let reply = this._replies[this._counter];
this._counter++;
if (reply) {
if (_.isFunction(reply)) {
reply = reply.call(this);
// console.log(" interpreting reply as a function" + reply);
if (!reply) {
return;
}
}
debugLog("\nFAKE SERVER RECEIVED");
debugLog(hexDump(data));
let replies = [];
if (reply instanceof Buffer) {
replies.push(reply);
} else {
replies = reply;
}
assert(replies.length >= 1, " expecting at least one reply " + JSON.stringify(reply));
replies.forEach((reply1: any) => {
debugLog("\nFAKE SERVER SEND");
debugLog(chalk.red(hexDump(reply1)));
this._mockTransport.server.write(reply1);
});
} else {
const msg = " MockServerTransport has no more packets to send to client to" +
" emulate server responses.... ";
console.log(chalk.red.bold(msg));
console.log(chalk.blue.bold(hexDump(data)));
display_trace_from_this_projet_only();
analyseExtensionObject(data, 0, 0, {});
this.emit("done");
}
});
示例8: _acknowledge_branch
public _acknowledge_branch(
eventId: Buffer,
comment: string | LocalizedTextLike | LocalizedText,
branch: ConditionSnapshot,
message: string
) {
assert(typeof (message) === "string");
const conditionNode = this;
if (conditionNode.confirmedState) {
// alarm has a confirmed state !
// we should be waiting for confirmation now
branch.setConfirmedState(false);
branch.setRetain(true);
} else {
branch.setRetain(false);
}
const statusCode = _setAckedState(branch, true, eventId, comment);
if (statusCode !== StatusCodes.Good) {
return statusCode;
}
branch.setComment(comment);
conditionNode.raiseNewBranchState(branch);
// xx conditionNode._raiseAuditConditionCommentEvent("Method/Acknowledge",eventId,comment);
conditionNode._raiseAuditConditionAcknowledgeEvent(branch);
/**
* @event acknowledged
* @param eventId {Buffer|null}
* @param comment {LocalizedText}
* @param branch {ConditionSnapshot}
* raised when the alarm branch has been acknowledged
*/
conditionNode.emit("acknowledged", eventId, comment, branch);
}
示例9: setDeprecated
export function setDeprecated(constructor: Function, methodName: string, helpString: string): void {
const oldMethod = constructor.prototype[methodName];
assert(oldMethod instanceof Function,
"expecting a valid " + methodName + "method on class " + constructor.constructor.name);
let counter = 0;
constructor.prototype[methodName] = function() {
if (counter % 1000 === 0) {
// tslint:disable:no-console
console.log(chalk.green("Warning !"),
chalk.green(chalk.bold(constructor.name + "#" + methodName), " is now deprecated"));
console.log(" ", helpString);
}
counter++;
return oldMethod.apply(this, arguments);
};
}
示例10: _start_one_time_message_receiver
private _start_one_time_message_receiver() {
assert(!this._timerId, "timer already started");
// Setup timeout detection timer ....
this._timerId = setTimeout(() => {
this._timerId = null;
this._fulfill_pending_promises(
new Error(`Timeout in waiting for data on socket ( timeout was = ${this.timeout} ms)`));
}, this.timeout);
// also monitored
if (this._socket) {
// to do = intercept socket error as well
this._on_error_during_one_time_message_receiver = (err?: Error) => {
this._fulfill_pending_promises(
new Error(`ERROR in waiting for data on socket ( timeout was = ${this.timeout} ms)`));
};
this._socket.on("close", this._on_error_during_one_time_message_receiver);
}
}