bare-rpc 0.2.7 → 0.2.8
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/README.md +5 -5
- package/index.d.ts +4 -4
- package/lib/messages.js +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ A boolean for whether the request has been sent.
|
|
|
65
65
|
|
|
66
66
|
A boolean for whether the request has received a reply.
|
|
67
67
|
|
|
68
|
-
#### `req.send(data[, encoding])`
|
|
68
|
+
#### `req.send([data[, encoding]])`
|
|
69
69
|
|
|
70
70
|
Send the request with the provided `data`. `data` can be a buffer or a string which will be encoded using `encoding`.
|
|
71
71
|
|
|
@@ -101,7 +101,7 @@ A boolean for whether a reply has been sent.
|
|
|
101
101
|
|
|
102
102
|
A boolean for whether the request has been received as a stream. See [`req.createRequestStream()`](#const-stream--reqcreaterequeststream) for receiving requests as a stream.
|
|
103
103
|
|
|
104
|
-
#### `req.reply(data, [encoding])`
|
|
104
|
+
#### `req.reply([data, [encoding]])`
|
|
105
105
|
|
|
106
106
|
Reply to the request with the provided `data`. `data` can be a buffer or a string which will be encoded using `encoding`.
|
|
107
107
|
|
|
@@ -141,12 +141,12 @@ Define a command and the handler for it. The callback for a command receives bot
|
|
|
141
141
|
|
|
142
142
|
Options include:
|
|
143
143
|
|
|
144
|
-
```
|
|
145
|
-
{
|
|
144
|
+
```js
|
|
145
|
+
options = {
|
|
146
146
|
// Encoding for incoming request
|
|
147
147
|
requestEncoding: c.raw,
|
|
148
148
|
// Encoding for outgoing response
|
|
149
|
-
responseEncoding: c.raw
|
|
149
|
+
responseEncoding: c.raw
|
|
150
150
|
}
|
|
151
151
|
```
|
|
152
152
|
|
package/index.d.ts
CHANGED
|
@@ -27,11 +27,11 @@ interface RPCIncomingRequest {
|
|
|
27
27
|
readonly rpc: RPC
|
|
28
28
|
readonly id: number
|
|
29
29
|
readonly command: number
|
|
30
|
-
readonly data: Buffer
|
|
30
|
+
readonly data: Buffer | null
|
|
31
31
|
readonly sent: boolean
|
|
32
32
|
readonly received: boolean
|
|
33
33
|
|
|
34
|
-
reply(data
|
|
34
|
+
reply(data?: Buffer | string | null, encoding?: BufferEncoding): void
|
|
35
35
|
|
|
36
36
|
createResponseStream(opts?: WritableOptions): RPCOutgoingStream
|
|
37
37
|
createRequestStream(opts?: ReadableOptions): RPCIncomingStream
|
|
@@ -48,9 +48,9 @@ interface RPCOutgoingRequest {
|
|
|
48
48
|
readonly sent: boolean
|
|
49
49
|
readonly received: boolean
|
|
50
50
|
|
|
51
|
-
send(data
|
|
51
|
+
send(data?: Buffer | string | null, encoding?: BufferEncoding): void
|
|
52
52
|
|
|
53
|
-
reply(encoding?: BufferEncoding): Promise<Buffer | string>
|
|
53
|
+
reply(encoding?: BufferEncoding): Promise<Buffer | string | null>
|
|
54
54
|
|
|
55
55
|
createRequestStream(opts?: WritableOptions): RPCOutgoingStream
|
|
56
56
|
createResponseStream(opts?: ReadableOptions): RPCIncomingStream
|
package/lib/messages.js
CHANGED
|
@@ -52,7 +52,7 @@ exports.header = {
|
|
|
52
52
|
break
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
if (hasData) c.uint.preencode(state, m.data.byteLength)
|
|
55
|
+
if (hasData) c.uint.preencode(state, m.data ? m.data.byteLength : 0)
|
|
56
56
|
},
|
|
57
57
|
encode(state, m) {
|
|
58
58
|
const frame = state.start
|
|
@@ -89,13 +89,16 @@ exports.header = {
|
|
|
89
89
|
break
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
if (hasData) c.uint.encode(state, m.data.byteLength)
|
|
92
|
+
if (hasData) c.uint.encode(state, m.data ? m.data.byteLength : 0)
|
|
93
93
|
|
|
94
94
|
const end = state.start
|
|
95
95
|
|
|
96
96
|
state.start = frame
|
|
97
97
|
|
|
98
|
-
c.uint32.encode(
|
|
98
|
+
c.uint32.encode(
|
|
99
|
+
state,
|
|
100
|
+
end - start + (hasData && m.data ? m.data.byteLength : 0)
|
|
101
|
+
)
|
|
99
102
|
|
|
100
103
|
state.start = end
|
|
101
104
|
}
|