Hoping you might be able to help me figure out why my null value is showing up as '\u0000' instead of null.
When using for a null-terminated string that has no value the resulting JSON has the following value: '\u0000'. I have this method to help me identify where the next null is (null is a delimiter for a file I am trying to parse).
Buffer.prototype.nextNull = function (from) {
var length = this.length,
from = (!from ? 0 : from);
for (var i = from; i < length; ++i) {
if (this[i] === 0x00) {
console.log(i, this.toString('hex', i, i+1));
return i;
}
}
return -1;
};
The console.log line prints out the below (meaning I know I have an exact match to 0x00 at index 12).
When I write a quick test with your code I see it working properly (but not against my file):
var spec = {
bigEndian: true,
fields: [
{ name: "shouldBeNull", start: 0, type: 'utf8', length: 0 }
]
};
var buf = new Buffer(1);
//either of these give the same result
//buf[0] = null;
buf.write("00", 0, 1, 'hex');
console.log("--" + buf.toString('hex', 0, 1));
console.log(decoderRing.decode(buf, spec));
The (acceptable) result from the code not using my file:
The output from my file:
{ shouldBeNull: '\u0000' }
Any thoughts? I looked for other ways to open the file and couldnt see anything. Suggestions welcome ;) - thanks!
Hoping you might be able to help me figure out why my null value is showing up as '\u0000' instead of null.
When using for a null-terminated string that has no value the resulting JSON has the following value: '\u0000'. I have this method to help me identify where the next null is (null is a delimiter for a file I am trying to parse).
The console.log line prints out the below (meaning I know I have an exact match to 0x00 at index 12).
When I write a quick test with your code I see it working properly (but not against my file):
The (acceptable) result from the code not using my file:
The output from my file:
Any thoughts? I looked for other ways to open the file and couldnt see anything. Suggestions welcome ;) - thanks!