This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
kernel-protomux/messages.js

42 lines
942 B
JavaScript
Raw Normal View History

2021-11-15 15:12:21 +00:00
const c = require('compact-encoding')
const version = {
preencode (state, v) {
c.uint.preencode(state, v.major)
c.uint.preencode(state, v.minor)
},
encode (state, v) {
c.uint.encode(state, v.major)
c.uint.encode(state, v.minor)
},
decode (state, v) {
return {
major: c.uint.decode(state),
minor: c.uint.decode(state)
}
}
}
2021-12-30 20:13:47 +00:00
exports.addProtocol = {
2021-11-15 15:12:21 +00:00
preencode (state, p) {
c.string.preencode(state, p.name)
version.preencode(state, p.version)
2021-12-30 20:13:47 +00:00
c.uint.preencode(state, p.offset)
c.uint.preencode(state, p.length)
2021-11-15 15:12:21 +00:00
},
encode (state, p) {
c.string.encode(state, p.name)
version.encode(state, p.version)
2021-12-30 20:13:47 +00:00
c.uint.encode(state, p.offset)
c.uint.encode(state, p.length)
2021-11-15 15:12:21 +00:00
},
decode (state, p) {
return {
name: c.string.decode(state),
version: version.decode(state),
2021-12-30 20:13:47 +00:00
offset: c.uint.decode(state),
length: c.uint.decode(state)
2021-11-15 15:12:21 +00:00
}
}
}