1

I am getting a data from device in the HEX format like below:

<Buffer 00 cc>

I need to read the same in TEXT format and store the value in Database. I am using PostgreSQL as database to store the data.

Below is the error message I am getting while processing it to the Database.

error: invalid message format
at Connection.parseE (/var/www/html/project/collection/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/var/www/html/project/collection/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/var/www/html/project/collection/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:182:13)

Please let me how to rectify this.

2
  • Have you tried converting the buffer to a string? Commented Jan 2, 2021 at 12:19
  • No not yet. if you can help with that how to do it will be great. Commented Jan 2, 2021 at 12:27

1 Answer 1

1

If you're dealing with a buffer that contains bytes of text data, you can try to convert the buffer to a string, which you can then pass to your db-call. Consider this simple example:

const responseBuffer = await someService.getData();
const contentString = responseBuffer.toString('utf8'); // you need to make sure the encoding is correct
await dbService.query(buildQuery(contentString), ...);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.