Best Python code snippet using avocado_python
UTF8Loader.js
Source:UTF8Loader.js
1/**2 * Loader for UTF8 version2 (after r51) encoded models generated by:3 * http://code.google.com/p/webgl-loader/4 *5 * Code to load/decompress mesh is taken from r100 of this webgl-loader6 */7THREE.UTF8Loader = function () {};8/**9 * Load UTF8 encoded model10 * @param jsonUrl - URL from which to load json containing information about model11 * @param callback - Callback(THREE.Object3D) on successful loading of model12 * @param options - options on how to load model (see THREE.MTLLoader.MaterialCreator for basic options)13 * Additional options include14 * geometryBase: Base url from which to load referenced geometries15 * materialBase: Base url from which to load referenced textures16 */17THREE.UTF8Loader.prototype.load = function ( jsonUrl, callback, options ) {18 this.downloadModelJson( jsonUrl, callback, options );19};20// BufferGeometryCreator21THREE.UTF8Loader.BufferGeometryCreator = function () {22};23THREE.UTF8Loader.BufferGeometryCreator.prototype.create = function ( attribArray, indices ) {24 var ntris = indices.length / 3;25 var geometry = new THREE.BufferGeometry();26 var positions = new Float32Array( ntris * 3 * 3 );27 var normals = new Float32Array( ntris * 3 * 3 );28 var uvs = new Float32Array( ntris * 3 * 2 );29 var i, j, offset;30 var end = attribArray.length;31 var stride = 8;32 // extract positions33 j = 0;34 offset = 0;35 for ( i = offset; i < end; i += stride ) {36 positions[ j ++ ] = attribArray[ i ];37 positions[ j ++ ] = attribArray[ i + 1 ];38 positions[ j ++ ] = attribArray[ i + 2 ];39 }40 // extract uvs41 j = 0;42 offset = 3;43 for ( i = offset; i < end; i += stride ) {44 uvs[ j ++ ] = attribArray[ i ];45 uvs[ j ++ ] = attribArray[ i + 1 ];46 }47 // extract normals48 j = 0;49 offset = 5;50 for ( i = offset; i < end; i += stride ) {51 normals[ j ++ ] = attribArray[ i ];52 normals[ j ++ ] = attribArray[ i + 1 ];53 normals[ j ++ ] = attribArray[ i + 2 ];54 }55 geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );56 geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );57 geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );58 geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );59 geometry.computeBoundingSphere();60 return geometry;61};62// UTF-8 decoder from webgl-loader (r100)63// http://code.google.com/p/webgl-loader/64// Model manifest description. Contains objects like:65// name: {66// materials: { 'material_name': { ... } ... },67// decodeParams: {68// decodeOffsets: [ ... ],69// decodeScales: [ ... ],70// },71// urls: {72// 'url': [73// { material: 'material_name',74// attribRange: [#, #],75// indexRange: [#, #],76// names: [ 'object names' ... ],77// lengths: [#, #, # ... ]78// }79// ],80// ...81// }82// }83var DEFAULT_DECODE_PARAMS = {84 decodeOffsets: [ -4095, -4095, -4095, 0, 0, -511, -511, -511 ],85 decodeScales: [ 1 / 8191, 1 / 8191, 1 / 8191, 1 / 1023, 1 / 1023, 1 / 1023, 1 / 1023, 1 / 1023 ]86 // TODO: normal decoding? (see walt.js)87 // needs to know: input, output (from vertex format!)88 //89 // Should split attrib/index.90 // 1) Decode position and non-normal attributes.91 // 2) Decode indices, computing normals92 // 3) Maybe normalize normals? Only necessary for refinement, or fixed?93 // 4) Maybe refine normals? Should this be part of regular refinement?94 // 5) Morphing95};96// Triangle strips!97// TODO: will it be an optimization to specialize this method at98// runtime for different combinations of stride, decodeOffset and99// decodeScale?100THREE.UTF8Loader.prototype.decompressAttribsInner_ = function ( str, inputStart, inputEnd,101 output, outputStart, stride,102 decodeOffset, decodeScale ) {103 var prev = 0;104 for ( var j = inputStart; j < inputEnd; j ++ ) {105 var code = str.charCodeAt( j );106 prev += ( code >> 1 ) ^ ( -( code & 1 ) );107 output[ outputStart ] = decodeScale * ( prev + decodeOffset );108 outputStart += stride;109 }110};111THREE.UTF8Loader.prototype.decompressIndices_ = function( str, inputStart, numIndices,112 output, outputStart ) {113 var highest = 0;114 for ( var i = 0; i < numIndices; i ++ ) {115 var code = str.charCodeAt( inputStart ++ );116 output[ outputStart ++ ] = highest - code;117 if ( code === 0 ) {118 highest ++;119 }120 }121};122THREE.UTF8Loader.prototype.decompressAABBs_ = function ( str, inputStart, numBBoxen,123 decodeOffsets, decodeScales ) {124 var numFloats = 6 * numBBoxen;125 var inputEnd = inputStart + numFloats;126 var outputStart = 0;127 var bboxen = new Float32Array( numFloats );128 for ( var i = inputStart; i < inputEnd; i += 6 ) {129 var minX = str.charCodeAt(i + 0) + decodeOffsets[0];130 var minY = str.charCodeAt(i + 1) + decodeOffsets[1];131 var minZ = str.charCodeAt(i + 2) + decodeOffsets[2];132 var radiusX = (str.charCodeAt(i + 3) + 1) >> 1;133 var radiusY = (str.charCodeAt(i + 4) + 1) >> 1;134 var radiusZ = (str.charCodeAt(i + 5) + 1) >> 1;135 bboxen[ outputStart ++ ] = decodeScales[0] * (minX + radiusX);136 bboxen[ outputStart ++ ] = decodeScales[1] * (minY + radiusY);137 bboxen[ outputStart ++ ] = decodeScales[2] * (minZ + radiusZ);138 bboxen[ outputStart ++ ] = decodeScales[0] * radiusX;139 bboxen[ outputStart ++ ] = decodeScales[1] * radiusY;140 bboxen[ outputStart ++ ] = decodeScales[2] * radiusZ;141 }142 return bboxen;143};144THREE.UTF8Loader.prototype.decompressMesh = function ( str, meshParams, decodeParams, name, idx, callback ) {145 // Extract conversion parameters from attribArrays.146 var stride = decodeParams.decodeScales.length;147 var decodeOffsets = decodeParams.decodeOffsets;148 var decodeScales = decodeParams.decodeScales;149 var attribStart = meshParams.attribRange[0];150 var numVerts = meshParams.attribRange[1];151 // Decode attributes.152 var inputOffset = attribStart;153 var attribsOut = new Float32Array( stride * numVerts );154 for (var j = 0; j < stride; j ++ ) {155 var end = inputOffset + numVerts;156 var decodeScale = decodeScales[j];157 if ( decodeScale ) {158 // Assume if decodeScale is never set, simply ignore the159 // attribute.160 this.decompressAttribsInner_( str, inputOffset, end,161 attribsOut, j, stride,162 decodeOffsets[j], decodeScale );163 }164 inputOffset = end;165 }166 var indexStart = meshParams.indexRange[ 0 ];167 var numIndices = 3 * meshParams.indexRange[ 1 ];168 var indicesOut = new Uint16Array( numIndices );169 this.decompressIndices_( str, inputOffset, numIndices, indicesOut, 0 );170 // Decode bboxen.171 var bboxen = undefined;172 var bboxOffset = meshParams.bboxes;173 if ( bboxOffset ) {174 bboxen = this.decompressAABBs_( str, bboxOffset, meshParams.names.length, decodeOffsets, decodeScales );175 }176 callback( name, idx, attribsOut, indicesOut, bboxen, meshParams );177};178THREE.UTF8Loader.prototype.copyAttrib = function ( stride, attribsOutFixed, lastAttrib, index ) {179 for ( var j = 0; j < stride; j ++ ) {180 lastAttrib[ j ] = attribsOutFixed[ stride * index + j ];181 }182};183THREE.UTF8Loader.prototype.decodeAttrib2 = function ( str, stride, decodeOffsets, decodeScales, deltaStart,184 numVerts, attribsOut, attribsOutFixed, lastAttrib,185 index ) {186 for ( var j = 0; j < 5; j ++ ) {187 var code = str.charCodeAt( deltaStart + numVerts * j + index );188 var delta = ( code >> 1) ^ (-(code & 1));189 lastAttrib[ j ] += delta;190 attribsOutFixed[ stride * index + j ] = lastAttrib[ j ];191 attribsOut[ stride * index + j ] = decodeScales[ j ] * ( lastAttrib[ j ] + decodeOffsets[ j ] );192 }193};194THREE.UTF8Loader.prototype.accumulateNormal = function ( i0, i1, i2, attribsOutFixed, crosses ) {195 var p0x = attribsOutFixed[ 8 * i0 ];196 var p0y = attribsOutFixed[ 8 * i0 + 1 ];197 var p0z = attribsOutFixed[ 8 * i0 + 2 ];198 var p1x = attribsOutFixed[ 8 * i1 ];199 var p1y = attribsOutFixed[ 8 * i1 + 1 ];200 var p1z = attribsOutFixed[ 8 * i1 + 2 ];201 var p2x = attribsOutFixed[ 8 * i2 ];202 var p2y = attribsOutFixed[ 8 * i2 + 1 ];203 var p2z = attribsOutFixed[ 8 * i2 + 2 ];204 p1x -= p0x;205 p1y -= p0y;206 p1z -= p0z;207 p2x -= p0x;208 p2y -= p0y;209 p2z -= p0z;210 p0x = p1y * p2z - p1z * p2y;211 p0y = p1z * p2x - p1x * p2z;212 p0z = p1x * p2y - p1y * p2x;213 crosses[ 3 * i0 ] += p0x;214 crosses[ 3 * i0 + 1 ] += p0y;215 crosses[ 3 * i0 + 2 ] += p0z;216 crosses[ 3 * i1 ] += p0x;217 crosses[ 3 * i1 + 1 ] += p0y;218 crosses[ 3 * i1 + 2 ] += p0z;219 crosses[ 3 * i2 ] += p0x;220 crosses[ 3 * i2 + 1 ] += p0y;221 crosses[ 3 * i2 + 2 ] += p0z;222};223THREE.UTF8Loader.prototype.decompressMesh2 = function( str, meshParams, decodeParams, name, idx, callback ) {224 var MAX_BACKREF = 96;225 // Extract conversion parameters from attribArrays.226 var stride = decodeParams.decodeScales.length;227 var decodeOffsets = decodeParams.decodeOffsets;228 var decodeScales = decodeParams.decodeScales;229 var deltaStart = meshParams.attribRange[ 0 ];230 var numVerts = meshParams.attribRange[ 1 ];231 var codeStart = meshParams.codeRange[ 0 ];232 var codeLength = meshParams.codeRange[ 1 ];233 var numIndices = 3 * meshParams.codeRange[ 2 ];234 var indicesOut = new Uint16Array( numIndices );235 var crosses = new Int32Array( 3 * numVerts );236 var lastAttrib = new Uint16Array( stride );237 var attribsOutFixed = new Uint16Array( stride * numVerts );238 var attribsOut = new Float32Array( stride * numVerts );239 var highest = 0;240 var outputStart = 0;241 for ( var i = 0; i < numIndices; i += 3 ) {242 var code = str.charCodeAt( codeStart ++ );243 var max_backref = Math.min( i, MAX_BACKREF );244 if ( code < max_backref ) {245 // Parallelogram246 var winding = code % 3;247 var backref = i - ( code - winding );248 var i0, i1, i2;249 switch ( winding ) {250 case 0:251 i0 = indicesOut[ backref + 2 ];252 i1 = indicesOut[ backref + 1 ];253 i2 = indicesOut[ backref + 0 ];254 break;255 case 1:256 i0 = indicesOut[ backref + 0 ];257 i1 = indicesOut[ backref + 2 ];258 i2 = indicesOut[ backref + 1 ];259 break;260 case 2:261 i0 = indicesOut[ backref + 1 ];262 i1 = indicesOut[ backref + 0 ];263 i2 = indicesOut[ backref + 2 ];264 break;265 }266 indicesOut[ outputStart ++ ] = i0;267 indicesOut[ outputStart ++ ] = i1;268 code = str.charCodeAt( codeStart ++ );269 var index = highest - code;270 indicesOut[ outputStart ++ ] = index;271 if ( code === 0 ) {272 for (var j = 0; j < 5; j ++ ) {273 var deltaCode = str.charCodeAt( deltaStart + numVerts * j + highest );274 var prediction = ((deltaCode >> 1) ^ (-(deltaCode & 1))) +275 attribsOutFixed[stride * i0 + j] +276 attribsOutFixed[stride * i1 + j] -277 attribsOutFixed[stride * i2 + j];278 lastAttrib[j] = prediction;279 attribsOutFixed[ stride * highest + j ] = prediction;280 attribsOut[ stride * highest + j ] = decodeScales[ j ] * ( prediction + decodeOffsets[ j ] );281 }282 highest ++;283 } else {284 this.copyAttrib( stride, attribsOutFixed, lastAttrib, index );285 }286 this.accumulateNormal( i0, i1, index, attribsOutFixed, crosses );287 } else {288 // Simple289 var index0 = highest - ( code - max_backref );290 indicesOut[ outputStart ++ ] = index0;291 if ( code === max_backref ) {292 this.decodeAttrib2( str, stride, decodeOffsets, decodeScales, deltaStart,293 numVerts, attribsOut, attribsOutFixed, lastAttrib,294 highest ++ );295 } else {296 this.copyAttrib(stride, attribsOutFixed, lastAttrib, index0);297 }298 code = str.charCodeAt( codeStart ++ );299 var index1 = highest - code;300 indicesOut[ outputStart ++ ] = index1;301 if ( code === 0 ) {302 this.decodeAttrib2( str, stride, decodeOffsets, decodeScales, deltaStart,303 numVerts, attribsOut, attribsOutFixed, lastAttrib,304 highest ++ );305 } else {306 this.copyAttrib( stride, attribsOutFixed, lastAttrib, index1 );307 }308 code = str.charCodeAt( codeStart ++ );309 var index2 = highest - code;310 indicesOut[ outputStart ++ ] = index2;311 if ( code === 0 ) {312 for ( var j = 0; j < 5; j ++ ) {313 lastAttrib[ j ] = ( attribsOutFixed[ stride * index0 + j ] + attribsOutFixed[ stride * index1 + j ] ) / 2;314 }315 this.decodeAttrib2( str, stride, decodeOffsets, decodeScales, deltaStart,316 numVerts, attribsOut, attribsOutFixed, lastAttrib,317 highest ++ );318 } else {319 this.copyAttrib( stride, attribsOutFixed, lastAttrib, index2 );320 }321 this.accumulateNormal( index0, index1, index2, attribsOutFixed, crosses );322 }323 }324 for ( var i = 0; i < numVerts; i ++ ) {325 var nx = crosses[ 3 * i ];326 var ny = crosses[ 3 * i + 1 ];327 var nz = crosses[ 3 * i + 2 ];328 var norm = 511.0 / Math.sqrt( nx * nx + ny * ny + nz * nz );329 var cx = str.charCodeAt( deltaStart + 5 * numVerts + i );330 var cy = str.charCodeAt( deltaStart + 6 * numVerts + i );331 var cz = str.charCodeAt( deltaStart + 7 * numVerts + i );332 attribsOut[ stride * i + 5 ] = norm * nx + ((cx >> 1) ^ (-(cx & 1)));333 attribsOut[ stride * i + 6 ] = norm * ny + ((cy >> 1) ^ (-(cy & 1)));334 attribsOut[ stride * i + 7 ] = norm * nz + ((cz >> 1) ^ (-(cz & 1)));335 }336 callback( name, idx, attribsOut, indicesOut, undefined, meshParams );337};338THREE.UTF8Loader.prototype.downloadMesh = function ( path, name, meshEntry, decodeParams, callback ) {339 var loader = this;340 var idx = 0;341 function onprogress( data ) {342 while ( idx < meshEntry.length ) {343 var meshParams = meshEntry[ idx ];344 var indexRange = meshParams.indexRange;345 if ( indexRange ) {346 var meshEnd = indexRange[ 0 ] + 3 * indexRange[ 1 ];347 if ( data.length < meshEnd ) break;348 loader.decompressMesh( data, meshParams, decodeParams, name, idx, callback );349 } else {350 var codeRange = meshParams.codeRange;351 var meshEnd = codeRange[ 0 ] + codeRange[ 1 ];352 if ( data.length < meshEnd ) break;353 loader.decompressMesh2( data, meshParams, decodeParams, name, idx, callback );354 }355 ++ idx;356 }357 }358 getHttpRequest( path, function( data ) {359 onprogress( data );360 // TODO: handle errors.361 });362};363THREE.UTF8Loader.prototype.downloadMeshes = function ( path, meshUrlMap, decodeParams, callback ) {364 for ( var url in meshUrlMap ) {365 var meshEntry = meshUrlMap[url];366 this.downloadMesh( path + url, url, meshEntry, decodeParams, callback );367 }368};369THREE.UTF8Loader.prototype.createMeshCallback = function( materialBaseUrl, loadModelInfo, allDoneCallback ) {370 var nCompletedUrls = 0;371 var nExpectedUrls = 0;372 var expectedMeshesPerUrl = {};373 var decodedMeshesPerUrl = {};374 var modelParts = {};375 var meshUrlMap = loadModelInfo.urls;376 for ( var url in meshUrlMap ) {377 expectedMeshesPerUrl[ url ] = meshUrlMap[ url ].length;378 decodedMeshesPerUrl[ url ] = 0;379 nExpectedUrls ++;380 modelParts[ url ] = new THREE.Object3D();381 }382 var model = new THREE.Object3D();383 // Prepare materials first...384 var materialCreator = new THREE.MTLLoader.MaterialCreator( materialBaseUrl, loadModelInfo.options );385 materialCreator.setMaterials( loadModelInfo.materials );386 materialCreator.preload();387 // Create callback for creating mesh parts388 var bufferGeometryCreator = new THREE.UTF8Loader.BufferGeometryCreator();389 var meshCallback = function( name, idx, attribArray, indexArray, bboxen, meshParams ) {390 // Got ourselves a new mesh391 // name identifies this part of the model (url)392 // idx is the mesh index of this mesh of the part393 // attribArray defines the vertices394 // indexArray defines the faces395 // bboxen defines the bounding box396 // meshParams contains the material info397 var geometry = bufferGeometryCreator.create( attribArray, indexArray );398 var material = materialCreator.create( meshParams.material );399 var mesh = new THREE.Mesh( geometry, material );400 modelParts[ name ].add( mesh );401 //model.add(new THREE.Mesh(geometry, material));402 decodedMeshesPerUrl[ name ] ++;403 if ( decodedMeshesPerUrl[ name ] === expectedMeshesPerUrl[ name ] ) {404 nCompletedUrls ++;405 model.add( modelParts[ name ] );406 if ( nCompletedUrls === nExpectedUrls ) {407 // ALL DONE!!!408 allDoneCallback( model );409 }410 }411 };412 return meshCallback;413};414THREE.UTF8Loader.prototype.downloadModel = function ( geometryBase, materialBase, model, callback ) {415 var meshCallback = this.createMeshCallback( materialBase, model, callback );416 this.downloadMeshes( geometryBase, model.urls, model.decodeParams, meshCallback );417};418THREE.UTF8Loader.prototype.downloadModelJson = function ( jsonUrl, callback, options ) {419 getJsonRequest( jsonUrl, function( loaded ) {420 if ( ! loaded.decodeParams ) {421 if ( options && options.decodeParams ) {422 loaded.decodeParams = options.decodeParams;423 } else {424 loaded.decodeParams = DEFAULT_DECODE_PARAMS;425 }426 }427 loaded.options = options;428 var geometryBase = jsonUrl.substr( 0, jsonUrl.lastIndexOf( "/" ) + 1 );429 var materialBase = geometryBase;430 if ( options && options.geometryBase ) {431 geometryBase = options.geometryBase;432 if ( geometryBase.charAt( geometryBase.length - 1 ) !== "/" ) {433 geometryBase = geometryBase + "/";434 }435 }436 if ( options && options.materialBase ) {437 materialBase = options.materialBase;438 if ( materialBase.charAt( materialBase.length - 1 ) !== "/" ) {439 materialBase = materialBase + "/";440 }441 }442 this.downloadModel( geometryBase, materialBase, loaded, callback );443 }.bind( this ) );444};445// XMLHttpRequest stuff446function getHttpRequest( url, onload, opt_onprogress ) {447 var req = new THREE.XHRLoader();448 req.load( url, onload, opt_onprogress );449}450function getJsonRequest( url, onjson ) {451 getHttpRequest( url,452 function( e ) { onjson( JSON.parse( e ) ); },453 function() {} );454}455function addListeners( dom, listeners ) {456 // TODO: handle event capture, object binding.457 for ( var key in listeners ) {458 dom.addEventListener( key, listeners[ key ] );459 }...
replay-dump.py
Source:replay-dump.py
...67 "Read a 64 bit word"68 return struct.unpack('>Q', fin.read(8))[0]69# Generic decoder structure70Decoder = namedtuple("Decoder", "eid name fn")71def call_decode(table, index, dumpfile):72 "Search decode table for next step"73 decoder = next((d for d in table if d.eid == index), None)74 if not decoder:75 print("Could not decode index: %d" % (index))76 print("Entry is: %s" % (decoder))77 print("Decode Table is:\n%s" % (table))78 return False79 else:80 return decoder.fn(decoder.eid, decoder.name, dumpfile)81# Print event82def print_event(eid, name, string=None, event_count=None):83 "Print event with count"84 if not event_count:85 event_count = replay_state.event_count86 if string:87 print("%d:%s(%d) %s" % (event_count, name, eid, string))88 else:89 print("%d:%s(%d)" % (event_count, name, eid))90# Decoders for each event type91def decode_unimp(eid, name, _unused_dumpfile):92 "Unimplimented decoder, will trigger exit"93 print("%s not handled - will now stop" % (name))94 return False95# Checkpoint decoder96def swallow_async_qword(eid, name, dumpfile):97 "Swallow a qword of data without looking at it"98 step_id = read_qword(dumpfile)99 print(" %s(%d) @ %d" % (name, eid, step_id))100 return True101async_decode_table = [ Decoder(0, "REPLAY_ASYNC_EVENT_BH", swallow_async_qword),102 Decoder(1, "REPLAY_ASYNC_INPUT", decode_unimp),103 Decoder(2, "REPLAY_ASYNC_INPUT_SYNC", decode_unimp),104 Decoder(3, "REPLAY_ASYNC_CHAR_READ", decode_unimp),105 Decoder(4, "REPLAY_ASYNC_EVENT_BLOCK", decode_unimp),106 Decoder(5, "REPLAY_ASYNC_EVENT_NET", decode_unimp),107]108# See replay_read_events/replay_read_event109def decode_async(eid, name, dumpfile):110 """Decode an ASYNC event"""111 print_event(eid, name)112 async_event_kind = read_byte(dumpfile)113 async_event_checkpoint = read_byte(dumpfile)114 if async_event_checkpoint != replay_state.current_checkpoint:115 print(" mismatch between checkpoint %d and async data %d" % (116 replay_state.current_checkpoint, async_event_checkpoint))117 return True118 return call_decode(async_decode_table, async_event_kind, dumpfile)119def decode_instruction(eid, name, dumpfile):120 ins_diff = read_dword(dumpfile)121 print_event(eid, name, "0x%x" % (ins_diff))122 return True123def decode_audio_out(eid, name, dumpfile):124 audio_data = read_dword(dumpfile)125 print_event(eid, name, "%d" % (audio_data))126 return True127def decode_checkpoint(eid, name, dumpfile):128 """Decode a checkpoint.129 Checkpoints contain a series of async events with their own specific data.130 """131 replay_state.set_checkpoint()132 # save event count as we peek ahead133 event_number = replay_state.event_count134 next_event = read_event(dumpfile)135 # if the next event is EVENT_ASYNC there are a bunch of136 # async events to read, otherwise we are done137 if next_event != 3:138 print_event(eid, name, "no additional data", event_number)139 else:140 print_event(eid, name, "more data follows", event_number)141 replay_state.reuse_event(next_event)142 return True143def decode_checkpoint_init(eid, name, dumpfile):144 print_event(eid, name)145 return True146def decode_interrupt(eid, name, dumpfile):147 print_event(eid, name)148 return True149def decode_clock(eid, name, dumpfile):150 clock_data = read_qword(dumpfile)151 print_event(eid, name, "0x%x" % (clock_data))152 return True153# pre-MTTCG merge154v5_event_table = [Decoder(0, "EVENT_INSTRUCTION", decode_instruction),155 Decoder(1, "EVENT_INTERRUPT", decode_interrupt),156 Decoder(2, "EVENT_EXCEPTION", decode_unimp),157 Decoder(3, "EVENT_ASYNC", decode_async),158 Decoder(4, "EVENT_SHUTDOWN", decode_unimp),159 Decoder(5, "EVENT_CHAR_WRITE", decode_unimp),160 Decoder(6, "EVENT_CHAR_READ_ALL", decode_unimp),161 Decoder(7, "EVENT_CHAR_READ_ALL_ERROR", decode_unimp),162 Decoder(8, "EVENT_CLOCK_HOST", decode_clock),163 Decoder(9, "EVENT_CLOCK_VIRTUAL_RT", decode_clock),164 Decoder(10, "EVENT_CP_CLOCK_WARP_START", decode_checkpoint),165 Decoder(11, "EVENT_CP_CLOCK_WARP_ACCOUNT", decode_checkpoint),166 Decoder(12, "EVENT_CP_RESET_REQUESTED", decode_checkpoint),167 Decoder(13, "EVENT_CP_SUSPEND_REQUESTED", decode_checkpoint),168 Decoder(14, "EVENT_CP_CLOCK_VIRTUAL", decode_checkpoint),169 Decoder(15, "EVENT_CP_CLOCK_HOST", decode_checkpoint),170 Decoder(16, "EVENT_CP_CLOCK_VIRTUAL_RT", decode_checkpoint),171 Decoder(17, "EVENT_CP_INIT", decode_checkpoint_init),172 Decoder(18, "EVENT_CP_RESET", decode_checkpoint),173]174# post-MTTCG merge, AUDIO support added175v6_event_table = [Decoder(0, "EVENT_INSTRUCTION", decode_instruction),176 Decoder(1, "EVENT_INTERRUPT", decode_interrupt),177 Decoder(2, "EVENT_EXCEPTION", decode_unimp),178 Decoder(3, "EVENT_ASYNC", decode_async),179 Decoder(4, "EVENT_SHUTDOWN", decode_unimp),180 Decoder(5, "EVENT_CHAR_WRITE", decode_unimp),181 Decoder(6, "EVENT_CHAR_READ_ALL", decode_unimp),182 Decoder(7, "EVENT_CHAR_READ_ALL_ERROR", decode_unimp),183 Decoder(8, "EVENT_AUDIO_OUT", decode_audio_out),184 Decoder(9, "EVENT_AUDIO_IN", decode_unimp),185 Decoder(10, "EVENT_CLOCK_HOST", decode_clock),186 Decoder(11, "EVENT_CLOCK_VIRTUAL_RT", decode_clock),187 Decoder(12, "EVENT_CP_CLOCK_WARP_START", decode_checkpoint),188 Decoder(13, "EVENT_CP_CLOCK_WARP_ACCOUNT", decode_checkpoint),189 Decoder(14, "EVENT_CP_RESET_REQUESTED", decode_checkpoint),190 Decoder(15, "EVENT_CP_SUSPEND_REQUESTED", decode_checkpoint),191 Decoder(16, "EVENT_CP_CLOCK_VIRTUAL", decode_checkpoint),192 Decoder(17, "EVENT_CP_CLOCK_HOST", decode_checkpoint),193 Decoder(18, "EVENT_CP_CLOCK_VIRTUAL_RT", decode_checkpoint),194 Decoder(19, "EVENT_CP_INIT", decode_checkpoint_init),195 Decoder(20, "EVENT_CP_RESET", decode_checkpoint),196]197# Shutdown cause added198v7_event_table = [Decoder(0, "EVENT_INSTRUCTION", decode_instruction),199 Decoder(1, "EVENT_INTERRUPT", decode_interrupt),200 Decoder(2, "EVENT_EXCEPTION", decode_unimp),201 Decoder(3, "EVENT_ASYNC", decode_async),202 Decoder(4, "EVENT_SHUTDOWN", decode_unimp),203 Decoder(5, "EVENT_SHUTDOWN_HOST_ERR", decode_unimp),204 Decoder(6, "EVENT_SHUTDOWN_HOST_QMP", decode_unimp),205 Decoder(7, "EVENT_SHUTDOWN_HOST_SIGNAL", decode_unimp),206 Decoder(8, "EVENT_SHUTDOWN_HOST_UI", decode_unimp),207 Decoder(9, "EVENT_SHUTDOWN_GUEST_SHUTDOWN", decode_unimp),208 Decoder(10, "EVENT_SHUTDOWN_GUEST_RESET", decode_unimp),209 Decoder(11, "EVENT_SHUTDOWN_GUEST_PANIC", decode_unimp),210 Decoder(12, "EVENT_SHUTDOWN___MAX", decode_unimp),211 Decoder(13, "EVENT_CHAR_WRITE", decode_unimp),212 Decoder(14, "EVENT_CHAR_READ_ALL", decode_unimp),213 Decoder(15, "EVENT_CHAR_READ_ALL_ERROR", decode_unimp),214 Decoder(16, "EVENT_AUDIO_OUT", decode_audio_out),215 Decoder(17, "EVENT_AUDIO_IN", decode_unimp),216 Decoder(18, "EVENT_CLOCK_HOST", decode_clock),217 Decoder(19, "EVENT_CLOCK_VIRTUAL_RT", decode_clock),218 Decoder(20, "EVENT_CP_CLOCK_WARP_START", decode_checkpoint),219 Decoder(21, "EVENT_CP_CLOCK_WARP_ACCOUNT", decode_checkpoint),220 Decoder(22, "EVENT_CP_RESET_REQUESTED", decode_checkpoint),221 Decoder(23, "EVENT_CP_SUSPEND_REQUESTED", decode_checkpoint),222 Decoder(24, "EVENT_CP_CLOCK_VIRTUAL", decode_checkpoint),223 Decoder(25, "EVENT_CP_CLOCK_HOST", decode_checkpoint),224 Decoder(26, "EVENT_CP_CLOCK_VIRTUAL_RT", decode_checkpoint),225 Decoder(27, "EVENT_CP_INIT", decode_checkpoint_init),226 Decoder(28, "EVENT_CP_RESET", decode_checkpoint),227]228def parse_arguments():229 "Grab arguments for script"230 parser = argparse.ArgumentParser()231 parser.add_argument("-f", "--file", help='record/replay dump to read from',232 required=True)233 return parser.parse_args()234def decode_file(filename):235 "Decode a record/replay dump"236 dumpfile = open(filename, "rb")237 # read and throwaway the header238 version = read_dword(dumpfile)239 junk = read_qword(dumpfile)240 print("HEADER: version 0x%x" % (version))241 if version == 0xe02007:242 event_decode_table = v7_event_table243 replay_state.checkpoint_start = 12244 elif version == 0xe02006:245 event_decode_table = v6_event_table246 replay_state.checkpoint_start = 12247 else:248 event_decode_table = v5_event_table249 replay_state.checkpoint_start = 10250 try:251 decode_ok = True252 while decode_ok:253 event = read_event(dumpfile)254 decode_ok = call_decode(event_decode_table, event, dumpfile)255 finally:256 dumpfile.close()257if __name__ == "__main__":258 args = parse_arguments()...
index.js
Source:index.js
...9 * @param data String to decode.10 * @param level Optional level to decode at. 0 = XML, 1 = HTML. Default is 0.11 * @deprecated Use `decodeXML` or `decodeHTML` directly.12 */13function decode(data, level) {14 return (!level || level <= 0 ? decode_1.decodeXML : decode_1.decodeHTML)(data);15}16exports.decode = decode;17/**18 * Decodes a string with entities. Does not allow missing trailing semicolons for entities.19 *20 * @param data String to decode.21 * @param level Optional level to decode at. 0 = XML, 1 = HTML. Default is 0.22 * @deprecated Use `decodeHTMLStrict` or `decodeXML` directly.23 */24function decodeStrict(data, level) {25 return (!level || level <= 0 ? decode_1.decodeXML : decode_1.decodeHTMLStrict)(data);26}27exports.decodeStrict = decodeStrict;...
encode_decode_uri.js
Source:encode_decode_uri.js
1// --------------------------------------------------------------------------------2var resolution = 251; // set to 1 for 100% coverage3function checkEncodeException(encodeFunctionName,c1,c2)4{5 if (c2 == undefined)6 shouldThrow(encodeFunctionName7 + "(String.fromCharCode(" + c1 + "))");8 else9 shouldThrow(encodeFunctionName10 + "(String.fromCharCode(" + c1 + ") + String.fromCharCode(" + c2 + "))");11}12function checkEncodeDecode(encodeFunctionName, decodeFunctionName, c1, c2)13{14 if (c2 == undefined)15 shouldBe(decodeFunctionName + "(" + encodeFunctionName16 + "(String.fromCharCode(" + c1 + ")))",17 "String.fromCharCode(" + c1 + ")");18 else19 shouldBe(decodeFunctionName + "(" + encodeFunctionName20 + "(String.fromCharCode(" + c1 + ") + String.fromCharCode(" + c2 + ")))",21 "String.fromCharCode(" + c1 + ") + String.fromCharCode(" + c2 + ")");22}23function checkWithFunctions(encodeFunction, decodeFunction)24{25 checkEncodeDecode(encodeFunction, decodeFunction, 0);26 checkEncodeDecode(encodeFunction, decodeFunction, 0xD7FF);27 checkEncodeDecode(encodeFunction, decodeFunction, 0xE000);28 checkEncodeDecode(encodeFunction, decodeFunction, 0xFFFD);29 checkEncodeDecode(encodeFunction, decodeFunction, 0xFFFE);30 checkEncodeDecode(encodeFunction, decodeFunction, 0xFFFF);31 checkEncodeException(encodeFunction, 0xDC00);32 checkEncodeException(encodeFunction, 0xDFFF);33 checkEncodeDecode(encodeFunction, decodeFunction, 0xD800, 0xDC00);34 checkEncodeDecode(encodeFunction, decodeFunction, 0xDBFF, 0xDC00);35 checkEncodeDecode(encodeFunction, decodeFunction, 0xD800, 0xDFFF);36 checkEncodeDecode(encodeFunction, decodeFunction, 0xDBFF, 0xDFFF);37 checkEncodeException(encodeFunction, 0xD800, 0);38 checkEncodeException(encodeFunction, 0xD800, 0xD7FF);39 checkEncodeException(encodeFunction, 0xD800, 0xD800);40 checkEncodeException(encodeFunction, 0xD800, 0xDBFF);41 checkEncodeException(encodeFunction, 0xD800, 0xE000);42 checkEncodeException(encodeFunction, 0xD800, 0xE000);43 checkEncodeException(encodeFunction, 0xD800, 0xFFFD);44 checkEncodeException(encodeFunction, 0xD800, 0xFFFE);45 checkEncodeException(encodeFunction, 0xD800, 0xFFFF);46 for (var charcode = 1; charcode < 0xD7FF; charcode += resolution)47 checkEncodeDecode(encodeFunction, decodeFunction, charcode);48 for (var charcode = 0xE001; charcode < 0xFFFD; charcode += resolution)49 checkEncodeDecode(encodeFunction, decodeFunction, charcode);50 for (var charcode = 0xDC01; charcode < 0xDFFF; charcode += resolution)51 checkEncodeException(encodeFunction, charcode);52 for (var charcode = 0xD801; charcode < 0xDBFF; charcode += resolution)53 checkEncodeDecode(encodeFunction, decodeFunction, charcode, 0xDC00);54 for (var charcode = 0xDC01; charcode < 0xDFFF; charcode += resolution)55 checkEncodeDecode(encodeFunction, decodeFunction, 0xD800, charcode);56 for (var charcode = 1; charcode < 0xDBFF; charcode += resolution)57 checkEncodeException(encodeFunction, 0xD800, charcode);58 for (var charcode = 0xE001; charcode < 0xFFFD; charcode += resolution)59 checkEncodeException(encodeFunction, 0xD800, charcode);60}61checkWithFunctions("encodeURI", "decodeURI");62checkWithFunctions("encodeURIComponent", "decodeURIComponent");...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!