const { c: e, b4a: r, assert: s } = require("hyperdispatch/runtime"),
{ version: t, getEncoding: n, setVersion: i } = require("./messages.js"),
a = t
class c {
constructor() {
;((this._handler0 = null),
(this._handler1 = null),
(this._handler2 = null),
(this._handler3 = null),
(this._handler4 = null),
(this._missing = 5))
}
add(e, r) {
switch (e) {
case "@keet-registry-service/add-writer":
this._handler0 = r
break
case "@keet-registry-service/put-record":
this._handler1 = r
break
case "@keet-registry-service/set-manifest":
this._handler2 = r
break
case "@keet-registry-service/reserve":
this._handler3 = r
break
case "@keet-registry-service/block":
this._handler4 = r
break
default:
throw new Error("Cannot register a handler for a nonexistent route: " + e)
}
this._missing--
}
_checkAll() {
;(s(null !== this._handler0, 'Missing handler for "@keet-registry-service/add-writer"'),
s(null !== this._handler1, 'Missing handler for "@keet-registry-service/put-record"'),
s(null !== this._handler2, 'Missing handler for "@keet-registry-service/set-manifest"'),
s(null !== this._handler3, 'Missing handler for "@keet-registry-service/reserve"'),
s(null !== this._handler4, 'Missing handler for "@keet-registry-service/block"'))
}
async dispatch(e, s) {
;(this._missing > 0 && this._checkAll(), i(a))
const t = r.isBuffer(e) ? l(e) : e
switch (t.id) {
case 0:
return this._handler0(t.value, s)
case 1:
return this._handler1(t.value, s)
case 2:
return this._handler2(t.value, s)
case 3:
return this._handler3(t.value, s)
case 4:
return this._handler4(t.value, s)
default:
throw new Error("Handler not found for ID:" + t.id)
}
}
}
function d(s, t, { version: n = a } = {}) {
const c = { buffer: null, start: 0, end: 0 },
d = k(s)
return (
i(n),
e.uint.preencode(c, d.id),
d.enc.preencode(c, t),
(c.buffer = r.allocUnsafe(c.end)),
e.uint.encode(c, d.id),
d.enc.encode(c, t),
c.buffer
)
}
function l(r, { version: s = a } = {}) {
const t = { buffer: r, start: 0, end: r.length },
n = e.uint.decode(t),
c = f(n)
i(s)
const d = c.enc.decode(t)
return { id: n, name: c.name, value: d }
}
const o = {
name: "@keet-registry-service/add-writer",
id: 0,
enc: n("@keet-registry-service/writer"),
},
u = { name: "@keet-registry-service/put-record", id: 1, enc: n("@keet-registry-service/record") },
h = { name: "@keet-registry-service/set-manifest", id: 2, enc: n("@keet-registry-v3/manifest") },
v = {
name: "@keet-registry-service/reserve",
id: 3,
enc: n("@keet-registry-service/reservation"),
},
g = {
name: "@keet-registry-service/block",
id: 4,
enc: n("@keet-registry-service/block-request"),
}
function k(e) {
switch (e) {
case "@keet-registry-service/add-writer":
return o
case "@keet-registry-service/put-record":
return u
case "@keet-registry-service/set-manifest":
return h
case "@keet-registry-service/reserve":
return v
case "@keet-registry-service/block":
return g
default:
throw new Error("Handler not found for name: " + e)
}
}
function f(e) {
switch (e) {
case 0:
return o
case 1:
return u
case 2:
return h
case 3:
return v
case 4:
return g
default:
throw new Error("Handler not found for ID: " + e)
}
}
module.exports = { version: t, encode: d, decode: l, Router: c }