starpc 0.22.7 → 0.23.0

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.
@@ -1,5 +1,5 @@
1
1
  // Code generated by protoc-gen-go-vtproto. DO NOT EDIT.
2
- // protoc-gen-go-vtproto version: v0.4.0
2
+ // protoc-gen-go-vtproto version: v0.6.0
3
3
  // source: github.com/aperturerobotics/starpc/echo/echo.proto
4
4
 
5
5
  package echo
@@ -7,8 +7,8 @@ package echo
7
7
  import (
8
8
  fmt "fmt"
9
9
  io "io"
10
- bits "math/bits"
11
10
 
11
+ protohelpers "github.com/planetscale/vtprotobuf/protohelpers"
12
12
  proto "google.golang.org/protobuf/proto"
13
13
  protoimpl "google.golang.org/protobuf/runtime/protoimpl"
14
14
  )
@@ -24,9 +24,8 @@ func (m *EchoMsg) CloneVT() *EchoMsg {
24
24
  if m == nil {
25
25
  return (*EchoMsg)(nil)
26
26
  }
27
- r := &EchoMsg{
28
- Body: m.Body,
29
- }
27
+ r := new(EchoMsg)
28
+ r.Body = m.Body
30
29
  if len(m.unknownFields) > 0 {
31
30
  r.unknownFields = make([]byte, len(m.unknownFields))
32
31
  copy(r.unknownFields, m.unknownFields)
@@ -90,24 +89,13 @@ func (m *EchoMsg) MarshalToSizedBufferVT(dAtA []byte) (int, error) {
90
89
  if len(m.Body) > 0 {
91
90
  i -= len(m.Body)
92
91
  copy(dAtA[i:], m.Body)
93
- i = encodeVarint(dAtA, i, uint64(len(m.Body)))
92
+ i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Body)))
94
93
  i--
95
94
  dAtA[i] = 0xa
96
95
  }
97
96
  return len(dAtA) - i, nil
98
97
  }
99
98
 
