本文整理汇总了TypeScript中node-opcua-chunkmanager.readMessageHeader函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readMessageHeader函数的具体用法?TypeScript readMessageHeader怎么用?TypeScript readMessageHeader使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readMessageHeader函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: messageHeaderToString
export function messageHeaderToString(messageChunk: Buffer): string {
const stream = new BinaryStream(messageChunk);
const messageHeader = readMessageHeader(stream);
if (messageHeader.msgType === "ERR" || messageHeader.msgType === "HEL") {
return messageHeader.msgType + " " + messageHeader.isFinal + " length = " + messageHeader.length;
}
const securityHeader = chooseSecurityHeader(messageHeader.msgType);
const sequenceHeader = new SequenceHeader();
assert(stream.length === 8);
const channelId = stream.readUInt32();
securityHeader.decode(stream);
sequenceHeader.decode(stream);
const slice = messageChunk.slice(0, stream.length);
return messageHeader.msgType + " " +
messageHeader.isFinal +
" length = " + messageHeader.length +
" channel = " + channelId +
" seqNum = " + sequenceHeader.sequenceNumber +
" req ID = " + sequenceHeader.requestId +
" security = " + securityHeader.toString() +
"\n\n" + hexDump(slice);
}
示例2: _handle_ACK_response
private _handle_ACK_response(messageChunk: Buffer, callback: ErrorCallback) {
const _stream = new BinaryStream(messageChunk);
const messageHeader = readMessageHeader(_stream);
let err;
if (messageHeader.isFinal !== "F") {
err = new Error(" invalid ACK message");
return callback(err);
}
let responseClass;
let response;
if (messageHeader.msgType === "ERR") {
responseClass = TCPErrorMessage;
_stream.rewind();
response = decodeMessage(_stream, responseClass) as TCPErrorMessage;
err = new Error("ACK: ERR received " + response.statusCode.toString() + " : " + response.reason);
(err as any).statusCode = response.statusCode;
callback(err);
} else {
responseClass = AcknowledgeMessage;
_stream.rewind();
response = decodeMessage(_stream, responseClass);
this.parameters = response;
callback();
}
}
示例3: readRawMessageHeader
export function readRawMessageHeader(data: Buffer): PacketInfo {
const messageHeader = readMessageHeader(new BinaryStream(data));
return {
extra: "",
length: messageHeader.length,
messageHeader
};
}
示例4: _read_headers
protected _read_headers(binaryStream: BinaryStream): boolean {
this.messageHeader = readMessageHeader(binaryStream);
assert(binaryStream.length === 8, "expecting message header to be 8 bytes");
this.channelId = binaryStream.readUInt32();
assert(binaryStream.length === 12);
// verifying secure ChannelId
if (this._expectedChannelId && this.channelId !== this._expectedChannelId) {
return this._report_error("Invalid secure channel Id");
}
return true;
}
示例5: _feed_messageChunk
private _feed_messageChunk(chunk: Buffer) {
assert(chunk);
const messageHeader = readMessageHeader(new BinaryStream(chunk));
/**
* notify the observers that new message chunk has been received
* @event chunk
* @param messageChunk the raw message chunk
*/
this.emit("chunk", chunk);
if (messageHeader.isFinal === "F") {
// last message
this._append(chunk);
if (this._hasReceivedError) {
return false;
}
const fullMessageBody: Buffer = this.blocks.length === 1 ? this.blocks[0] : Buffer.concat(this.blocks);
if (doPerfMonitoring) {
// record tick 1: when a complete message has been received ( all chunks assembled)
this._tick1 = get_clock_tick();
}
/**
* notify the observers that a full message has been received
* @event full_message_body
* @param full_message_body the full message body made of all concatenated chunks.
*/
this.emit("full_message_body", fullMessageBody);
this._decodeMessageBody(fullMessageBody);
// be ready for next block
this._init_new();
return true;
} else if (messageHeader.isFinal === "A") {
return this._report_error("received and Abort Message");
} else if (messageHeader.isFinal === "C") {
return this._append(chunk);
}
return false;
}
示例6: decodeMessage
export function decodeMessage(stream: BinaryStream, classNameConstructor: ConstructorFunc): BaseUAObject {
assert(stream instanceof BinaryStream);
assert(classNameConstructor instanceof Function, " expecting a function for " + classNameConstructor);
const header = readMessageHeader(stream);
assert(stream.length === 8);
let obj;
if (header.msgType === "ERR") {
obj = new TCPErrorMessage();
obj.decode(stream);
return obj;
} else {
obj = new classNameConstructor();
obj.decode(stream);
return obj;
}
}