eventbus-grpc 0.42.0 → 0.44.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.
Files changed (2) hide show
  1. package/events_pb.js +108 -24
  2. package/package.json +2 -2
package/events_pb.js CHANGED
@@ -43,7 +43,7 @@ class Reader {
43
43
  }
44
44
  }
45
45
  take(n) {
46
- const value = this.bytes.slice(this.pos, this.pos + n);
46
+ const value = this.bytes.subarray(this.pos, this.pos + n);
47
47
  if (value.length !== n) throw new Error("truncated field");
48
48
  this.pos += n;
49
49
  return value;
@@ -54,25 +54,29 @@ class Reader {
54
54
  const tag = this.varint();
55
55
  const field = Number(tag >> 3n);
56
56
  const wire = Number(tag & 7n);
57
+ const f = this._f || (this._f = [0, 0, null, null]);
58
+ f[0] = field;
59
+ f[1] = wire;
57
60
  switch (wire) {
58
61
  case 0:
59
- return [field, wire, this.varint(), this.bytes.slice(start, this.pos)];
62
+ f[2] = this.varint();
63
+ break;
60
64
  case 2: {
61
65
  const len = Number(this.varint());
62
- const v = this.take(len);
63
- return [field, wire, v, this.bytes.slice(start, this.pos)];
64
- }
65
- case 1: {
66
- const v = this.take(8);
67
- return [field, wire, v, this.bytes.slice(start, this.pos)];
68
- }
69
- case 5: {
70
- const v = this.take(4);
71
- return [field, wire, v, this.bytes.slice(start, this.pos)];
66
+ f[2] = this.take(len);
67
+ break;
72
68
  }
69
+ case 1:
70
+ f[2] = this.take(8);
71
+ break;
72
+ case 5:
73
+ f[2] = this.take(4);
74
+ break;
73
75
  default:
74
76
  throw new Error("bad wire type " + wire);
75
77
  }
78
+ f[3] = this.bytes.subarray(start, this.pos);
79
+ return f;
76
80
  }
77
81
  }
78
82
 
@@ -83,6 +87,9 @@ function concatBytes(a, b) {
83
87
  return out;
84
88
  }
85
89
 
90
+ const textEncoder = new TextEncoder();
91
+ const textDecoder = new TextDecoder();
92
+ const EMPTY_BYTES = new Uint8Array(0);
86
93
  function putRaw(out, bytes) {
87
94
  for (let i = 0; i < bytes.length; i++) out.push(bytes[i]);
88
95
  }
