feat: use tahu for sparkplug decoding
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user