Testing
This commit is contained in:
@@ -0,0 +1,368 @@
|
||||
// This file is autogenerated by the hyperschema compiler
|
||||
// Schema Version: 1
|
||||
/* eslint-disable camelcase */
|
||||
/* eslint-disable quotes */
|
||||
/* eslint-disable space-before-function-paren */
|
||||
|
||||
import { c } from 'hyperschema/runtime'
|
||||
|
||||
const VERSION = 1
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let version = VERSION
|
||||
|
||||
// @peardata/node
|
||||
const encoding0 = {
|
||||
preencode(state, m) {
|
||||
c.string.preencode(state, m.nodeId)
|
||||
c.string.preencode(state, m.hostname)
|
||||
state.end++ // max flag is 64 so always one byte
|
||||
|
||||
if (m.publicKeyHex) c.string.preencode(state, m.publicKeyHex)
|
||||
if (m.platform) c.string.preencode(state, m.platform)
|
||||
if (m.arch) c.string.preencode(state, m.arch)
|
||||
if (m.cpus) c.uint.preencode(state, m.cpus)
|
||||
if (m.totalMemMiB) c.uint.preencode(state, m.totalMemMiB)
|
||||
if (m.agentVersion) c.string.preencode(state, m.agentVersion)
|
||||
if (m.labelsJson) c.string.preencode(state, m.labelsJson)
|
||||
c.uint.preencode(state, m.updatedAt)
|
||||
},
|
||||
encode(state, m) {
|
||||
const flags =
|
||||
(m.publicKeyHex ? 1 : 0) |
|
||||
(m.platform ? 2 : 0) |
|
||||
(m.arch ? 4 : 0) |
|
||||
(m.cpus ? 8 : 0) |
|
||||
(m.totalMemMiB ? 16 : 0) |
|
||||
(m.agentVersion ? 32 : 0) |
|
||||
(m.labelsJson ? 64 : 0)
|
||||
|
||||
c.string.encode(state, m.nodeId)
|
||||
c.string.encode(state, m.hostname)
|
||||
c.uint.encode(state, flags)
|
||||
|
||||
if (m.publicKeyHex) c.string.encode(state, m.publicKeyHex)
|
||||
if (m.platform) c.string.encode(state, m.platform)
|
||||
if (m.arch) c.string.encode(state, m.arch)
|
||||
if (m.cpus) c.uint.encode(state, m.cpus)
|
||||
if (m.totalMemMiB) c.uint.encode(state, m.totalMemMiB)
|
||||
if (m.agentVersion) c.string.encode(state, m.agentVersion)
|
||||
if (m.labelsJson) c.string.encode(state, m.labelsJson)
|
||||
c.uint.encode(state, m.updatedAt)
|
||||
},
|
||||
decode(state) {
|
||||
const r0 = c.string.decode(state)
|
||||
const r1 = c.string.decode(state)
|
||||
const flags = c.uint.decode(state)
|
||||
|
||||
return {
|
||||
nodeId: r0,
|
||||
hostname: r1,
|
||||
publicKeyHex: (flags & 1) !== 0 ? c.string.decode(state) : null,
|
||||
platform: (flags & 2) !== 0 ? c.string.decode(state) : null,
|
||||
arch: (flags & 4) !== 0 ? c.string.decode(state) : null,
|
||||
cpus: (flags & 8) !== 0 ? c.uint.decode(state) : 0,
|
||||
totalMemMiB: (flags & 16) !== 0 ? c.uint.decode(state) : 0,
|
||||
agentVersion: (flags & 32) !== 0 ? c.string.decode(state) : null,
|
||||
labelsJson: (flags & 64) !== 0 ? c.string.decode(state) : null,
|
||||
updatedAt: c.uint.decode(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @peardata/peer-link
|
||||
const encoding1 = {
|
||||
preencode(state, m) {
|
||||
c.string.preencode(state, m.localNodeId)
|
||||
c.string.preencode(state, m.remotePublicKey)
|
||||
state.end++ // max flag is 16 so always one byte
|
||||
|
||||
if (m.role) c.string.preencode(state, m.role)
|
||||
if (m.alias) c.string.preencode(state, m.alias)
|
||||
if (m.dbKeyHex) c.string.preencode(state, m.dbKeyHex)
|
||||
if (m.syncMode) c.string.preencode(state, m.syncMode)
|
||||
c.uint.preencode(state, m.linkedAt)
|
||||
if (m.lastSeen) c.uint.preencode(state, m.lastSeen)
|
||||
},
|
||||
encode(state, m) {
|
||||
const flags =
|
||||
(m.role ? 1 : 0) |
|
||||
(m.alias ? 2 : 0) |
|
||||
(m.dbKeyHex ? 4 : 0) |
|
||||
(m.syncMode ? 8 : 0) |
|
||||
(m.lastSeen ? 16 : 0)
|
||||
|
||||
c.string.encode(state, m.localNodeId)
|
||||
c.string.encode(state, m.remotePublicKey)
|
||||
c.uint.encode(state, flags)
|
||||
|
||||
if (m.role) c.string.encode(state, m.role)
|
||||
if (m.alias) c.string.encode(state, m.alias)
|
||||
if (m.dbKeyHex) c.string.encode(state, m.dbKeyHex)
|
||||
if (m.syncMode) c.string.encode(state, m.syncMode)
|
||||
c.uint.encode(state, m.linkedAt)
|
||||
if (m.lastSeen) c.uint.encode(state, m.lastSeen)
|
||||
},
|
||||
decode(state) {
|
||||
const r0 = c.string.decode(state)
|
||||
const r1 = c.string.decode(state)
|
||||
const flags = c.uint.decode(state)
|
||||
|
||||
return {
|
||||
localNodeId: r0,
|
||||
remotePublicKey: r1,
|
||||
role: (flags & 1) !== 0 ? c.string.decode(state) : null,
|
||||
alias: (flags & 2) !== 0 ? c.string.decode(state) : null,
|
||||
dbKeyHex: (flags & 4) !== 0 ? c.string.decode(state) : null,
|
||||
syncMode: (flags & 8) !== 0 ? c.string.decode(state) : null,
|
||||
linkedAt: c.uint.decode(state),
|
||||
lastSeen: (flags & 16) !== 0 ? c.uint.decode(state) : 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @peardata/alert-config
|
||||
const encoding2 = {
|
||||
preencode(state, m) {
|
||||
c.string.preencode(state, m.id)
|
||||
c.string.preencode(state, m.chart)
|
||||
c.string.preencode(state, m.dimension)
|
||||
state.end++ // max flag is 16 so always one byte
|
||||
|
||||
if (m.warn) c.float64.preencode(state, m.warn)
|
||||
if (m.crit) c.float64.preencode(state, m.crit)
|
||||
if (m.comparator) c.string.preencode(state, m.comparator)
|
||||
if (m.info) c.string.preencode(state, m.info)
|
||||
c.uint.preencode(state, m.updatedAt)
|
||||
},
|
||||
encode(state, m) {
|
||||
const flags =
|
||||
(m.warn ? 1 : 0) |
|
||||
(m.crit ? 2 : 0) |
|
||||
(m.comparator ? 4 : 0) |
|
||||
(m.enabled ? 8 : 0) |
|
||||
(m.info ? 16 : 0)
|
||||
|
||||
c.string.encode(state, m.id)
|
||||
c.string.encode(state, m.chart)
|
||||
c.string.encode(state, m.dimension)
|
||||
c.uint.encode(state, flags)
|
||||
|
||||
if (m.warn) c.float64.encode(state, m.warn)
|
||||
if (m.crit) c.float64.encode(state, m.crit)
|
||||
if (m.comparator) c.string.encode(state, m.comparator)
|
||||
if (m.info) c.string.encode(state, m.info)
|
||||
c.uint.encode(state, m.updatedAt)
|
||||
},
|
||||
decode(state) {
|
||||
const r0 = c.string.decode(state)
|
||||
const r1 = c.string.decode(state)
|
||||
const r2 = c.string.decode(state)
|
||||
const flags = c.uint.decode(state)
|
||||
|
||||
return {
|
||||
id: r0,
|
||||
chart: r1,
|
||||
dimension: r2,
|
||||
warn: (flags & 1) !== 0 ? c.float64.decode(state) : 0,
|
||||
crit: (flags & 2) !== 0 ? c.float64.decode(state) : 0,
|
||||
comparator: (flags & 4) !== 0 ? c.string.decode(state) : null,
|
||||
enabled: (flags & 8) !== 0,
|
||||
info: (flags & 16) !== 0 ? c.string.decode(state) : null,
|
||||
updatedAt: c.uint.decode(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @peardata/alert-event
|
||||
const encoding3 = {
|
||||
preencode(state, m) {
|
||||
c.string.preencode(state, m.id)
|
||||
c.uint.preencode(state, m.ts)
|
||||
c.string.preencode(state, m.chart)
|
||||
state.end++ // max flag is 16 so always one byte
|
||||
|
||||
if (m.dimension) c.string.preencode(state, m.dimension)
|
||||
c.string.preencode(state, m.severity)
|
||||
if (m.value) c.float64.preencode(state, m.value)
|
||||
if (m.threshold) c.float64.preencode(state, m.threshold)
|
||||
if (m.message) c.string.preencode(state, m.message)
|
||||
},
|
||||
encode(state, m) {
|
||||
const flags =
|
||||
(m.dimension ? 1 : 0) |
|
||||
(m.value ? 2 : 0) |
|
||||
(m.threshold ? 4 : 0) |
|
||||
(m.message ? 8 : 0) |
|
||||
(m.cleared ? 16 : 0)
|
||||
|
||||
c.string.encode(state, m.id)
|
||||
c.uint.encode(state, m.ts)
|
||||
c.string.encode(state, m.chart)
|
||||
c.uint.encode(state, flags)
|
||||
|
||||
if (m.dimension) c.string.encode(state, m.dimension)
|
||||
c.string.encode(state, m.severity)
|
||||
if (m.value) c.float64.encode(state, m.value)
|
||||
if (m.threshold) c.float64.encode(state, m.threshold)
|
||||
if (m.message) c.string.encode(state, m.message)
|
||||
},
|
||||
decode(state) {
|
||||
const r0 = c.string.decode(state)
|
||||
const r1 = c.uint.decode(state)
|
||||
const r2 = c.string.decode(state)
|
||||
const flags = c.uint.decode(state)
|
||||
|
||||
return {
|
||||
id: r0,
|
||||
ts: r1,
|
||||
chart: r2,
|
||||
dimension: (flags & 1) !== 0 ? c.string.decode(state) : null,
|
||||
severity: c.string.decode(state),
|
||||
value: (flags & 2) !== 0 ? c.float64.decode(state) : 0,
|
||||
threshold: (flags & 4) !== 0 ? c.float64.decode(state) : 0,
|
||||
message: (flags & 8) !== 0 ? c.string.decode(state) : null,
|
||||
cleared: (flags & 16) !== 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @peardata/metric-point
|
||||
const encoding4 = {
|
||||
preencode(state, m) {
|
||||
c.string.preencode(state, m.chart)
|
||||
c.uint.preencode(state, m.ts)
|
||||
c.string.preencode(state, m.context)
|
||||
c.uint.preencode(state, m.tier)
|
||||
c.string.preencode(state, m.valuesJson)
|
||||
},
|
||||
encode(state, m) {
|
||||
c.string.encode(state, m.chart)
|
||||
c.uint.encode(state, m.ts)
|
||||
c.string.encode(state, m.context)
|
||||
c.uint.encode(state, m.tier)
|
||||
c.string.encode(state, m.valuesJson)
|
||||
},
|
||||
decode(state) {
|
||||
const r0 = c.string.decode(state)
|
||||
const r1 = c.uint.decode(state)
|
||||
const r2 = c.string.decode(state)
|
||||
const r3 = c.uint.decode(state)
|
||||
const r4 = c.string.decode(state)
|
||||
|
||||
return {
|
||||
chart: r0,
|
||||
ts: r1,
|
||||
context: r2,
|
||||
tier: r3,
|
||||
valuesJson: r4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @peardata/job
|
||||
const encoding5 = {
|
||||
preencode(state, m) {
|
||||
c.string.preencode(state, m.id)
|
||||
c.string.preencode(state, m.name)
|
||||
c.string.preencode(state, m.status)
|
||||
state.end++ // max flag is 8 so always one byte
|
||||
|
||||
if (m.startedAt) c.uint.preencode(state, m.startedAt)
|
||||
if (m.finishedAt) c.uint.preencode(state, m.finishedAt)
|
||||
if (m.resultJson) c.string.preencode(state, m.resultJson)
|
||||
if (m.error) c.string.preencode(state, m.error)
|
||||
},
|
||||
encode(state, m) {
|
||||
const flags =
|
||||
(m.startedAt ? 1 : 0) | (m.finishedAt ? 2 : 0) | (m.resultJson ? 4 : 0) | (m.error ? 8 : 0)
|
||||
|
||||
c.string.encode(state, m.id)
|
||||
c.string.encode(state, m.name)
|
||||
c.string.encode(state, m.status)
|
||||
c.uint.encode(state, flags)
|
||||
|
||||
if (m.startedAt) c.uint.encode(state, m.startedAt)
|
||||
if (m.finishedAt) c.uint.encode(state, m.finishedAt)
|
||||
if (m.resultJson) c.string.encode(state, m.resultJson)
|
||||
if (m.error) c.string.encode(state, m.error)
|
||||
},
|
||||
decode(state) {
|
||||
const r0 = c.string.decode(state)
|
||||
const r1 = c.string.decode(state)
|
||||
const r2 = c.string.decode(state)
|
||||
const flags = c.uint.decode(state)
|
||||
|
||||
return {
|
||||
id: r0,
|
||||
name: r1,
|
||||
status: r2,
|
||||
startedAt: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
|
||||
finishedAt: (flags & 2) !== 0 ? c.uint.decode(state) : 0,
|
||||
resultJson: (flags & 4) !== 0 ? c.string.decode(state) : null,
|
||||
error: (flags & 8) !== 0 ? c.string.decode(state) : null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setVersion(v) {
|
||||
version = v
|
||||
}
|
||||
|
||||
function encode(name, value, v = VERSION) {
|
||||
version = v
|
||||
return c.encode(getEncoding(name), value)
|
||||
}
|
||||
|
||||
function decode(name, buffer, v = VERSION) {
|
||||
version = v
|
||||
return c.decode(getEncoding(name), buffer)
|
||||
}
|
||||
|
||||
function getEnum(name) {
|
||||
switch (name) {
|
||||
default:
|
||||
throw new Error('Enum not found ' + name)
|
||||
}
|
||||
}
|
||||
|
||||
function getEncoding(name) {
|
||||
switch (name) {
|
||||
case '@peardata/node':
|
||||
return encoding0
|
||||
case '@peardata/peer-link':
|
||||
return encoding1
|
||||
case '@peardata/alert-config':
|
||||
return encoding2
|
||||
case '@peardata/alert-event':
|
||||
return encoding3
|
||||
case '@peardata/metric-point':
|
||||
return encoding4
|
||||
case '@peardata/job':
|
||||
return encoding5
|
||||
default:
|
||||
throw new Error('Encoder not found ' + name)
|
||||
}
|
||||
}
|
||||
|
||||
function getStruct(name, v = VERSION) {
|
||||
const enc = getEncoding(name)
|
||||
return {
|
||||
preencode(state, m) {
|
||||
version = v
|
||||
enc.preencode(state, m)
|
||||
},
|
||||
encode(state, m) {
|
||||
version = v
|
||||
enc.encode(state, m)
|
||||
},
|
||||
decode(state) {
|
||||
version = v
|
||||
return enc.decode(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const resolveStruct = getStruct // compat
|
||||
|
||||
export { resolveStruct, getStruct, getEnum, getEncoding, encode, decode, setVersion, version }
|
||||
Reference in New Issue
Block a user