Comparing buffer

Hi,

How do you compare two buffers (using a function node)?

const decs1 = [3, 1, 1]
const buffer1 = Buffer.from(decs1);

const decs2 = [3, 1, 1]
const buffer2 = Buffer.from(decs2);

if (buffer1 != buffer2){
    msg.payload = 'true'
    return msg
} else{
    msg.payload = 'false'
    return msg
}

I think you have the right idea.

But you need to clarify how this is being triggered.
Usually the incoming message contains the things to be compared.
Changing a property defines if it is 1 or 2.

decs2 seems to get the values.
But how that works is way above my head.

Google, or your favourite search engine, is often the easiest way to get answers to such questions. Then look for the w3schools or MDN link there if there is one.

1 Like

Thank you @Colin

Just a bit confusing as if the statement is true it returned 0 and false it is 1, but nether the less a comparison and you can work with that.

It may return 1 or -1 if not equal, so in you case test for 0 or not zero. The reason for +-1 is so that buffers can be sorted into order.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.