100
- func encodeVarint(dAtA []byte, offset int, v uint64) int {
101
- offset -= sov(v)
102
- base := offset
103
- for v >= 1<<7 {
104
- dAtA[offset] = uint8(v&0x7f | 0x80)
105
- v >>= 7
106
- offset++
107
- }
108
- dAtA[offset] = uint8(v)
109
- return base
110
- }
111
99
  func (m *EchoMsg) SizeVT() (n int) {
112
100
  if m == nil {
113
101
  return 0
@@ -116,18 +104,12 @@ func (m *EchoMsg) SizeVT() (n int) {
116
104
  _ = l
117
105
  l = len(m.Body)
118
106
  if l > 0 {
119
- n += 1 + l + sov(uint64(l))
107
+ n += 1 + l + protohelpers.SizeOfVarint(uint64(l))
120
108
  }
121
109
  n += len(m.unknownFields)
122
110
  return n
123
111
  }
124
112
 
125
- func sov(x uint64) (n int) {
126
- return (bits.Len64(x|1) + 6) / 7
127
- }
128
- func soz(x uint64) (n int) {
129
- return sov(uint64((x << 1) ^ uint64((int64(x) >> 63))))
130
- }
131
113
  func (m *EchoMsg) UnmarshalVT(dAtA []byte) error {
132
114
  l := len(dAtA)
133
115
  iNdEx := 0
@@ -136,7 +118,7 @@ func (m *EchoMsg) UnmarshalVT(dAtA []byte) error {
136
118
  var wire uint64
137
119
  for shift := uint(0); ; shift += 7 {
138
120
  if shift >= 64 {
139
- return ErrIntOverflow
121
+ return protohelpers.ErrIntOverflow
140
122
  }
141
123
  if iNdEx >= l {
142
124
  return io.ErrUnexpectedEOF
@@ -164,7 +146,7 @@ func (m *EchoMsg) UnmarshalVT(dAtA []byte) error {
164
146
  var stringLen uint64
165
147
  for shift := uint(0); ; shift += 7 {
166
148
  if shift >= 64 {
167
- return ErrIntOverflow
149
+ return protohelpers.ErrIntOverflow
168
150
  }
169
151
  if iNdEx >= l {
170
152
  return io.ErrUnexpectedEOF
@@ -178,11 +160,11 @@ func (m *EchoMsg) UnmarshalVT(dAtA []byte) error {
178
160
  }
179
161
  intStringLen := int(stringLen)
180
162
  if intStringLen < 0 {
181
- return ErrInvalidLength
163
+ return protohelpers.ErrInvalidLength
182
164
  }
183
165
  postIndex := iNdEx + intStringLen
184
166
  if postIndex < 0 {
185
- return ErrInvalidLength
167
+ return protohelpers.ErrInvalidLength
186
168
  }
187
169
  if postIndex > l {
188
170
  return io.ErrUnexpectedEOF
@@ -191,12 +173,12 @@ func (m *EchoMsg) UnmarshalVT(dAtA []byte) error {
191
173
  iNdEx = postIndex
192
174
  default:
193
175
  iNdEx = preIndex
194
- skippy, err := skip(dAtA[iNdEx:])
176
+ skippy, err := protohelpers.Skip(dAtA[iNdEx:])
195
177
  if err != nil {
196
178
  return err
197
179
  }
198
180
  if (skippy < 0) || (iNdEx+skippy) < 0 {
199
- return ErrInvalidLength
181
+ return protohelpers.ErrInvalidLength
200
182
  }
201
183
  if (iNdEx + skippy) > l {
202
184
  return io.ErrUnexpectedEOF
@@ -211,88 +193,3 @@ func (m *EchoMsg) UnmarshalVT(dAtA []byte) error {
211
193
  }
212
194
  return nil
213
195
  }
214
-
215
- func skip(dAtA []byte) (n int, err error) {
216
- l := len(dAtA)
217
- iNdEx := 0
218
- depth := 0
219
- for iNdEx < l {
220
- var wire uint64
221
- for shift := uint(0); ; shift += 7 {
222
- if shift >= 64 {
223
- return 0, ErrIntOverflow
224
- }
225
- if iNdEx >= l {
226
- return 0, io.ErrUnexpectedEOF
227
- }
228
- b := dAtA[iNdEx]
229
- iNdEx++
230
- wire |= (uint64(b) & 0x7F) << shift
231
- if b < 0x80 {
232
- break
233
- }
234
- }
235
- wireType := int(wire & 0x7)
236
- switch wireType {
237
- case 0:
238
- for shift := uint(0); ; shift += 7 {
239
- if shift >= 64 {
240
- return 0, ErrIntOverflow
241
- }
242
- if iNdEx >= l {
243
- return 0, io.ErrUnexpectedEOF
244
- }
245
- iNdEx++
246
- if dAtA[iNdEx-1] < 0x80 {
247
- break
248
- }
249
- }
250
- case 1:
251
- iNdEx += 8
252
- case 2:
253
- var length int
254
- for shift := uint(0); ; shift += 7 {
255
- if shift >= 64 {
256
- return 0, ErrIntOverflow
257
- }
258
- if iNdEx >= l {
259
- return 0, io.ErrUnexpectedEOF
260
- }
261
- b := dAtA[iNdEx]
262
- iNdEx++
263
- length |= (int(b) & 0x7F) << shift
264
- if b < 0x80 {
265
- break
266
- }
267
- }
268
- if length < 0 {
269
- return 0, ErrInvalidLength
270
- }
271
- iNdEx += length
272
- case 3:
273
- depth++
274
- case 4:
275
- if depth == 0 {
276
- return 0, ErrUnexpectedEndOfGroup
277
- }
278
- depth--
279
- case 5:
280
- iNdEx += 4
281
- default:
282
- return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
283
- }
284
- if iNdEx < 0 {
285
- return 0, ErrInvalidLength
286
- }
287
- if depth == 0 {
288
- return iNdEx, nil
289
- }
290
- }
291
- return 0, io.ErrUnexpectedEOF
292
- }
293
-
294
- var (
295
- ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling")
296
- ErrIntOverflow = fmt.Errorf("proto: integer overflow")
297
- ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group")
298
- )
package/go.mod CHANGED
@@ -9,12 +9,14 @@ require (
9
9
  )
10
10
 
11
11
  require (
12
- github.com/aperturerobotics/util v1.12.0 // latest
12
+ github.com/aperturerobotics/util v1.13.3 // latest
13
13
  github.com/libp2p/go-libp2p v0.32.2 // latest
14
- github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512 // master
14
+ github.com/libp2p/go-yamux/v4 v4.0.2-0.20240206065824-7222fbc3459d // master
15
15
  github.com/sirupsen/logrus v1.9.3 // latest
16
16
  )
17
17
 
18
+ require github.com/planetscale/vtprotobuf v0.6.0
19
+
18
20
  require (
19
21
  github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
20
22
  github.com/ipfs/go-cid v0.4.1 // indirect
@@ -33,6 +35,6 @@ require (
33
35
  github.com/spaolacci/murmur3 v1.1.0 // indirect
34
36
  golang.org/x/crypto v0.17.0 // indirect
35
37
  golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
36
- golang.org/x/sys v0.15.0 // indirect
38
+ golang.org/x/sys v0.16.0 // indirect
37
39
  lukechampine.com/blake3 v1.2.1 // indirect
38
40
  )
package/go.sum CHANGED
@@ -1,16 +1,16 @@
1
- github.com/aperturerobotics/util v1.11.0 h1:SpbpNw23DACYkiZ9cCauP98Nwg73T04YkfD4E/WZ2Hc=
2
- github.com/aperturerobotics/util v1.11.0/go.mod h1:d84OAQAGXCpl7JOBstnal91Lm6nKgk+vBgtHPgxBYrQ=
3
- github.com/aperturerobotics/util v1.11.3 h1:qg7TTe1L/rtoENssNKwz+VMeA3CCDVQ5SnYWig6WMOk=
4
- github.com/aperturerobotics/util v1.11.3/go.mod h1:d84OAQAGXCpl7JOBstnal91Lm6nKgk+vBgtHPgxBYrQ=
5
- github.com/aperturerobotics/util v1.12.0 h1:jdEU/xbApQIuc4cq2/JRnJmA21243StGsODIU5vekik=
6
- github.com/aperturerobotics/util v1.12.0/go.mod h1:d84OAQAGXCpl7JOBstnal91Lm6nKgk+vBgtHPgxBYrQ=
1
+ github.com/aperturerobotics/util v1.13.2 h1:MTe8MO+Tfo9d3Z4Zi6Akm//rIymy5gyoAOIEHQdFrOU=
2
+ github.com/aperturerobotics/util v1.13.2/go.mod h1:d84OAQAGXCpl7JOBstnal91Lm6nKgk+vBgtHPgxBYrQ=
3
+ github.com/aperturerobotics/util v1.13.3 h1:N4JXKYql0R/A2hMuV79SZ2vaftf8tiN8DUJ8sGc7Rso=
4
+ github.com/aperturerobotics/util v1.13.3/go.mod h1:JdziNd9tR6lWqc9bSMIe1At8Gagrg986rmtZuPCv6+w=
7
5
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8
6
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9
7
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10
8
  github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
9
+ github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
11
10
  github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
12
11
  github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
13
12
  github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
13
+ github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
14
14
  github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
15
15
  github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
16
16
  github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
@@ -20,8 +20,9 @@ github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QT
20
20
  github.com/libp2p/go-libp2p v0.32.2 h1:s8GYN4YJzgUoyeYNPdW7JZeZ5Ee31iNaIBfGYMAY4FQ=
21
21
  github.com/libp2p/go-libp2p v0.32.2/go.mod h1:E0LKe+diV/ZVJVnOJby8VC5xzHF0660osg71skcxJvk=
22
22
  github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
23
- github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512 h1:QvLt0Hr2Qmex+9wrv/tBeDsZ5AutKdy6ZF7pGTyEeQY=
24
- github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512/go.mod h1:OsNeDpmxccy93bUsruLEdsqIuO1VbBOFsQ4c4GfwenE=
23
+ github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
24
+ github.com/libp2p/go-yamux/v4 v4.0.2-0.20240206065824-7222fbc3459d h1:Lag2VlBLRAiYKMnbIJGSDFmfSIoaeQRZ3wJXt91ZWV8=
25
+ github.com/libp2p/go-yamux/v4 v4.0.2-0.20240206065824-7222fbc3459d/go.mod h1:OsNeDpmxccy93bUsruLEdsqIuO1VbBOFsQ4c4GfwenE=
25
26
  github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
26
27
  github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
27
28
  github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
@@ -44,6 +45,8 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n
44
45
  github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
45
46
  github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
46
47
  github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
48
+ github.com/planetscale/vtprotobuf v0.6.0 h1:nBeETjudeJ5ZgBHUz1fVHvbqUKnYOXNhsIEabROxmNA=
49
+ github.com/planetscale/vtprotobuf v0.6.0/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
47
50
  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
48
51
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
49
52
  github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
@@ -53,6 +56,7 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2
53
56
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
54
57
  github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
55
58
  github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
59
+ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
56
60
  golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
57
61
  golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
58
62
  golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
@@ -61,11 +65,14 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
61
65
  golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
62
66
  golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
63
67
  golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
68
+ golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
69
+ golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
64
70
  google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
65
71
  google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
66
72
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
67
73
  gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
68
74
  gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
75
+ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
69
76
  lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
70
77
  lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
71
78
  nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
@@ -6,7 +6,7 @@ unset GOARCH
6
6
 
7
7
  echo "Compiling ts..."
8
8
  # ../node_modules/.bin/tsc --out integration.js --project tsconfig.json
9
- ../node_modules/.bin/esbuild integration.ts --bundle --platform=node --outfile=integration.js
9
+ ../node_modules/.bin/esbuild integration.ts --bundle --sourcemap --platform=node --outfile=integration.js
10
10
 
11
11
  echo "Compiling go..."
12
12
  go build -o integration -v ./
@@ -13,14 +13,14 @@ async function runRPC() {
13
13
  const channel = new WebSocketConn(ws, 'outbound')
14
14
  const client = channel.buildClient()
15
15
 
16
- console.log('Running RpcStream test via WebSocket..')
17
- await runRpcStreamTest(client)
18
-
19
16
  console.log('Running client test via WebSocket..')
20
17
  await runClientTest(client)
21
18
 
22
19
  console.log('Running abort controller test via WebSocket..')
23
20
  await runAbortControllerTest(client)
21
+
22
+ console.log('Running RpcStream test via WebSocket..')
23
+ await runRpcStreamTest(client)
24
24
  }
25
25
 
26
26
  process.on('unhandledRejection', (ev) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.22.7",
3
+ "version": "0.23.0",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -61,10 +61,10 @@
61
61
  "singleQuote": true
62
62
  },
63
63
  "devDependencies": {
64
- "@aperturerobotics/ts-common": "^0.8.2",
64
+ "@aperturerobotics/ts-common": "^0.8.3",
65
65
  "bufferutil": "^4.0.7",
66
66
  "depcheck": "^1.4.6",
67
- "esbuild": "^0.19.11",
67
+ "esbuild": "^0.20.0",
68
68
  "prettier": "^3.2.4",
69
69
  "rimraf": "^5.0.1",
70
70
  "ts-poet": "6.6.0",
@@ -74,13 +74,13 @@
74
74
  },
75
75
  "dependencies": {
76
76
  "@aptre/it-ws": "^1.0.0",
77
- "@chainsafe/libp2p-yamux": "^5.0.0",
78
- "@libp2p/interface": "^0.1.2",
77
+ "@chainsafe/libp2p-yamux": "^6.0.2",
78
+ "@libp2p/interface": "^1.1.3",
79
+ "@libp2p/logger": "^4.0.6",
79
80
  "event-iterator": "^2.0.0",
80
81
  "is-promise": "^4.0.0",
81
82
  "isomorphic-ws": "^5.0.0",
82
83
  "it-first": "^3.0.3",
83
- "it-length-prefixed": "^9.0.4",
84
84
  "it-pipe": "^3.0.1",
85
85
  "it-pushable": "^3.2.3",
86
86
  "it-stream-types": "^2.0.1",
package/srpc/client.ts CHANGED
@@ -70,7 +70,7 @@ export class Client implements TsProtoRpc {
70
70
  .then(async (call) => {
71
71
  return writeToPushable(call.rpcDataSource, serverData)
72
72
  })
73
- .catch(err => serverData.end(err))
73
+ .catch((err) => serverData.end(err))
74
74
  return serverData
75
75
  }
76
76
 
@@ -94,7 +94,7 @@ export class Client implements TsProtoRpc {
94
94
  serverData.end(err as Error)
95
95
  }
96
96
  })
97
- .catch(err => serverData.end(err))
97
+ .catch((err) => serverData.end(err))
98
98
  return serverData
99
99
  }
100
100
 
package/srpc/conn.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  import { yamux } from '@chainsafe/libp2p-yamux'
2
- import type { Direction, Stream } from '@libp2p/interface/connection'
3
2
  import type {
3
+ Direction,
4
+ Stream,
4
5
  StreamMuxer,
5
6
  StreamMuxerFactory,
6
- } from '@libp2p/interface/stream-muxer'
7
+ } from '@libp2p/interface'
7
8
  import { pipe } from 'it-pipe'
8
9
  import type { Duplex, Source } from 'it-stream-types'
9
10
  import { Uint8ArrayList } from 'uint8arraylist'
10
11
  import isPromise from 'is-promise'
11
12
  import { pushable, Pushable } from 'it-pushable'
13
+ import { defaultLogger } from '@libp2p/logger'
12
14
 
13
15
  import type { OpenStreamFunc, Stream as SRPCStream } from './stream.js'
14
16
  import { Client } from './client.js'
@@ -73,7 +75,11 @@ export class Conn
73
75
  if (server) {
74
76
  this.server = server
75
77
  }
76
- const muxerFactory = connParams?.muxerFactory ?? yamux()()
78
+ const muxerFactory =
79
+ connParams?.muxerFactory ??
80
+ yamux({ enableKeepAlive: false })({
81
+ logger: defaultLogger(),
82
+ })
77
83
  this.muxer = muxerFactory.createStreamMuxer({
78
84
  onIncomingStream: this.handleIncomingStream.bind(this),
79
85
  direction: connParams?.direction || 'outbound',
package/srpc/index.ts CHANGED
@@ -32,6 +32,13 @@ export {
32
32
  prependLengthPrefixTransform,
33
33
  decodePacketSource,
34
34
  encodePacketSource,
35
+ uint32LEDecode,
36
+ uint32LEEncode,
37
+ decodeUint32Le,
38
+ encodeUint32Le,
39
+ lengthPrefixDecode,
40
+ lengthPrefixEncode,
41
+ prependPacketLen,
35
42
  } from './packet.js'
36
43
  export { combineUint8ArrayListTransform } from './array-list.js'
37
44
  export { ValueCtr } from './value-ctr.js'
File without changes
package/srpc/message.ts CHANGED
@@ -42,7 +42,7 @@ export function buildDecodeMessageTransform<T>(
42
42
  def: MessageDefinition<T>,
43
43
  memoize?: boolean,
44
44
  ): DecodeMessageTransform<T> {
45
- const decode = memoize ? memoProtoDecode(def) : def.decode.bind(def)
45
+ const decode = !memoize ? def.decode.bind(def) : memoProtoDecode(def)
46
46
 
47
47
  // decodeMessageSource unmarshals and async yields encoded Messages.
48
48
  return async function* decodeMessageSource(
@@ -71,11 +71,11 @@ export function buildEncodeMessageTransform<T>(
71
71
  def: MessageDefinition<T>,
72
72
  memoize?: boolean,
73
73
  ): EncodeMessageTransform<T> {
74
- const encode = memoize
75
- ? memoProto(def)
76
- : (msg: T): Uint8Array => {
74
+ const encode = !memoize
75
+ ? (msg: T): Uint8Array => {
77
76
  return def.encode(msg).finish()
78
77
  }
78
+ : memoProto(def)
79
79
 
80
80
  // encodeMessageSource encodes messages to byte arrays.
81
81
  return async function* encodeMessageSource(
package/srpc/packet.ts CHANGED
@@ -1,15 +1,11 @@
1
- import {
2
- encode as lengthPrefixEncode,
3
- decode as lengthPrefixDecode,
4
- } from 'it-length-prefixed'
5
1
  import { Uint8ArrayList } from 'uint8arraylist'
2
+ import { Source, Transform } from 'it-stream-types'
6
3
 
7
4
  import { Packet } from './rpcproto.pb.js'
8
5
  import {
9
6
  buildDecodeMessageTransform,
10
7
  buildEncodeMessageTransform,
11
8
  } from './message.js'
12
- import { Source, Transform } from 'it-stream-types'
13
9
 
14
10
  // decodePacketSource decodes packets from a binary data stream.
15
11
  export const decodePacketSource = buildDecodeMessageTransform<Packet>(Packet)
@@ -18,7 +14,7 @@ export const decodePacketSource = buildDecodeMessageTransform<Packet>(Packet)
18
14
  export const encodePacketSource = buildEncodeMessageTransform<Packet>(Packet)
19
15
 
20
16
  // uint32LEDecode removes the length prefix.
21
- const uint32LEDecode = (data: Uint8ArrayList) => {
17
+ export const uint32LEDecode = (data: Uint8ArrayList) => {
22
18
  if (data.length < 4) {
23
19
  throw RangeError('Could not decode int32BE')
24
20
  }
@@ -28,34 +24,80 @@ const uint32LEDecode = (data: Uint8ArrayList) => {
28
24
  uint32LEDecode.bytes = 4
29
25
 
30
26
  // uint32LEEncode adds the length prefix.
31
- const uint32LEEncode = (value: number) => {
27
+ export const uint32LEEncode = (value: number) => {
32
28
  const data = new Uint8ArrayList(new Uint8Array(4))
33
29
  data.setUint32(0, value, true)
34
30
  return data
35
31
  }
36
32
  uint32LEEncode.bytes = 4
37
33
 
34
+ // lengthPrefixEncode transforms a source to a length-prefixed Uint8ArrayList stream.
35
+ export async function* lengthPrefixEncode(
36
+ source: Source<Uint8Array | Uint8ArrayList>,
37
+ lengthEncoder: typeof uint32LEEncode,
38
+ ) {
39
+ for await (const chunk of source) {
40
+ // Encode the length of the chunk.
41
+ const length = chunk instanceof Uint8Array ? chunk.length : chunk.byteLength
42
+ const lengthEncoded = lengthEncoder(length)
43
+
44
+ // Concatenate the length prefix and the data.
45
+ yield new Uint8ArrayList(lengthEncoded, chunk)
46
+ }
47
+ }
48
+
49
+ // lengthPrefixDecode decodes a length-prefixed source to a Uint8ArrayList stream.
50
+ export async function* lengthPrefixDecode(
51
+ source: Source<Uint8Array | Uint8ArrayList>,
52
+ lengthDecoder: typeof uint32LEDecode,
53
+ ) {
54
+ const buffer = new Uint8ArrayList()
55
+
56
+ for await (const chunk of source) {
57
+ buffer.append(chunk)
58
+
59
+ // Continue extracting messages while buffer contains enough data for decoding.
60
+ while (buffer.length >= lengthDecoder.bytes) {
61
+ const messageLength = lengthDecoder(buffer)
62
+ const totalLength = lengthDecoder.bytes + messageLength
63
+
64
+ if (buffer.length < totalLength) break // Wait for more data if the full message hasn't arrived.
65
+
66
+ // Extract the message excluding the length prefix.
67
+ const message = buffer.sublist(lengthDecoder.bytes, totalLength)
68
+ yield message
69
+
70
+ // Remove the processed message from the buffer.
71
+ buffer.consume(totalLength)
72
+ }
73
+ }
74
+ }
75
+
38
76
  // prependLengthPrefixTransform adds a length prefix to a message source.
39
77
  // little-endian uint32
40
- export function prependLengthPrefixTransform(): Transform<
78
+ export function prependLengthPrefixTransform(
79
+ lengthEncoder = uint32LEEncode,
80
+ ): Transform<
41
81
  Source<Uint8Array | Uint8ArrayList>,
42
- | AsyncGenerator<Uint8Array, void, undefined>
43
- | Generator<Uint8Array, void, undefined>
82
+ | AsyncGenerator<Uint8ArrayList, void, undefined>
83
+ | Generator<Uint8ArrayList, void, undefined>
44
84
  > {
45
85
  return (source: Source<Uint8Array | Uint8ArrayList>) => {
46
- return lengthPrefixEncode(source, { lengthEncoder: uint32LEEncode })
86
+ return lengthPrefixEncode(source, lengthEncoder)
47
87
  }
48
88
  }
49
89
 
50
90
  // parseLengthPrefixTransform parses the length prefix from a message source.
51
91
  // little-endian uint32
52
- export function parseLengthPrefixTransform(): Transform<
53
- Source<Uint8Array | Uint8ArrayList>, // Allow both AsyncIterable and Iterable
92
+ export function parseLengthPrefixTransform(
93
+ lengthDecoder = uint32LEDecode,
94
+ ): Transform<
95
+ Source<Uint8Array | Uint8ArrayList>,
54
96
  | AsyncGenerator<Uint8ArrayList, void, unknown>
55
97
  | Generator<Uint8ArrayList, void, unknown>
56
98
  > {
57
99
  return (source: Source<Uint8Array | Uint8ArrayList>) => {
58
- return lengthPrefixDecode(source, { lengthDecoder: uint32LEDecode })
100
+ return lengthPrefixDecode(source, lengthDecoder)
59
101
  }
60
102
  }
61
103
 
@@ -1,7 +1,7 @@
1
1
  // Code generated by protoc-gen-go. DO NOT EDIT.
2
2
  // versions:
3
- // protoc-gen-go v1.31.0-devel
4
- // protoc v4.25.1
3
+ // protoc-gen-go v1.32.0-devel
4
+ // protoc v4.25.2
5
5
  // source: github.com/aperturerobotics/starpc/srpc/rpcproto.proto
6
6
 
7
7
  package srpc