/**
* Wire codec for the release-event-log Hypercore entries.
*
* Single entry type, compact-encoded:
*
* { op: uint8, // 0=published, 1=promoted, 2=unpinned, 3=deleted
* repo: string, // repo name
* version: string, // release version ('' where the op is channel-only)
* channel: string, // channel name ('' when not channel-scoped)
* ts: uint } // unix ms
*
* Deliberately its OWN log rather than a new op code on RepoEventLog:
* `RepoPuller._enqueue` treats every entry whose op is not OP_RETIRED as
* "git-pull this repo", so a release op appended there would make every
* already-deployed mirror spuriously git-fetch on each publish. A separate
* core is also what OrgEventLog did for the same reason — different domain,
* different log, same single-writer/read-replica architecture.
*/
import c from 'compact-encoding'
export const entry = {
preencode (state, m) {
c.uint8.preencode(state, m.op | 0)
c.string.preencode(state, m.repo || '')
c.string.preencode(state, m.version || '')
c.string.preencode(state, m.channel || '')
c.uint.preencode(state, m.ts || 0)
},
encode (state, m) {
c.uint8.encode(state, m.op | 0)
c.string.encode(state, m.repo || '')
c.string.encode(state, m.version || '')
c.string.encode(state, m.channel || '')
c.uint.encode(state, m.ts || 0)
},
decode (state) {
const op = c.uint8.decode(state)
const repo = c.string.decode(state)
const version = c.string.decode(state)
const channel = c.string.decode(state)
const ts = c.uint.decode(state)
return { op, repo, version, channel, ts }
}
}