1
0
Fork 0

FIXED - DMAPType

master
Matthieu Lalonde 12 years ago committed by xSmurf
parent d4ef8101f2
commit dcfb1307cc

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

Loading…
Cancel
Save