Files
BridgeSwarm/spec/hrpc/messages.js
T
Raven Scott f4569b765e
CI / Build & Test (push) Successful in 3m12s
Updates
2026-07-26 22:58:33 -04:00

365 lines
7.9 KiB
JavaScript

// This file is autogenerated by the hyperschema compiler
// Schema Version: 2
/* eslint-disable camelcase */
/* eslint-disable quotes */
/* eslint-disable space-before-function-paren */
const { c } = require('hyperschema/runtime')
const VERSION = 2
// eslint-disable-next-line no-unused-vars
let version = VERSION
// @bridgeswarm/ping-request
const encoding0 = {
preencode(state, m) {
state.end++ // max flag is 1 so always one byte
if (m.value) c.string.preencode(state, m.value)
},
encode(state, m) {
const flags = m.value ? 1 : 0
c.uint.encode(state, flags)
if (m.value) c.string.encode(state, m.value)
},
decode(state) {
const flags = c.uint.decode(state)
return {
value: (flags & 1) !== 0 ? c.string.decode(state) : null
}
}
}
// @bridgeswarm/ping-response
const encoding1 = {
preencode(state, m) {
state.end++ // max flag is 1 so always one byte
if (m.pong) c.string.preencode(state, m.pong)
},
encode(state, m) {
const flags = m.pong ? 1 : 0
c.uint.encode(state, flags)
if (m.pong) c.string.encode(state, m.pong)
},
decode(state) {
const flags = c.uint.decode(state)
return {
pong: (flags & 1) !== 0 ? c.string.decode(state) : null
}
}
}
// @bridgeswarm/stream-request-chunk
const encoding2 = {
preencode(state, m) {
state.end++ // max flag is 2 so always one byte
if (m.n) c.uint.preencode(state, m.n)
if (m.label) c.string.preencode(state, m.label)
},
encode(state, m) {
const flags = (m.n ? 1 : 0) | (m.label ? 2 : 0)
c.uint.encode(state, flags)
if (m.n) c.uint.encode(state, m.n)
if (m.label) c.string.encode(state, m.label)
},
decode(state) {
const flags = c.uint.decode(state)
return {
n: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
label: (flags & 2) !== 0 ? c.string.decode(state) : null
}
}
}
// @bridgeswarm/stream-sum-response
const encoding3 = {
preencode(state, m) {
state.end++ // max flag is 2 so always one byte
if (m.sum) c.uint.preencode(state, m.sum)
if (m.count) c.uint.preencode(state, m.count)
},
encode(state, m) {
const flags = (m.sum ? 1 : 0) | (m.count ? 2 : 0)
c.uint.encode(state, flags)
if (m.sum) c.uint.encode(state, m.sum)
if (m.count) c.uint.encode(state, m.count)
},
decode(state) {
const flags = c.uint.decode(state)
return {
sum: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
count: (flags & 2) !== 0 ? c.uint.decode(state) : 0
}
}
}
// @bridgeswarm/fetch-request
const encoding4 = {
preencode(state, m) {
state.end++ // max flag is 1 so always one byte
if (m.count) c.uint.preencode(state, m.count)
},
encode(state, m) {
const flags = m.count ? 1 : 0
c.uint.encode(state, flags)
if (m.count) c.uint.encode(state, m.count)
},
decode(state) {
const flags = c.uint.decode(state)
return {
count: (flags & 1) !== 0 ? c.uint.decode(state) : 0
}
}
}
// @bridgeswarm/fetch-chunk
const encoding5 = {
preencode(state, m) {
state.end++ // max flag is 2 so always one byte
if (m.i) c.uint.preencode(state, m.i)
if (m.data) c.string.preencode(state, m.data)
},
encode(state, m) {
const flags = (m.i ? 1 : 0) | (m.data ? 2 : 0)
c.uint.encode(state, flags)
if (m.i) c.uint.encode(state, m.i)
if (m.data) c.string.encode(state, m.data)
},
decode(state) {
const flags = c.uint.decode(state)
return {
i: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
data: (flags & 2) !== 0 ? c.string.decode(state) : null
}
}
}
// @bridgeswarm/duplex-in
const encoding6 = {
preencode(state, m) {
state.end++ // max flag is 2 so always one byte
if (m.x) c.uint.preencode(state, m.x)
if (m.y) c.string.preencode(state, m.y)
},
encode(state, m) {
const flags = (m.x ? 1 : 0) | (m.y ? 2 : 0)
c.uint.encode(state, flags)
if (m.x) c.uint.encode(state, m.x)
if (m.y) c.string.encode(state, m.y)
},
decode(state) {
const flags = c.uint.decode(state)
return {
x: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
y: (flags & 2) !== 0 ? c.string.decode(state) : null
}
}
}
// @bridgeswarm/duplex-out
const encoding7 = {
preencode(state, m) {
state.end++ // max flag is 2 so always one byte
if (m.result) c.string.preencode(state, m.result)
if (m.n) c.uint.preencode(state, m.n)
},
encode(state, m) {
const flags = (m.result ? 1 : 0) | (m.n ? 2 : 0)
c.uint.encode(state, flags)
if (m.result) c.string.encode(state, m.result)
if (m.n) c.uint.encode(state, m.n)
},
decode(state) {
const flags = c.uint.decode(state)
return {
result: (flags & 1) !== 0 ? c.string.decode(state) : null,
n: (flags & 2) !== 0 ? c.uint.decode(state) : 0
}
}
}
// @bridgeswarm/notify-request
const encoding8 = {
preencode(state, m) {
state.end++ // max flag is 2 so always one byte
if (m.event) c.string.preencode(state, m.event)
if (m.payload) c.uint.preencode(state, m.payload)
},
encode(state, m) {
const flags = (m.event ? 1 : 0) | (m.payload ? 2 : 0)
c.uint.encode(state, flags)
if (m.event) c.string.encode(state, m.event)
if (m.payload) c.uint.encode(state, m.payload)
},
decode(state) {
const flags = c.uint.decode(state)
return {
event: (flags & 1) !== 0 ? c.string.decode(state) : null,
payload: (flags & 2) !== 0 ? c.uint.decode(state) : 0
}
}
}
// @bridgeswarm/record
const encoding9 = {
preencode(state, m) {
c.string.preencode(state, m.id)
c.string.preencode(state, m.value)
},
encode(state, m) {
c.string.encode(state, m.id)
c.string.encode(state, m.value)
},
decode(state) {
const r0 = c.string.decode(state)
const r1 = c.string.decode(state)
return {
id: r0,
value: r1
}
}
}
// @bridgeswarm/note
const encoding10 = {
preencode(state, m) {
c.string.preencode(state, m.id)
c.string.preencode(state, m.title)
c.string.preencode(state, m.body)
},
encode(state, m) {
c.string.encode(state, m.id)
c.string.encode(state, m.title)
c.string.encode(state, m.body)
},
decode(state) {
const r0 = c.string.decode(state)
const r1 = c.string.decode(state)
const r2 = c.string.decode(state)
return {
id: r0,
title: r1,
body: r2
}
}
}
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 '@bridgeswarm/ping-request':
return encoding0
case '@bridgeswarm/ping-response':
return encoding1
case '@bridgeswarm/stream-request-chunk':
return encoding2
case '@bridgeswarm/stream-sum-response':
return encoding3
case '@bridgeswarm/fetch-request':
return encoding4
case '@bridgeswarm/fetch-chunk':
return encoding5
case '@bridgeswarm/duplex-in':
return encoding6
case '@bridgeswarm/duplex-out':
return encoding7
case '@bridgeswarm/notify-request':
return encoding8
case '@bridgeswarm/record':
return encoding9
case '@bridgeswarm/note':
return encoding10
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
module.exports = {
resolveStruct,
getStruct,
getEnum,
getEncoding,
encode,
decode,
setVersion,
version
}