I'm trying to decode a topic key of a type number with KafkaJS.
The key object arrives as a Buffer, but I'm struggling with finding a way to decode it's value.
Example:
// message.key equals to Buffer.from([0x49, 0x57, 0x48, 0x55, 0x52, 057, 0x52])
const decodedKey = decodeBuffer(message.key);
// Should be equal to 1907494
I assume that it's a product of Java serialization. 'How can I deserialize it in JavaScript?
Check Buffer docs for different ways to read numbers.
Ex.
var b = Buffer.from([0x49, 0x57, 0x48, 0x55, 0x52, 057, 0x52]);
console.log(b.readInt32LE()) // 1430804297