added arrayParser

This commit is contained in:
Alexander Sulfrian 2011-01-28 18:06:05 +01:00
parent d5538816ef
commit 37e958f779

View File

@ -326,6 +326,72 @@ var parseDate = function(value) {
return new Date((((sign == 0) ? 1 : -1) * rawValue / 1000) + 946684800000);
}
var arrayParser = function(value) {
var dim = parseBits(value, 32);
var flags = parseBits(value, 32, 32);
var elementType = parseBits(value, 32, 64);
var offset = 96;
var dims = new Array();
for (var i = 0; i < dim; i++) {
// parse dimension
dims[i] = parseBits(value, 32, offset);
offset += 32;
// ignore lower bounds
offset += 32;
};
var parseElement = function(elementType) {
// parse content length
var length = parseBits(value, 32, offset);
offset += 32;
// parse null values
if (length == 0xffffffff) {
return null;
}
if (elementType == 0x17) {
// int
var result = parseBits(value, length * 8, offset);
offset += length * 8;
return result;
}
else if (elementType == 0x19) {
// string
var result = value.toString('utf8', offset >> 3, (offset += (length << 3)) >> 3);
return result;
}
else {
console.log("ERROR: ElementType not implemented: " + elementType);
}
};
var parseArray = function(dimension, elementType) {
var array = new Array();
if (dimension.length > 1) {
var count = dimension.shift();
for (var i = 0; i < count; i++) {
array[i] = parseArray(dimension, elementType);
}
dimension.unshift(count);
}
else {
for (var i = 0; i < dimension[0]; i++) {
array[i] = parseElement(elementType);
}
}
return array;
}
return parseArray(dims, elementType);
};
// To help we test dateParser
Query.dateParser = dateParser;
@ -341,7 +407,8 @@ var dataTypeParsers = {
26: parseBinaryInt64,
700: parseBinaryFloat32,
701: parseBinaryFloat64,
// 1009: arrayParser,
1007: arrayParser,
1009: arrayParser,
1114: parseDate,
//1184: parseBinaryInt64
// 1700: parseFloat,