@@ -105,7 +112,7 @@ function putBytesField(out, num, payload) {
105
112
 
106
113
  function putStringField(out, num, value) {
107
114
  if (!value) return;
108
- putBytesField(out, num, new TextEncoder().encode(value));
115
+ putBytesField(out, num, textEncoder.encode(value));
109
116
  }
110
117
 
111
118
  function putFixedField(out, num, payload) {
@@ -113,10 +120,11 @@ function putFixedField(out, num, payload) {
113
120
  out.push(...payload);
114
121
  }
115
122
 
123
+ const _fixedBuf = new Uint8Array(8);
124
+ const _fixedView = new DataView(_fixedBuf.buffer);
116
125
  function fixedBytes(value, size, write) {
117
- const bytes = new Uint8Array(size);
118
- write(new DataView(bytes.buffer), value);
119
- return bytes;
126
+ write(_fixedView, value);
127
+ return _fixedBuf.subarray(0, size);
120
128
  }
121
129
 
122
130
  function readFixed(bytes, read) {
@@ -133,7 +141,7 @@ export class TagValue {
133
141
  this.doubleValue = doubleValue;
134
142
  this.boolValue = boolValue;
135
143
  this.enumValue = enumValue;
136
- this.unknownFields = new Uint8Array(0);
144
+ this.unknownFields = EMPTY_BYTES;
137
145
  }
138
146
  static encode(msg) {
139
147
  const out = [];
@@ -156,13 +164,22 @@ export class TagValue {
156
164
  }
157
165
  static decode(bytes) {
158
166
  const msg = new TagValue();
167
+ TagValue._fill(msg, bytes);
168
+ return msg;
169
+ }
170
+ static decodeInto(msg, bytes) {
171
+ msg._reset();
172
+ TagValue._fill(msg, bytes);
173
+ return msg;
174
+ }
175
+ static _fill(msg, bytes) {
159
176
  const reader = new Reader(bytes);
160
177
  let f;
161
178
  while ((f = reader.field()) !== null) {
162
179
  const [num, wire, value, raw] = f;
163
180
  switch (num) {
164
181
  case 1: msg.tag = Number(BigInt.asIntN(32, value)); break;
165
- case 2: msg.intValue = 0n; msg.doubleValue = 0; msg.boolValue = false; msg.enumValue = 0; msg.stringValue = new TextDecoder().decode(value); break;
182
+ case 2: msg.intValue = 0n; msg.doubleValue = 0; msg.boolValue = false; msg.enumValue = 0; msg.stringValue = textDecoder.decode(value); break;
166
183
  case 3: msg.stringValue = ""; msg.doubleValue = 0; msg.boolValue = false; msg.enumValue = 0; msg.intValue = BigInt.asIntN(64, value); break;
167
184
  case 4: msg.stringValue = ""; msg.intValue = 0n; msg.boolValue = false; msg.enumValue = 0; msg.doubleValue = readFixed(value, (dv) => dv.getFloat64(0, true)); break;
168
185
  case 5: msg.stringValue = ""; msg.intValue = 0n; msg.doubleValue = 0; msg.enumValue = 0; msg.boolValue = value !== 0n; break;
@@ -172,6 +189,15 @@ export class TagValue {
172
189
  }
173
190
  return msg;
174
191
  }
192
+ _reset() {
193
+ this.tag = 0;
194
+ this.stringValue = "";
195
+ this.intValue = 0n;
196
+ this.doubleValue = 0;
197
+ this.boolValue = false;
198
+ this.enumValue = 0;
199
+ this.unknownFields = EMPTY_BYTES;
200
+ }
175
201
  }
176
202
 
177
203
  export class PublishRequest {
@@ -179,7 +205,7 @@ export class PublishRequest {
179
205
  this.tags = tags;
180
206
  this.payload = payload;
181
207
  this.publisherId = publisherId;
182
- this.unknownFields = new Uint8Array(0);
208
+ this.unknownFields = EMPTY_BYTES;
183
209
  }
184
210
  static encode(msg) {
185
211
  const out = [];
@@ -191,6 +217,15 @@ export class PublishRequest {
191
217
  }
192
218
  static decode(bytes) {
193
219
  const msg = new PublishRequest();
220
+ PublishRequest._fill(msg, bytes);
221
+ return msg;
222
+ }
223
+ static decodeInto(msg, bytes) {
224
+ msg._reset();
225
+ PublishRequest._fill(msg, bytes);
226
+ return msg;
227
+ }
228
+ static _fill(msg, bytes) {
194
229
  const reader = new Reader(bytes);
195
230
  let f;
196
231
  while ((f = reader.field()) !== null) {
@@ -198,18 +233,24 @@ export class PublishRequest {
198
233
  switch (num) {
199
234
  case 1: msg.tags.push(TagValue.decode(value)); break;
200
235
  case 2: msg.payload = value; break;
201
- case 3: msg.publisherId = new TextDecoder().decode(value); break;
236
+ case 3: msg.publisherId = textDecoder.decode(value); break;
202
237
  default: msg.unknownFields = concatBytes(msg.unknownFields, raw); break;
203
238
  }
204
239
  }
205
240
  return msg;
206
241
  }
242
+ _reset() {
243
+ this.tags = [];
244
+ this.payload = new Uint8Array(0);
245
+ this.publisherId = "";
246
+ this.unknownFields = EMPTY_BYTES;
247
+ }
207
248
  }
208
249
 
209
250
  export class PublishReply {
210
251
  constructor({ seq = 0n } = {}) {
211
252
  this.seq = seq;
212
- this.unknownFields = new Uint8Array(0);
253
+ this.unknownFields = EMPTY_BYTES;
213
254
  }
214
255
  static encode(msg) {
215
256
  const out = [];
@@ -219,6 +260,15 @@ export class PublishReply {
219
260
  }
220
261
  static decode(bytes) {
221
262
  const msg = new PublishReply();
263
+ PublishReply._fill(msg, bytes);
264
+ return msg;
265
+ }
266
+ static decodeInto(msg, bytes) {
267
+ msg._reset();
268
+ PublishReply._fill(msg, bytes);
269
+ return msg;
270
+ }
271
+ static _fill(msg, bytes) {
222
272
  const reader = new Reader(bytes);
223
273
  let f;
224
274
  while ((f = reader.field()) !== null) {
@@ -230,12 +280,16 @@ export class PublishReply {
230
280
  }
231
281
  return msg;
232
282
  }
283
+ _reset() {
284
+ this.seq = 0n;
285
+ this.unknownFields = EMPTY_BYTES;
286
+ }
233
287
  }
234
288
 
235
289
  export class SubscribeRequest {
236
290
  constructor({ filter = [] } = {}) {
237
291
  this.filter = filter;
238
- this.unknownFields = new Uint8Array(0);
292
+ this.unknownFields = EMPTY_BYTES;
239
293
  }
240
294
  static encode(msg) {
241
295
  const out = [];
@@ -245,6 +299,15 @@ export class SubscribeRequest {
245
299
  }
246
300
  static decode(bytes) {
247
301
  const msg = new SubscribeRequest();
302
+ SubscribeRequest._fill(msg, bytes);
303
+ return msg;
304
+ }
305
+ static decodeInto(msg, bytes) {
306
+ msg._reset();
307
+ SubscribeRequest._fill(msg, bytes);
308
+ return msg;
309
+ }
310
+ static _fill(msg, bytes) {
248
311
  const reader = new Reader(bytes);
249
312
  let f;
250
313
  while ((f = reader.field()) !== null) {
@@ -256,6 +319,10 @@ export class SubscribeRequest {
256
319
  }
257
320
  return msg;
258
321
  }
322
+ _reset() {
323
+ this.filter = [];
324
+ this.unknownFields = EMPTY_BYTES;
325
+ }
259
326
  }
260
327
 
261
328
  export class Event {
@@ -265,7 +332,7 @@ export class Event {
265
332
  this.seq = seq;
266
333
  this.publisherId = publisherId;
267
334
  this.timestampUnixMs = timestampUnixMs;
268
- this.unknownFields = new Uint8Array(0);
335
+ this.unknownFields = EMPTY_BYTES;
269
336
  }
270
337
  static encode(msg) {
271
338
  const out = [];
@@ -279,6 +346,15 @@ export class Event {
279
346
  }
280
347
  static decode(bytes) {
281
348
  const msg = new Event();
349
+ Event._fill(msg, bytes);
350
+ return msg;
351
+ }
352
+ static decodeInto(msg, bytes) {
353
+ msg._reset();
354
+ Event._fill(msg, bytes);
355
+ return msg;
356
+ }
357
+ static _fill(msg, bytes) {
282
358
  const reader = new Reader(bytes);
283
359
  let f;
284
360
  while ((f = reader.field()) !== null) {
@@ -287,12 +363,20 @@ export class Event {
287
363
  case 1: msg.tags.push(TagValue.decode(value)); break;
288
364
  case 2: msg.payload = value; break;
289
365
  case 3: msg.seq = BigInt.asUintN(64, value); break;
290
- case 4: msg.publisherId = new TextDecoder().decode(value); break;
366
+ case 4: msg.publisherId = textDecoder.decode(value); break;
291
367
  case 5: msg.timestampUnixMs = BigInt.asIntN(64, value); break;
292
368
  default: msg.unknownFields = concatBytes(msg.unknownFields, raw); break;
293
369
  }
294
370
  }
295
371
  return msg;
296
372
  }
373
+ _reset() {
374
+ this.tags = [];
375
+ this.payload = new Uint8Array(0);
376
+ this.seq = 0n;
377
+ this.publisherId = "";
378
+ this.timestampUnixMs = 0n;
379
+ this.unknownFields = EMPTY_BYTES;
380
+ }
297
381
  }
298
382
 
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "eventbus-grpc",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "description": "Event bus over gRPC — generated grpcdc.events.v1 publish/subscribe clients over WebRTC DataChannels, via the grpc-dc runtime (JavaScript, browser + Node)",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "files": ["index.js", "events_pb.js", "events_grpc_dc.js"],
8
- "dependencies": {"grpc-dc": "^0.42.0"},
8
+ "dependencies": {"grpc-dc": "^0.44.0"},
9
9
  "license": "Apache-2.0",
10
10
  "repository": {"type": "git", "url": "git+https://github.com/browser-grpc/grpc-over-datachannels.git"}
11
11
  }