// Wire messages for the hypershell protocol — pure compact-encoding, so it
// runs unchanged on both node and bare. Ported from hypershell (shell subset).
import c from 'compact-encoding'
const stringArray = c.array(c.string)
export const handshakeSpawn = {
preencode (state, s) {
c.string.preencode(state, s.command || '')
stringArray.preencode(state, s.args || [])
c.uint.preencode(state, s.width || 0)
c.uint.preencode(state, s.height || 0)
},
encode (state, s) {
c.string.encode(state, s.command || '')
stringArray.encode(state, s.args || [])
c.uint.encode(state, s.width || 0)
c.uint.encode(state, s.height || 0)
},
decode (state) {
return {
command: c.string.decode(state),
args: stringArray.decode(state),
width: c.uint.decode(state),
height: c.uint.decode(state)
}
}
}
export const resize = {
preencode (state, r) {
c.uint.preencode(state, r.width || 0)
c.uint.preencode(state, r.height || 0)
},
encode (state, r) {
c.uint.encode(state, r.width || 0)
c.uint.encode(state, r.height || 0)
},
decode (state) {
return {
width: c.uint.decode(state),
height: c.uint.decode(state)
}
}
}