Skip to content

Commit 531af31

Browse files
committed
remobe generated ts and load proto file directly
1 parent e708e1d commit 531af31

File tree

7 files changed

+232
-2417
lines changed

7 files changed

+232
-2417
lines changed

app/src/components/Sidebar/ValueRenderer/ValueRenderer.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as q from '../../../../../backend/src/Model'
22
import * as React from 'react'
3+
import * as fs from 'fs'
34
import CodeDiff from '../CodeDiff'
45
import { AppState } from '../../../reducers'
56
import { Base64Message } from '../../../../../backend/src/Model/Base64Message'
6-
import { Payload } from '../../../../../backend/src/Model/sparkplug'
7+
import { Payload } from '../../../../../backend/src/Model/sparkplugb'
78
import { connect } from 'react-redux'
89
import { ValueRendererDisplayMode } from '../../../reducers/Settings'
910
import { Fade } from '@material-ui/core'
@@ -50,8 +51,14 @@ class ValueRenderer extends React.Component<Props, State> {
5051
} catch (error) {
5152
try {
5253
//Sparkplugb
53-
let payload = Payload.decode(Base64Message.toUint8Array(msg))
54-
const json = Payload.toJSON(payload)
54+
if (Payload === undefined) {
55+
throw Error('sparkplugb.Payload is not loaded yet')
56+
}
57+
let json = Payload.toObject(Payload.decode(Base64Message.toUint8Array(msg)), {
58+
longs: String,
59+
enums: String,
60+
bytes: String,
61+
})
5562
return [JSON.stringify(json, undefined, ' '), 'json']
5663
} catch (error) {
5764
return [str, undefined]

app/src/components/TopicPlot.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PlotHistory from './Chart/Chart'
55
import { Base64Message } from '../../../backend/src/Model/Base64Message'
66
import { toPlottableValue } from './Sidebar/CodeDiff/util'
77
import { PlotCurveTypes } from '../reducers/Charts'
8-
import { Payload } from '../../../backend/src/Model/sparkplug'
8+
import { Payload } from '../../../backend/src/Model/sparkplugb'
99
const parseDuration = require('parse-duration')
1010

1111
interface Props {
@@ -41,12 +41,7 @@ function nodeDotPathToHistory(startTime: number | undefined, history: q.MessageH
4141
let json: any = {}
4242
try {
4343
json = message.payload ? JSON.parse(Base64Message.toUnicodeString(message.payload)) : {}
44-
} catch (ignore) {
45-
// sparkplugb
46-
try {
47-
json = message.payload ? Payload.toJSON(Payload.decode(Base64Message.toUint8Array(message.payload))) : {}
48-
} catch (ignore) {}
49-
}
44+
} catch (ignore) {}
5045

5146
const value = dotProp.get(json, dotPath)
5247

app/src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import { connect, Provider } from 'react-redux'
1010
import { ThemeProvider } from '@material-ui/styles'
1111
import './utils/tracking'
1212
import { themes } from './theme'
13+
import { loadSparkplugBPayload } from '../../backend/src/Model/sparkplugb'
1314

1415
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
1516
const store = createStore(reducers, composeEnhancers(applyMiddleware(reduxThunk, batchDispatchMiddleware)))
17+
loadSparkplugBPayload()
1618

1719
function ApplicationRenderer(props: { theme: 'light' | 'dark' }) {
1820
return (

app/webpack.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ module.exports = {
8787
}
8888
}
8989
},
90+
{
91+
test: /\.proto$/,
92+
use: [
93+
{
94+
loader: 'file-loader',
95+
options: {
96+
esModule: false,
97+
},
98+
},
99+
]
100+
},
90101
],
91102
},
92103

0 commit comments

Comments
 (0)