Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode Sparkplug Longs to Numbers #712

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Convert longs to numbers
  • Loading branch information
AlexGodbehere committed Mar 21, 2023
commit 01dc27309d442de34da86cec318d995320f9abc6
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