<commit_before>/**
 * AMF deserializer
 */

/** dependencies */ 
var amf = require('./amf');
var utils = require('./utils');
var utf8 = require('./utf8');
var bin = require('./bin');


/** export constructor */
exports.AMFDeserializer = AMFDeserializer;



// ----------------------------------

 

/** Constructor */
function AMFDeserializer( src ){
	this.s = src || '';
	this.i = 0;
	this.resetRefs();
	this.beParser = bin.parser( true, true );  // <- big endian binary unpacker
	this.leParser = bin.parser( false, true ); // <- little endian binary unpacker
}



/** */
AMFDeserializer.prototype.resetRefs = function(){
	this.refObj = []; // object references
	this.refStr = []; // string references
	this.refTra = []; // trait references
}



/** */
AMFDeserializer.prototype.shiftBytes = function( n ){
	if( n === 0 ){
		return '';
	} 
	var s = this.s.slice( 0, n );
	if( s.length !== n ){
		throw new Error("Not enough input to read "+n+" bytes, got "+s.length+", offset "+this.i);
	}
	this.s = this.s.slice(n);
	this.i += n;
	return s;
}
	
	
/** */	
AMFDeserializer.prototype.readU8 = function(){
	var s = this.shiftBytes(1);
	return s.charCodeAt(0);
}


/** */
AMFDeserializer.prototype.readU16 = function (){
	var s = this.shiftBytes(2);
	return this.beParser.toWord( s );
}


/** */
AMFDeserializer.prototype.readU32 = function(){
	var s = this.shiftBytes(4);
	return this.beParser.toDWord( s );
}


/** */
AMFDeserializer.prototype.readDouble = function(){
	var s = this.shiftBytes(8);
	return this.leParser.toDouble( s );
}


/** */
AMFDeserializer.prototype.readU29 = function(){
	var i;
	var n = 0;
	var t = 0;
	while ( true ){
		if( t++ === 4 ){
			throw new Error("U29 range error, offset "+this.i);
		}
		i = this.readU8();
		// next byte is part of the sequence if high bit is set
		if( i & 0x80 && t !== 4 ){
			n = ( n << 7) | (i & 0x7F);
			continue;
		}
		// else is final, partial byte
		else if ( t !== 4 ){
			n = (n << 7) | i;
			break;
		}
		// else is final, full byte
		else {
			n = (n << 8) | i;<commit_msg>fixed endian bug in readDouble<commit_after>/**
 * AMF deserializer
 */

/** dependencies */ 
var amf = require('./amf');
var utils = require('./utils');
var utf8 = require('./utf8');
var bin = require('./bin');


/** export constructor */
exports.AMFDeserializer = AMFDeserializer;



// ----------------------------------

 

/** Constructor */
function AMFDeserializer( src ){
	this.s = src || '';
	this.i = 0;
	this.resetRefs();
	this.beParser = bin.parser( true, true );  // <- big endian binary unpacker
	this.leParser = bin.parser( false, true ); // <- little endian binary unpacker
}



/** */
AMFDeserializer.prototype.resetRefs = function(){
	this.refObj = []; // object references
	this.refStr = []; // string references
	this.refTra = []; // trait references
}



/** */
AMFDeserializer.prototype.shiftBytes = function( n ){
	if( n === 0 ){
		return '';
	} 
	var s = this.s.slice( 0, n );
	if( s.length !== n ){
		throw new Error("Not enough input to read "+n+" bytes, got "+s.length+", offset "+this.i);
	}
	this.s = this.s.slice(n);
	this.i += n;
	return s;
}
	
	
/** */	
AMFDeserializer.prototype.readU8 = function(){
	var s = this.shiftBytes(1);
	return s.charCodeAt(0);
}


/** */
AMFDeserializer.prototype.readU16 = function (){
	var s = this.shiftBytes(2);
	return this.beParser.toWord( s );
}


/** */
AMFDeserializer.prototype.readU32 = function(){
	var s = this.shiftBytes(4);
	return this.beParser.toDWord( s );
}


/** */
AMFDeserializer.prototype.readDouble = function(){
	var s = this.shiftBytes(8);
	return this.beParser.toDouble( s );
}


/** */
AMFDeserializer.prototype.readU29 = function(){
	var i;
	var n = 0;
	var t = 0;
	while ( true ){
		if( t++ === 4 ){
			throw new Error("U29 range error, offset "+this.i);
		}
		i = this.readU8();
		// next byte is part of the sequence if high bit is set
		if( i & 0x80 && t !== 4 ){
			n = ( n << 7) | (i & 0x7F);
			continue;
		}
		// else is final, partial byte
		else if ( t !== 4 ){
			n = (n << 7) | i;
			break;
		}
		// else is final, full byte
		else {
			n = (n << 8) | i;
{'fraction_non_alphanumeric': 0.20278524309797213, 'fraction_numerical': 0.016125091619838747, 'mean_word_length': 2.7388127853881277, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2096518', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1475, 'n_words': 387}