Skip to content

Commit

Permalink
Convert longs to numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGodbehere committed Mar 21, 2023
1 parent 0884813 commit 01dc273
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions backend/src/Model/sparkplugb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ export let SparkplugPayload = root.lookupType('com.cirruslink.sparkplug.protobuf

export const SparkplugDecoder = {
decode(input: Buffer): Base64Message | undefined {

// ! Longs are being decoded as Long { low: 2034658590, high: 390, unsigned: true } despite toNumber being called on them in the
// ! translation app
// console.log(SparkplugPayload.decode(new Uint8Array(input)));
try {
let message = Base64Message.fromString(
JSON.stringify(
SparkplugPayload.toObject(SparkplugPayload.decode(new Uint8Array(input)))
SparkplugPayload.toObject(SparkplugPayload.decode(new Uint8Array(input)), {longs: Number})
)
)
message.decoder = Decoder.SPARKPLUG
// console.log(message);
return message
} catch {
// ignore
Expand Down

0 comments on commit 01dc273

Please sign in to comment.