Skip to content

Commit

Permalink
feat: use tahu for sparkplug decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
bj00rn committed May 17, 2024
1 parent a346c48 commit b03cd3c
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 442 deletions.
204 changes: 0 additions & 204 deletions backend/src/Model/sparkplugb.proto.ts

This file was deleted.

14 changes: 5 additions & 9 deletions backend/src/Model/sparkplugb.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// cSpell:words protobuf
import * as protobuf from 'protobufjs'
import protocol from './sparkplugb.proto'
import { Base64Message } from './Base64Message'
import { Decoder } from './Decoder'

const root = protobuf.parse(protocol).root
/* cspell:disable-next-line */
export let SparkplugPayload = root.lookupType('com.cirruslink.sparkplug.protobuf.Payload')
import { get } from 'sparkplug-payload'
var sparkplug = get("spBv1.0")

export const SparkplugDecoder = {
decode(input: Buffer): Base64Message {
try {
const message = Base64Message.fromString(
JSON.stringify(SparkplugPayload.toObject(SparkplugPayload.decode(new Uint8Array(input))))
const message = Base64Message.fromString(JSON.stringify(
// @ts-ignore
sparkplug.decodePayload(new Uint8Array(input)))
)
message.decoder = Decoder.SPARKPLUG
return message
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"semantic-release": "^23.0.8",
"semantic-release-export-data": "^1.0.1",
"source-map-support": "^0.5.9",
"sparkplug-client": "^3.2.4",
"ts-node": "^10.9.2",
"tslint": "^6.1.3",
"tslint-config-airbnb": "^5.11.2",
Expand All @@ -126,8 +127,8 @@
"lowdb": "^1.0.0",
"mime": "^2.4.4",
"mqtt": "^4.3.6",
"protobufjs": "^6.11.4",
"sha1": "^1.1.1",
"sparkplug-payload": "^1.0.3",
"uuid": "^8.3.2",
"yarn-run-all": "^3.1.1"
}
Expand Down
Loading

0 comments on commit b03cd3c

Please sign in to comment.