bare-rpc 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +12 -12
- package/lib/messages.js +8 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -154,22 +154,22 @@ module.exports = exports = class RPC {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
_onafterframe() {
|
|
157
|
-
|
|
158
|
-
const buffer =
|
|
159
|
-
this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer)
|
|
157
|
+
if (this._buffered < this._frame) return
|
|
160
158
|
|
|
161
|
-
|
|
159
|
+
const buffer =
|
|
160
|
+
this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer)
|
|
162
161
|
|
|
163
|
-
|
|
164
|
-
this._buffer = this._buffered > 0 ? [buffer.subarray(frame)] : []
|
|
165
|
-
this._frame = -1
|
|
162
|
+
const frame = this._frame
|
|
166
163
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
this._buffered -= frame
|
|
165
|
+
this._buffer = this._buffered > 0 ? [buffer.subarray(frame)] : []
|
|
166
|
+
this._frame = -1
|
|
167
|
+
|
|
168
|
+
this._onmessage(buffer.subarray(0, frame))
|
|
169
|
+
this._onbeforeframe()
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
_onmessage(buffer) {
|
|
172
|
+
async _onmessage(buffer) {
|
|
173
173
|
let message
|
|
174
174
|
try {
|
|
175
175
|
message = m.message.decode(c.state(0, buffer.length, buffer))
|
|
@@ -189,7 +189,7 @@ module.exports = exports = class RPC {
|
|
|
189
189
|
)
|
|
190
190
|
|
|
191
191
|
try {
|
|
192
|
-
this._onrequest(request)
|
|
192
|
+
await this._onrequest(request)
|
|
193
193
|
} catch (err) {
|
|
194
194
|
safetyCatch(err)
|
|
195
195
|
|
package/lib/messages.js
CHANGED
|
@@ -53,16 +53,20 @@ const response = {
|
|
|
53
53
|
c.bool.encode(state, !!m.error)
|
|
54
54
|
c.uint.encode(state, m.stream)
|
|
55
55
|
|
|
56
|
-
if (m.error) error.encode(state, m)
|
|
56
|
+
if (m.error) error.encode(state, m.error)
|
|
57
57
|
else if (m.stream === 0) c.buffer.encode(state, m.data)
|
|
58
58
|
},
|
|
59
59
|
decode(state) {
|
|
60
|
-
const
|
|
60
|
+
const err = c.bool.decode(state)
|
|
61
61
|
const stream = c.uint.decode(state)
|
|
62
62
|
|
|
63
|
-
if (
|
|
64
|
-
|
|
63
|
+
if (err) {
|
|
64
|
+
return { stream, error: error.decode(state), data: null }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (stream === 0) {
|
|
65
68
|
return { stream, error: null, data: c.buffer.decode(state) }
|
|
69
|
+
}
|
|
66
70
|
|
|
67
71
|
return { stream, error: null, data: null }
|
|
68
72
|
}
|