UNPKG

hyperns-service

Version:
162 lines (135 loc) 4.16 kB
// This file is autogenerated by the hyperschema compiler // Schema Version: 1 /* eslint-disable camelcase */ /* eslint-disable quotes */ const VERSION = 1 const { c } = require('hyperschema/runtime') // eslint-disable-next-line no-unused-vars let version = VERSION // @hyperns/name-entry.blindPeers const encoding0_2 = c.array(c.fixed32) // @hyperns/name-entry const encoding0 = { preencode (state, m) { c.fixed32.preencode(state, m.publicKey) c.string.preencode(state, m.name) encoding0_2.preencode(state, m.blindPeers) }, encode (state, m) { c.fixed32.encode(state, m.publicKey) c.string.encode(state, m.name) encoding0_2.encode(state, m.blindPeers) }, decode (state) { const res = {} res.publicKey = null res.name = null res.blindPeers = null res.publicKey = c.fixed32.decode(state) res.name = c.string.decode(state) res.blindPeers = encoding0_2.decode(state) return res } } // @hyperns/op.record const encoding1_3 = c.frame(encoding0) // @hyperns/op const encoding1 = { preencode (state, m) { let flags = 0 if (m.blindPeerKey) flags |= 1 if (m.writerKey) flags |= 2 if (m.record) flags |= 4 c.uint.preencode(state, m.op) c.uint.preencode(state, flags) if (m.blindPeerKey) c.fixed32.preencode(state, m.blindPeerKey) if (m.writerKey) c.fixed32.preencode(state, m.writerKey) if (m.record) encoding1_3.preencode(state, m.record) }, encode (state, m) { let flags = 0 if (m.blindPeerKey) flags |= 1 if (m.writerKey) flags |= 2 if (m.record) flags |= 4 c.uint.encode(state, m.op) c.uint.encode(state, flags) if (m.blindPeerKey) c.fixed32.encode(state, m.blindPeerKey) if (m.writerKey) c.fixed32.encode(state, m.writerKey) if (m.record) encoding1_3.encode(state, m.record) }, decode (state) { const res = {} res.op = 0 res.blindPeerKey = null res.writerKey = null res.record = null res.op = c.uint.decode(state) const flags = state.start < state.end ? c.uint.decode(state) : 0 if ((flags & 1) !== 0) res.blindPeerKey = c.fixed32.decode(state) if ((flags & 2) !== 0) res.writerKey = c.fixed32.decode(state) if ((flags & 4) !== 0) res.record = encoding1_3.decode(state) return res } } // @hyperns/op/value.record const encoding2_2 = c.frame(encoding0) // @hyperns/op/value const encoding2 = { preencode (state, m) { let flags = 0 if (m.blindPeerKey) flags |= 1 if (m.writerKey) flags |= 2 if (m.record) flags |= 4 c.uint.preencode(state, flags) if (m.blindPeerKey) c.fixed32.preencode(state, m.blindPeerKey) if (m.writerKey) c.fixed32.preencode(state, m.writerKey) if (m.record) encoding2_2.preencode(state, m.record) }, encode (state, m) { let flags = 0 if (m.blindPeerKey) flags |= 1 if (m.writerKey) flags |= 2 if (m.record) flags |= 4 c.uint.encode(state, flags) if (m.blindPeerKey) c.fixed32.encode(state, m.blindPeerKey) if (m.writerKey) c.fixed32.encode(state, m.writerKey) if (m.record) encoding2_2.encode(state, m.record) }, decode (state) { const res = {} res.blindPeerKey = null res.writerKey = null res.record = null const flags = state.start < state.end ? c.uint.decode(state) : 0 if ((flags & 1) !== 0) res.blindPeerKey = c.fixed32.decode(state) if ((flags & 2) !== 0) res.writerKey = c.fixed32.decode(state) if ((flags & 4) !== 0) res.record = encoding2_2.decode(state) return res } } function getStructByName (name) { switch (name) { case '@hyperns/name-entry': return encoding0 case '@hyperns/op': return encoding1 case '@hyperns/op/value': return encoding2 default: throw new Error('Encoder not found ' + name) } } function resolveStruct (name, v = VERSION) { const enc = getStructByName(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) } } } module.exports = { resolveStruct, version }