Hi,
no - this is a brand new, no-external-dependencies approach. Can you shoot me a link to the Node Red?
As for converting the messages to JSON that'd be dead simple: just call JSON.stringify(data) and you'd be done. The only exception are BigInt (uint64_t, int64_t) fields which are not directly serializable to JSON. You'd need to do a bit of preprocessing of the objects to figure out how to serialize them properly.
If you'd like to do that preprocessing you can access the definition of list of fields using the packet.protocol.constructor.FIELDS collection. This will tell you the field name and its type (sort of reflection metadata) and you'll have it done in a few lines of code:
function convertToJson(data) {
const FILTERED_FIELD_TYPES = [
'int64_t', 'uint64_t', 'int64_t[]', 'int64_t[]'
]
const result = data.constructor.FIELDS
.filter(field => !FILTERED_FIELD_TYPES.includes(field.type))
return JSON.stringify(result)
}
Of course instead of filtering you could figure some other way of managing those fields, maybe truncating the value or converting it to string - kinda depends on what you're after.
Hope that helps.
M.