chaindb: endianness.

This commit is contained in:
Christopher Jeffrey 2016-08-18 00:44:36 -07:00
parent 096957ccb9
commit e817b89653
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -165,17 +165,13 @@ var layout = {
key[0] = 0x9a; // W + C key[0] = 0x9a; // W + C
write(key, address, 1); write(key, address, 1);
write(key, hash, 33); write(key, hash, 33);
// TODO: Change this to big key.writeUInt32BE(index, 65, true);
// endian for saner sorting.
key.writeUInt32LE(index, 65, true);
} else { } else {
key = new Buffer(57); key = new Buffer(57);
key[0] = 0x43; // C key[0] = 0x43; // C
write(key, address, 1); write(key, address, 1);
write(key, hash, 21); write(key, hash, 21);
// TODO: Change this to big key.writeUInt32BE(index, 53, true);
// endian for saner sorting.
key.writeUInt32LE(index, 53, true);
} }
return key; return key;
@ -185,10 +181,10 @@ var layout = {
if (key.length === 69) { if (key.length === 69) {
hash = key.slice(33, 65).toString('hex'); hash = key.slice(33, 65).toString('hex');
index = key.readUInt32LE(65, 0); index = key.readUInt32BE(65, 0);
} else { } else {
hash = key.slice(21, 53).toString('hex'); hash = key.slice(21, 53).toString('hex');
index = key.readUInt32LE(53, 0); index = key.readUInt32BE(53, 0);
} }
return [hash, index]; return [hash, index];