decode diff view for sparkplug

This commit is contained in:
Sinuhe Tellez
2021-08-08 16:32:22 -04:00
parent 68ef9ac913
commit 23b46cd432
4 changed files with 21 additions and 19 deletions

View File

@@ -40,7 +40,7 @@ function ActionButtons(props: {
</Tooltip>
</ToggleButton>
<ToggleButton className={props.classes.toggleButton} value="raw" id="valueRendererDisplayMode-raw">
<Tooltip title="Raw / formatted JSON">
<Tooltip title="Raw / formatted JSON / formatted sparkplugb protojson">
<span>
<Reorder className={props.classes.toggleButtonIcon} />
</span>

View File

@@ -52,7 +52,8 @@ class ValueRenderer extends React.Component<Props, State> {
JSON.parse(str)
} catch (error) {
try {
let payload = Payload.decode(this.base64MessageToUint8Array(msg))
//Sparkplugb
let payload = Payload.decode(Base64Message.toUint8Array(msg))
const json = Payload.toJSON(payload)
return [JSON.stringify(json, undefined, ' '), 'json']
} catch (error) {
@@ -63,21 +64,6 @@ class ValueRenderer extends React.Component<Props, State> {
return [this.messageToPrettyJson(str), 'json']
}
private base64MessageToUint8Array(msg: Base64Message): Uint8Array {
let dataUri = Base64Message.toDataUri(msg, "")
let parts = dataUri.split(',')
let b64 = parts[1]
var binary_string = window.atob(b64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes
}
private messageToPrettyJson(str: string): string | undefined {
try {
const json = JSON.parse(str)

View File

@@ -5,6 +5,7 @@ import PlotHistory from './Chart/Chart'
import { Base64Message } from '../../../backend/src/Model/Base64Message'
import { toPlottableValue } from './Sidebar/CodeDiff/util'
import { PlotCurveTypes } from '../reducers/Charts'
import { Payload } from '../../../backend/src/Model/sparkplug'
const parseDuration = require('parse-duration')
interface Props {
@@ -37,10 +38,15 @@ function nodeToHistory(startTime: number | undefined, history: q.MessageHistory)
function nodeDotPathToHistory(startTime: number | undefined, history: q.MessageHistory, dotPath: string) {
return filterUsingTimeRange(startTime, history.toArray())
.map((message: q.Message) => {
let json = {}
let json: any = {}
try {
json = message.payload ? JSON.parse(Base64Message.toUnicodeString(message.payload)) : {}
} catch (ignore) {}
} catch (ignore) { }
// sparkplugb
try {
json = message.payload ? Payload.toJSON(Payload.decode(Base64Message.toUint8Array(message.payload))) : {}
} catch (ignore) { }
const value = dotProp.get(json, dotPath)