forked from holepunchto/hypershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.js
117 lines (109 loc) · 2.46 KB
/
messages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const c = require('compact-encoding')
const stringArray = c.array(c.string)
const handshakeSpawn = {
preencode (state, s) {
c.string.preencode(state, s.command || '')
stringArray.preencode(state, s.args || [])
c.uint.preencode(state, s.width)
c.uint.preencode(state, s.height)
},
encode (state, s) {
c.string.encode(state, s.command || '')
stringArray.encode(state, s.args || [])
c.uint.encode(state, s.width)
c.uint.encode(state, s.height)
},
decode (state) {
return {
command: c.string.decode(state),
args: stringArray.decode(state),
width: c.uint.decode(state),
height: c.uint.decode(state)
}
}
}
const handshakeUpload = {
preencode (state, u) {
c.string.preencode(state, u.target || '')
c.bool.preencode(state, u.isDirectory || false)
},
encode (state, u) {
c.string.encode(state, u.target || '')
c.bool.encode(state, u.isDirectory || false)
},
decode (state) {
return {
target: c.string.decode(state),
isDirectory: c.bool.decode(state)
}
}
}
const handshakeDownload = {
preencode (state, u) {
c.string.preencode(state, u.source || '')
},
encode (state, u) {
c.string.encode(state, u.source || '')
},
decode (state) {
return {
source: c.string.decode(state)
}
}
}
const downloadHeader = {
preencode (state, d) {
c.bool.preencode(state, d.isDirectory)
},
encode (state, d) {
c.bool.encode(state, d.isDirectory)
},
decode (state) {
return {
isDirectory: c.bool.decode(state)
}
}
}
const error = {
preencode (state, e) {
c.string.preencode(state, e.code || '')
c.string.preencode(state, e.path || '')
c.string.preencode(state, e.message || '')
},
encode (state, e) {
c.string.encode(state, e.code || '')
c.string.encode(state, e.path || '')
c.string.encode(state, e.message || '')
},
decode (state) {
return {
code: c.string.decode(state),
path: c.string.decode(state),
message: c.string.decode(state)
}
}
}
const resize = {
preencode (state, r) {
c.uint.preencode(state, r.width)
c.uint.preencode(state, r.height)
},
encode (state, r) {
c.uint.encode(state, r.width)
c.uint.encode(state, r.height)
},
decode (state) {
return {
width: c.uint.decode(state),
height: c.uint.decode(state)
}
}
}
module.exports = {
handshakeSpawn,
handshakeUpload,
handshakeDownload,
downloadHeader,
error,
resize
}