@ -1,70 +1,15 @@
/*jslint laxbreak:true */
/*jslint laxcomma:true */
/*jslint loopfunc:true */
/*jslint strict:true */
define ( [
"toolbox"
"underscore"
, "toolbox"
]
, function ( Toolbox ) {
var that
, typeMap = {
1 : {
length : 1
, unpack : Types . getInt8
}
, function ( _ , Toolbox ) {
"use strict" ;
, 2 : {
length : 1
, unpack : Types . getUint8
}
, 3 : {
length : 2
, unpack : Types . getInt16
}
, 4 : {
length : 2
, unpack : Types . getUint16
}
, 5 : {
length : 4
, unpack : Types . getInt32
}
, 6 : {
length : 4
, unpack : Types . getUint32
}
, 7 : {
length : 8
, unpack : Types . getFloat64
}
// There is no unsigned 64bit integer in JS.
, 8 : {
length : 8
, unpack : Types . getFloat64
}
, 9 : {
length : null
, unpack : Types . getUTFString
}
, 10 : {
length : 4
, unpack : Types . getDate
}
, 11 : {
length : 2
, unpack : Types . getVersion
}
, 12 : {
length : null
, unpack : Types . getCollection
}
}
var that
, Types = Toolbox . Base . extend ( {
constructor : function ( code ) {
@ -73,8 +18,8 @@ define([
;
if ( _ . isNumber ( code ) ) {
if ( ! _ . isUndefined ( typeMap[ code ] ) ) {
_ . extend ( this , typeMap[ code ] ) ;
if ( ! _ . isUndefined ( Types. typeMap[ code ] ) ) {
_ . extend ( this , Types. typeMap[ code ] ) ;
} else {
}
@ -94,39 +39,129 @@ define([
, getByteLength : function ( ) {
return this . length ;
}
}
, {
getInt8 : function ( chunk ) {
return new DataView ( chunk . slice ( 0 , typeMap [ 1 ] . length ) ) . getInt8 ( 0 , false ) ;
typeMap : {
1 : {
length : 1
, unpack : function ( chunk ) {
Types . getInt8 ( chunk ) ;
}
}
, 2 : {
length : 1
, unpack : function ( chunk ) {
Types . getUint8 ( chunk ) ;
}
}
, 3 : {
length : 2
, unpack : function ( chunk ) {
Types . getInt16 ( chunk ) ;
}
}
, 4 : {
length : 2
, unpack : function ( chunk ) {
Types . getUint16 ( chunk ) ;
}
}
, 5 : {
length : 4
, unpack : function ( chunk ) {
Types . getInt32 ( chunk ) ;
}
}
, 6 : {
length : 4
, unpack : function ( chunk ) {
Types . getUint32 ( chunk ) ;
}
}
, 7 : {
length : 8
, unpack : function ( chunk ) {
Types . getFloat64 ( chunk ) ;
}
}
// There is no unsigned 64bit integer in JS.
, 8 : {
length : 8
, unpack : function ( chunk ) {
Types . getFloat64 ( chunk ) ;
}
}
, 9 : {
length : null
, unpack : function ( chunk , length ) {
Types . getUTFString ( chunk , length ) ;
}
}
, 10 : {
length : 4
, unpack : function ( chunk ) {
Types . getDate ( chunk ) ;
}
}
, 11 : {
length : 2
, unpack : function ( chunk ) {
Types . getVersion ( chunk ) ;
}
}
, 12 : {
length : null
, unpack : function ( chunk , length ) {
Types . getModel ( chunk , length ) ;
}
}
}
, getInt8 : function ( chunk ) {
return new DataView ( chunk . slice ( 0 , Types . typeMap [ 1 ] . length ) ) . getInt8 ( 0 , false ) ;
}
, getUint8 : function ( chunk ) {
return new DataView ( chunk . slice ( 0 , typeMap [ 2 ] . length ) ) . getUint8 ( 0 , false ) ;
return new DataView ( chunk . slice ( 0 , Types. typeMap[ 2 ] . length ) ) . getUint8 ( 0 , false ) ;
}
, getInt16 : function ( chunk ) {
return new DataView ( chunk . slice ( 0 , typeMap [ 3 ] . length ) ) . getInt16 ( 0 , false ) ;
return new DataView ( chunk . slice ( 0 , Types. typeMap[ 3 ] . length ) ) . getInt16 ( 0 , false ) ;
}
, getUint16 : function ( chunk ) {
return new DataView ( chunk . slice ( 0 , typeMap [ 4 ] . length ) ) . getUint16 ( 0 , false ) ;
return new DataView ( chunk . slice ( 0 , Types. typeMap[ 4 ] . length ) ) . getUint16 ( 0 , false ) ;
}
, getInt32 : function ( chunk ) {
return new DataView ( chunk . slice ( 0 , typeMap [ 5 ] . length ) ) . getInt32 ( 0 , false ) ;
return new DataView ( chunk . slice ( 0 , Types. typeMap[ 5 ] . length ) ) . getInt32 ( 0 , false ) ;
}
, getUint32 : function ( chunk ) {
return new DataView ( chunk . slice ( 0 , typeMap [ 6 ] . length ) ) . getUint32 ( 0 , false ) ;
return new DataView ( chunk . slice ( 0 , Types. typeMap[ 6 ] . length ) ) . getUint32 ( 0 , false ) ;
}
, getFloat64 : function ( chunk ) {
return new DataView ( chunk . slice ( 0 , typeMap [ 7 ] . length ) ) . getFloat64 ( 0 , false ) ;
return new DataView ( chunk . slice ( 0 , Types. typeMap[ 7 ] . length ) ) . getFloat64 ( 0 , false ) ;
}
, getString : function ( chunk , length ) {
if ( ! _ . isNumber ( length ) || length > chunk . byteLength ) {
var length = chunk . byteLength ;
length = chunk . byteLength ;
}
return String . fromCharCode . apply ( null , new Uint8Array ( chunk . slice ( 0 , length ) ) ) ;
@ -136,7 +171,7 @@ define([
, getUTFString : function ( chunk , length ) {
var str = '' ;
if ( ! _ . isNumber ( length ) || length > chunk . byteLength ) {
var length = chunk . byteLength ;
length = chunk . byteLength ;
}
for ( var i = 0 ; i < length ; i ++ ) {
@ -166,7 +201,9 @@ define([
, getUnknown : function ( chunk ) {
// Unimplemented
/ * s w i t c h ( c h u n k . b y t e L e n g t h ) {
throw "ERROR_UNIMPLEMENTED" ;
/ *
switch ( chunk . byteLength ) {
// We can tring a string
default :