From 37e958f779c5f2442893412e8aac00ed349eb338 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 28 Jan 2011 18:06:05 +0100 Subject: [PATCH] added arrayParser --- lib/query.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/lib/query.js b/lib/query.js index 4e8af8c..4e93680 100644 --- a/lib/query.js +++ b/lib/query.js @@ -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,