25 lines
582 B
JavaScript
25 lines
582 B
JavaScript
import c from 'compact-encoding'
|
|
|
|
export const BARE_OS_MESHDROP_WIRE_SCHEMA_VERSION = 1
|
|
|
|
/**
|
|
* Compact JSON payload wrapper. The booter validates and caps shape.
|
|
*/
|
|
export const msgMeshdropEnvelopeEncoding = {
|
|
preencode(state, m) {
|
|
c.string.preencode(state, JSON.stringify(m || {}))
|
|
},
|
|
encode(state, m) {
|
|
c.string.encode(state, JSON.stringify(m || {}))
|
|
},
|
|
decode(state) {
|
|
const t = c.string.decode(state)
|
|
try {
|
|
const obj = JSON.parse(String(t || ''))
|
|
return obj && typeof obj === 'object' ? obj : {}
|
|
} catch {
|
|
return {}
|
|
}
|
|
}
|
|
}
|