本文整理汇总了TypeScript中node-opcua-binary-stream.BinaryStream.rewind方法的典型用法代码示例。如果您正苦于以下问题:TypeScript BinaryStream.rewind方法的具体用法?TypeScript BinaryStream.rewind怎么用?TypeScript BinaryStream.rewind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node-opcua-binary-stream.BinaryStream
的用法示例。
在下文中一共展示了BinaryStream.rewind方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _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();
}
}
示例2: encode_decode_round_trip_test
export function encode_decode_round_trip_test(obj: any, options: any, callback_buffer?: any) {
if (!callback_buffer && _.isFunction(options)) {
callback_buffer = options;
options = {};
}
callback_buffer = callback_buffer || dump_block_in_debug_mode;
should.exist(obj);
const size = obj.binaryStoreSize(options);
const stream = new BinaryStream(Buffer.alloc(size));
obj.encode(stream, options);
callback_buffer(stream.buffer, obj.encodingDefaultBinary, options);
stream.rewind();
// reconstruct a object ( some object may not have a default Binary and should be recreated
const expandedNodeId = obj.encodingDefaultBinary;
const objReloaded = expandedNodeId ? constructObject(expandedNodeId) : new obj.constructor();
objReloaded.decode(stream, options);
redirectToNull(() => analyze_object_binary_encoding(obj));
compare(objReloaded, obj);
return objReloaded;
}
示例3: randomGuid
export function randomGuid(): Guid {
const b = new BinaryStream(20);
for (let i = 0; i < 20; i++) {
b.writeUInt8(getRandomInt(0, 255));
}
b.rewind();
const value = decodeGuid(b) as Guid;
return value;
}
示例4: it
it("should encode/decode an ArgumentList (scalar)", () => {
const definition = [{dataType: DataType.UInt32}];
const args = [100];
const size = binaryStoreSize_ArgumentList(definition, args);
size.should.equal(4, " the size of a single UInt32");
const stream = new BinaryStream(size);
encode_ArgumentList(definition, args, stream);
stream.rewind();
const args_reloaded = decode_ArgumentList(definition, stream);
_.isArray(args_reloaded).should.equal(true);
args_reloaded[0].should.eql(100);
});
示例5: it
it("Q3 should encode and decode a method call request", async () => {
const objectId = makeNodeId(999990, 0);
const methodId = makeNodeId(999992, 0);
const obj = addressSpace.findNode(objectId)! as UAObject;
obj.nodeClass.should.eql(NodeClass.Object);
const method = obj.getMethodById(methodId)!;
method.nodeClass.should.eql(NodeClass.Method);
method.browseName.toString().should.eql("DoStuff");
const inputArguments = method.getInputArguments();
inputArguments.should.be.instanceOf(Array);
const callRequest = new CallRequest({
methodsToCall: [{
inputArguments: [{
dataType: DataType.UInt32,
value: [0xAA, 0xAB, 0xAC]
}],
methodId,
objectId
}]
});
const size = callRequest.binaryStoreSize();
const stream = new BinaryStream(size);
callRequest.encode(stream);
if (doDebug) {
console.log(hexDump(stream.buffer));
}
// now decode
const callRequest_reloaded = new CallRequest();
stream.rewind();
callRequest_reloaded.decode(stream);
});
示例6: analyze_object_binary_encoding
export function analyze_object_binary_encoding(obj: BaseUAObject) {
assert(obj);
const size = obj.binaryStoreSize();
console.log("-------------------------------------------------");
console.log(" size = ", size);
const stream = new BinaryStream(size);
obj.encode(stream);
stream.rewind();
console.log("-------------------------------------------------");
if (stream.buffer.length < 256) {
console.log(hexDump(stream.buffer));
console.log("-------------------------------------------------");
}
const reloadedObject = new (obj.constructor as any)();
analyzePacket(stream.buffer, reloadedObject, 0);
}