diff options
Diffstat (limited to 'js/src/Ice/TraceUtil.js')
-rw-r--r-- | js/src/Ice/TraceUtil.js | 345 |
1 files changed, 171 insertions, 174 deletions
diff --git a/js/src/Ice/TraceUtil.js b/js/src/Ice/TraceUtil.js index f341bb20232..3d8c2c93304 100644 --- a/js/src/Ice/TraceUtil.js +++ b/js/src/Ice/TraceUtil.js @@ -7,11 +7,10 @@ // // ********************************************************************** -var Ice = require("../Ice/ModuleRegistry").Ice; +const Ice = require("../Ice/ModuleRegistry").Ice; Ice.__M.require(module, [ "../Ice/Debug", - "../Ice/HashMap", "../Ice/Protocol", "../Ice/StringUtil", "../Ice/Current", @@ -21,185 +20,43 @@ Ice.__M.require(module, // // Local aliases. // -var Debug = Ice.Debug; -var HashMap = Ice.HashMap; -var Protocol = Ice.Protocol; -var StringUtil = Ice.StringUtil; -var OperationMode = Ice.OperationMode; -var Identity = Ice.Identity; +const Debug = Ice.Debug; +const Protocol = Ice.Protocol; +const StringUtil = Ice.StringUtil; +const OperationMode = Ice.OperationMode; +const Identity = Ice.Identity; -var TraceUtil = {}; - -TraceUtil.traceSend = function(stream, logger, traceLevels) -{ - if(traceLevels.protocol >= 1) - { - var p = stream.pos; - var is = new Ice.InputStream(stream.instance, stream.getEncoding(), stream.buffer); - is.pos = 0; - - var s = []; - var type = printMessage(s, is); - - logger.trace(traceLevels.protocolCat, "sending " + getMessageTypeAsString(type) + " " + s.join("")); - - stream.pos = p; - } -}; - -TraceUtil.traceRecv = function(stream, logger, traceLevels) -{ - if(traceLevels.protocol >= 1) - { - var p = stream.pos; - stream.pos = 0; - - var s = []; - var type = printMessage(s, stream); - - logger.trace(traceLevels.protocolCat, "received " + getMessageTypeAsString(type) + " " + s.join("")); - - stream.pos = p; - } -}; - -TraceUtil.traceOut = function(heading, stream, logger, traceLevels) -{ - if(traceLevels.protocol >= 1) - { - var p = stream.pos; - var is = new Ice.InputStream(stream.instance, stream.getEncoding(), stream.buffer); - is.pos = 0; - - var s = []; - s.push(heading); - printMessage(s, is); - - logger.trace(traceLevels.protocolCat, s.join("")); - stream.pos = p; - } -}; - -TraceUtil.traceIn = function(heading, stream, logger, traceLevels) -{ - if(traceLevels.protocol >= 1) - { - var p = stream.pos; - stream.pos = 0; - - var s = []; - s.push(heading); - printMessage(s, stream); - - logger.trace(traceLevels.protocolCat, s.join("")); - stream.pos = p; - } -}; - -var slicingIds = new HashMap(); +const slicingIds = new Map(); function traceSlicing(kind, typeId, slicingCat, logger) { if(!slicingIds.has(typeId)) { - var s = "unknown " + kind + " type `" + typeId + "'"; - logger.trace(slicingCat, s); + logger.trace(slicingCat, `unknown ${kind} type \`${typeId}'`); slicingIds.set(typeId, 1); } } -TraceUtil.dumpStream = function(stream) -{ - var pos = stream.pos; - stream.pos = 0; - - var data = stream.readBlob(stream.size()); - TraceUtil.dumpOctets(data); - - stream.pos = pos; -}; - -TraceUtil.dumpOctets = function(data) -{ - var inc = 8; - var buf = []; - - for(var i = 0; i < data.length; i += inc) - { - var j; - for(j = i; j - i < inc; j++) - { - if(j < data.length) - { - var n = data[j]; - if(n < 0) - { - n += 256; - } - var s; - if(n < 10) - { - s = " " + n; - } - else if(n < 100) - { - s = " " + n; - } - else - { - s = "" + n; - } - buf.push(s + " "); - } - else - { - buf.push(" "); - } - } - - buf.push('"'); - - for(j = i; j < data.length && j - i < inc; j++) - { - if(data[j] >= 32 && data[j] < 127) - { - buf.push(String.fromCharCode(data[j])); - } - else - { - buf.push('.'); - } - } - - buf.push("\"\n"); - } - - console.log(buf.join("")); -}; - -Ice.TraceUtil = TraceUtil; -module.exports.Ice = Ice; - function printIdentityFacetOperation(s, stream) { - var identity = new Identity(); + const identity = new Identity(); identity.__read(stream); s.push("\nidentity = " + Ice.identityToString(identity)); - var facet = Ice.StringSeqHelper.read(stream); + const facet = Ice.StringSeqHelper.read(stream); s.push("\nfacet = "); if(facet.length > 0) { s.push(StringUtil.escapeString(facet[0], "")); } - var operation = stream.readString(); + const operation = stream.readString(); s.push("\noperation = " + operation); } function printRequest(s, stream) { - var requestId = stream.readInt(); + const requestId = stream.readInt(); s.push("\nrequest id = " + requestId); if(requestId === 0) { @@ -211,10 +68,10 @@ function printRequest(s, stream) function printBatchRequest(s, stream) { - var batchRequestNum = stream.readInt(); + const batchRequestNum = stream.readInt(); s.push("\nnumber of requests = " + batchRequestNum); - for(var i = 0; i < batchRequestNum; ++i) + for(let i = 0; i < batchRequestNum; ++i) { s.push("\nrequest #" + i + ':'); printRequestHeader(s, stream); @@ -223,10 +80,10 @@ function printBatchRequest(s, stream) function printReply(s, stream) { - var requestId = stream.readInt(); + const requestId = stream.readInt(); s.push("\nrequest id = " + requestId); - var replyStatus = stream.readByte(); + const replyStatus = stream.readByte(); s.push("\nreply status = " + replyStatus + ' '); switch(replyStatus) @@ -309,7 +166,7 @@ function printReply(s, stream) } } - var unknown = stream.readString(); + const unknown = stream.readString(); s.push("\nunknown = " + unknown); break; } @@ -323,7 +180,7 @@ function printReply(s, stream) if(replyStatus === Protocol.replyOK || replyStatus === Protocol.replyUserException) { - var ver = stream.skipEncapsulation(); + const ver = stream.skipEncapsulation(); if(!ver.equals(Ice.Encoding_1_0)) { s.push("\nencoding = "); @@ -336,7 +193,7 @@ function printRequestHeader(s, stream) { printIdentityFacetOperation(s, stream); - var mode = stream.readByte(); + const mode = stream.readByte(); s.push("\nmode = " + mode + ' '); switch(OperationMode.valueOf(mode)) { @@ -365,12 +222,12 @@ function printRequestHeader(s, stream) } } - var sz = stream.readSize(); + let sz = stream.readSize(); s.push("\ncontext = "); while(sz-- > 0) { - var key = stream.readString(); - var value = stream.readString(); + const key = stream.readString(); + const value = stream.readString(); s.push(key + '/'+ value); if(sz > 0) { @@ -378,7 +235,7 @@ function printRequestHeader(s, stream) } } - var ver = stream.skipEncapsulation(); + const ver = stream.skipEncapsulation(); if(!ver.equals(Ice.Encoding_1_0)) { s.push("\nencoding = "); @@ -393,22 +250,22 @@ function printHeader(s, stream) stream.readByte(); stream.readByte(); -// var pMajor = stream.readByte(); -// var pMinor = stream.readByte(); +// const pMajor = stream.readByte(); +// const pMinor = stream.readByte(); // s.push("\nprotocol version = " + pMajor + "." + pMinor); stream.readByte(); // major stream.readByte(); // minor -// var eMajor = stream.readByte(); -// var eMinor = stream.readByte(); +// const eMajor = stream.readByte(); +// const eMinor = stream.readByte(); // s.push("\nencoding version = " + eMajor + "." + eMinor); stream.readByte(); // major stream.readByte(); // minor - var type = stream.readByte(); + const type = stream.readByte(); s.push("\nmessage type = " + type + " (" + getMessageTypeAsString(type) + ')'); - var compress = stream.readByte(); + const compress = stream.readByte(); s.push("\ncompression status = " + compress + ' '); switch(compress) { @@ -437,14 +294,14 @@ function printHeader(s, stream) } } - var size = stream.readInt(); + const size = stream.readInt(); s.push("\nmessage size = " + size); return type; } function printMessage(s, stream) { - var type = printHeader(s, stream); + const type = printHeader(s, stream); switch(type) { @@ -500,3 +357,143 @@ function getMessageTypeAsString(type) return "unknown"; } } + +class TraceUtil +{ + static traceSend(stream, logger, traceLevels) + { + if(traceLevels.protocol >= 1) + { + const p = stream.pos; + const is = new Ice.InputStream(stream.instance, stream.getEncoding(), stream.buffer); + is.pos = 0; + + const s = []; + const type = printMessage(s, is); + + logger.trace(traceLevels.protocolCat, "sending " + getMessageTypeAsString(type) + " " + s.join("")); + + stream.pos = p; + } + } + + static traceRecv(stream, logger, traceLevels) + { + if(traceLevels.protocol >= 1) + { + const p = stream.pos; + stream.pos = 0; + + const s = []; + const type = printMessage(s, stream); + + logger.trace(traceLevels.protocolCat, "received " + getMessageTypeAsString(type) + " " + s.join("")); + + stream.pos = p; + } + } + + static traceOut(heading, stream, logger, traceLevels) + { + if(traceLevels.protocol >= 1) + { + const p = stream.pos; + const is = new Ice.InputStream(stream.instance, stream.getEncoding(), stream.buffer); + is.pos = 0; + + const s = []; + s.push(heading); + printMessage(s, is); + + logger.trace(traceLevels.protocolCat, s.join("")); + stream.pos = p; + } + } + + static traceIn(heading, stream, logger, traceLevels) + { + if(traceLevels.protocol >= 1) + { + const p = stream.pos; + stream.pos = 0; + + const s = []; + s.push(heading); + printMessage(s, stream); + + logger.trace(traceLevels.protocolCat, s.join("")); + stream.pos = p; + } + } + + static dumpStream(stream) + { + const pos = stream.pos; + stream.pos = 0; + + const data = stream.readBlob(stream.size()); + TraceUtil.dumpOctets(data); + + stream.pos = pos; + } + + static dumpOctets(data) + { + const inc = 8; + const buf = []; + + for(let i = 0; i < data.length; i += inc) + { + for(let j = i; j - i < inc; j++) + { + if(j < data.length) + { + let n = data[j]; + if(n < 0) + { + n += 256; + } + let s; + if(n < 10) + { + s = " " + n; + } + else if(n < 100) + { + s = " " + n; + } + else + { + s = "" + n; + } + buf.push(s + " "); + } + else + { + buf.push(" "); + } + } + + buf.push('"'); + + for(let j = i; j < data.length && j - i < inc; j++) + { + if(data[j] >= 32 && data[j] < 127) + { + buf.push(String.fromCharCode(data[j])); + } + else + { + buf.push('.'); + } + } + + buf.push("\"\n"); + } + + console.log(buf.join("")); + } +} + +Ice.TraceUtil = TraceUtil; +module.exports.Ice = Ice; |