64 ビット (8 バイト) の大きな整数を nodejs バッファー オブジェクトにビッグ エンディアン形式で格納したいと考えています。
このタスクに関する問題は、nodejs バッファーが最大 32 ビット整数の書き込みのみをサポートすることです (buf.write32UInt32BE(value, offset) を使用)。だから私は、64ビット整数を分割できないのはなぜだと思いましたか?
var buf = new Buffer(8);
buf.fill(0) // clear all bytes of the buffer
console.log(buf); // outputs <Buffer 00 00 00 00 00 00 00 00>
var int = 0xffff; // as dezimal: 65535
buf.write32UInt32BE(0xff, 4); // right the first part of the int
console.log(buf); // outputs <Buffer 00 00 00 00 00 00 00 ff>
buf.write32UInt32BE(0xff, 0); // right the second part of the int
console.log(buf); // outputs <Buffer 00 00 00 ff 00 00 00 ff>
var bufInt = buf.read32UInt32BE(0) * buf.read32UInt32BE(4);
console.log(bufInt); // outputs 65025
ご覧のとおり、これはほぼ機能します。問題は、64 ビット整数を分割し、それを読み取るときに欠落している 510 を見つけることです。誰かがこれら2つの問題の解決策を示してくれませんか?