2011-06-22 03:37:48 +08:00
|
|
|
var textParsers = require(__dirname + "/textParsers"),
|
|
|
|
binaryParsers = require(__dirname + "/binaryParsers");
|
2011-03-03 13:28:17 +08:00
|
|
|
|
2011-06-22 03:37:48 +08:00
|
|
|
var typeParsers = {
|
|
|
|
text: {},
|
|
|
|
binary: {}
|
2011-03-03 13:28:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//the empty parse function
|
|
|
|
var noParse = function(val) {
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
//returns a function used to convert a specific type (specified by
|
|
|
|
//oid) into a result javascript type
|
2011-06-22 03:37:48 +08:00
|
|
|
var getTypeParser = function(oid, format) {
|
|
|
|
if (!typeParsers[format])
|
|
|
|
return noParse;
|
2011-03-03 13:28:17 +08:00
|
|
|
|
2011-06-22 03:37:48 +08:00
|
|
|
return typeParsers[format][oid] || noParse;
|
2011-03-03 13:28:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-22 03:37:48 +08:00
|
|
|
textParsers.init(function(oid, converter) {
|
|
|
|
typeParsers.text[oid] = converter;
|
|
|
|
});
|
2011-03-03 13:28:17 +08:00
|
|
|
|
2011-06-22 03:37:48 +08:00
|
|
|
binaryParsers.init(function(oid, converter) {
|
|
|
|
typeParsers.binary[oid] = converter;
|
|
|
|
});
|
2011-04-29 22:39:00 +08:00
|
|
|
|
2011-03-03 13:28:17 +08:00
|
|
|
|
|
|
|
module.exports = {
|
2011-06-22 03:37:48 +08:00
|
|
|
getTypeParser: getTypeParser,
|
2011-03-03 13:28:17 +08:00
|
|
|
}
|