@libp2p/webrtc 6.0.14 → 6.0.15

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,9 +1,9 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebRTC data channels](https://webrtc.org/).
4
+ * A [libp2p transport](https://libp2p.io/docs/transports-overview/) based on [WebRTC data channels](https://webrtc.org/).
5
5
  *
6
- * [WebRTC](https://www.w3.org/TR/webrtc/) is a specification that allows real-time communication between nodes - it's commonly used in browser video conferencing applications but it also provides a reliable data transport mechanism called [data channels](https://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which libp2p uses to facilitate [protocol streams](https://docs.libp2p.io/concepts/multiplex/overview/) between peers.
6
+ * [WebRTC](https://www.w3.org/TR/webrtc/) is a specification that allows real-time communication between nodes - it's commonly used in browser video conferencing applications but it also provides a reliable data transport mechanism called [data channels](https://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which libp2p uses to facilitate [protocol streams](https://libp2p.io/docs/multiplexing-overview/) between peers.
7
7
  *
8
8
  * There are two transports exposed by this module, [webRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md) and [webRTCDirect](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md).
9
9
  *
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * A third party is usually necessary to carry out this handshake, forwarding messages between the two peers until they can make a direct connection between themselves.
15
15
  *
16
- * The WebRTC transport uses libp2p [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange.
16
+ * The WebRTC transport uses libp2p [Circuit Relay](https://libp2p.io/docs/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange.
17
17
  *
18
18
  * WebRTC Direct uses a technique known as [SDP munging](https://webrtchacks.com/not-a-guide-to-sdp-munging/) to skip the handshake step, instead encoding enough information in the connection request that the responder can derive what would have been in the handshake messages and so requires no third parties to establish a connection.
19
19
  *
package/dist/src/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebRTC data channels](https://webrtc.org/).
4
+ * A [libp2p transport](https://libp2p.io/docs/transports-overview/) based on [WebRTC data channels](https://webrtc.org/).
5
5
  *
6
- * [WebRTC](https://www.w3.org/TR/webrtc/) is a specification that allows real-time communication between nodes - it's commonly used in browser video conferencing applications but it also provides a reliable data transport mechanism called [data channels](https://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which libp2p uses to facilitate [protocol streams](https://docs.libp2p.io/concepts/multiplex/overview/) between peers.
6
+ * [WebRTC](https://www.w3.org/TR/webrtc/) is a specification that allows real-time communication between nodes - it's commonly used in browser video conferencing applications but it also provides a reliable data transport mechanism called [data channels](https://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which libp2p uses to facilitate [protocol streams](https://libp2p.io/docs/multiplexing-overview/) between peers.
7
7
  *
8
8
  * There are two transports exposed by this module, [webRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md) and [webRTCDirect](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md).
9
9
  *
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * A third party is usually necessary to carry out this handshake, forwarding messages between the two peers until they can make a direct connection between themselves.
15
15
  *
16
- * The WebRTC transport uses libp2p [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange.
16
+ * The WebRTC transport uses libp2p [Circuit Relay](https://libp2p.io/docs/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange.
17
17
  *
18
18
  * WebRTC Direct uses a technique known as [SDP munging](https://webrtchacks.com/not-a-guide-to-sdp-munging/) to skip the handshake step, instead encoding enough information in the connection request that the responder can derive what would have been in the handshake messages and so requires no third parties to establish a connection.
19
19
  *
@@ -14,7 +14,16 @@ export declare namespace Message {
14
14
  const codec: () => Codec<Type>;
15
15
  }
16
16
  const codec: () => Codec<Message>;
17
- const encode: (obj: Partial<Message>) => Uint8Array;
18
- const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>) => Message;
17
+ interface MessageTypeFieldEvent {
18
+ field: '$.type';
19
+ value: Message.Type;
20
+ }
21
+ interface MessageDataFieldEvent {
22
+ field: '$.data';
23
+ value: string;
24
+ }
25
+ function encode(obj: Partial<Message>): Uint8Array;
26
+ function decode(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message;
27
+ function stream(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Generator<MessageTypeFieldEvent | MessageDataFieldEvent>;
19
28
  }
20
29
  //# sourceMappingURL=message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../src/private-to-private/pb/message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,yBAAiB,OAAO,CAAC;IACvB,KAAY,IAAI;QACd,SAAS,cAAc;QACvB,UAAU,eAAe;QACzB,aAAa,kBAAkB;KAChC;IAQD,UAAiB,IAAI,CAAC;QACb,MAAM,KAAK,QAAO,KAAK,CAAC,IAAI,CAElC,CAAA;KACF;IAIM,MAAM,KAAK,QAAO,KAAK,CAAC,OAAO,CAiDrC,CAAA;IAEM,MAAM,MAAM,GAAI,KAAK,OAAO,CAAC,OAAO,CAAC,KAAG,UAE9C,CAAA;IAEM,MAAM,MAAM,GAAI,KAAK,UAAU,GAAG,cAAc,EAAE,OAAO,aAAa,CAAC,OAAO,CAAC,KAAG,OAExF,CAAA;CACF"}
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../src/private-to-private/pb/message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,yBAAiB,OAAO,CAAC;IACvB,KAAY,IAAI;QACd,SAAS,cAAc;QACvB,UAAU,eAAe;QACzB,aAAa,kBAAkB;KAChC;IAQD,UAAiB,IAAI,CAAC;QACb,MAAM,KAAK,QAAO,KAAK,CAAC,IAAI,CAElC,CAAA;KACF;IAIM,MAAM,KAAK,QAAO,KAAK,CAAC,OAAO,CA4ErC,CAAA;IAED,UAAiB,qBAAqB;QACpC,KAAK,EAAE,QAAQ,CAAA;QACf,KAAK,EAAE,OAAO,CAAC,IAAI,CAAA;KACpB;IAED,UAAiB,qBAAqB;QACpC,KAAK,EAAE,QAAQ,CAAA;QACf,KAAK,EAAE,MAAM,CAAA;KACd;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,UAAU,CAEzD;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,OAAO,CAEhG;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,qBAAqB,GAAG,qBAAqB,CAAC,CAEjJ;CACF"}
@@ -1,4 +1,4 @@
1
- import { decodeMessage, encodeMessage, enumeration, message } from 'protons-runtime';
1
+ import { decodeMessage, encodeMessage, enumeration, message, streamMessage } from 'protons-runtime';
2
2
  export var Message;
3
3
  (function (Message) {
4
4
  let Type;
@@ -57,15 +57,46 @@ export var Message;
57
57
  }
58
58
  }
59
59
  return obj;
60
+ }, function* (reader, length, prefix, opts = {}) {
61
+ const end = length == null ? reader.len : reader.pos + length;
62
+ while (reader.pos < end) {
63
+ const tag = reader.uint32();
64
+ switch (tag >>> 3) {
65
+ case 1: {
66
+ yield {
67
+ field: `${prefix}.type`,
68
+ value: Message.Type.codec().decode(reader)
69
+ };
70
+ break;
71
+ }
72
+ case 2: {
73
+ yield {
74
+ field: `${prefix}.data`,
75
+ value: reader.string()
76
+ };
77
+ break;
78
+ }
79
+ default: {
80
+ reader.skipType(tag & 7);
81
+ break;
82
+ }
83
+ }
84
+ }
60
85
  });
61
86
  }
62
87
  return _codec;
63
88
  };
64
- Message.encode = (obj) => {
89
+ function encode(obj) {
65
90
  return encodeMessage(obj, Message.codec());
66
- };
67
- Message.decode = (buf, opts) => {
91
+ }
92
+ Message.encode = encode;
93
+ function decode(buf, opts) {
68
94
  return decodeMessage(buf, Message.codec(), opts);
69
- };
95
+ }
96
+ Message.decode = decode;
97
+ function stream(buf, opts) {
98
+ return streamMessage(buf, Message.codec(), opts);
99
+ }
100
+ Message.stream = stream;
70
101
  })(Message || (Message = {}));
71
102
  //# sourceMappingURL=message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../src/private-to-private/pb/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AASpF,MAAM,KAAW,OAAO,CA+EvB;AA/ED,WAAiB,OAAO;IACtB,IAAY,IAIX;IAJD,WAAY,IAAI;QACd,+BAAuB,CAAA;QACvB,iCAAyB,CAAA;QACzB,uCAA+B,CAAA;IACjC,CAAC,EAJW,IAAI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CAAA;IAClD,CAAC;IAFe,cAAM,SAErB,CAAA;AACH,CAAC,EAxHgB,OAAO,KAAP,OAAO,QAwHvB"}
@@ -15,7 +15,16 @@ export declare namespace Message {
15
15
  const codec: () => Codec<Flag>;
16
16
  }
17
17
  const codec: () => Codec<Message>;
18
- const encode: (obj: Partial<Message>) => Uint8Array;
19
- const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>) => Message;
18
+ interface MessageFlagFieldEvent {
19
+ field: '$.flag';
20
+ value: Message.Flag;
21
+ }
22
+ interface MessageMessageFieldEvent {
23
+ field: '$.message';
24
+ value: Uint8Array;
25
+ }
26
+ function encode(obj: Partial<Message>): Uint8Array;
27
+ function decode(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message;
28
+ function stream(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Generator<MessageFlagFieldEvent | MessageMessageFieldEvent>;
20
29
  }
21
30
  //# sourceMappingURL=message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../src/private-to-public/pb/message.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAA;IACnB,OAAO,CAAC,EAAE,UAAU,CAAA;CACrB;AAED,yBAAiB,OAAO,CAAC;IACvB,KAAY,IAAI;QACd,GAAG,QAAQ;QACX,YAAY,iBAAiB;QAC7B,KAAK,UAAU;QACf,OAAO,YAAY;KACpB;IASD,UAAiB,IAAI,CAAC;QACb,MAAM,KAAK,QAAO,KAAK,CAAC,IAAI,CAElC,CAAA;KACF;IAIM,MAAM,KAAK,QAAO,KAAK,CAAC,OAAO,CAiDrC,CAAA;IAEM,MAAM,MAAM,G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,GAAG,SAAS,CAAC,qBAAqB,GAAG,wBAAwB,CAAC,CAEpJ;CACF"}
@@ -1,4 +1,4 @@
1
- import { decodeMessage, encodeMessage, enumeration, message } from 'protons-runtime';
1
+ import { decodeMessage, encodeMessage, enumeration, message, streamMessage } from 'protons-runtime';
2
2
  export var Message;
3
3
  (function (Message) {
4
4
  let Flag;
@@ -59,15 +59,46 @@ export var Message;
59
59
  }
60
60
  }
61
61
  return obj;
62
+ }, function* (reader, length, prefix, opts = {}) {
63
+ const end = length == null ? reader.len : reader.pos + length;
64
+ while (reader.pos < end) {
65
+ const tag = reader.uint32();
66
+ switch (tag >>> 3) {
67
+ case 1: {
68
+ yield {
69
+ field: `${prefix}.flag`,
70
+ value: Message.Flag.codec().decode(reader)
71
+ };
72
+ break;
73
+ }
74
+ case 2: {
75
+ yield {
76
+ field: `${prefix}.message`,
77
+ value: reader.bytes()
78
+ };
79
+ break;
80
+ }
81
+ default: {
82
+ reader.skipType(tag & 7);
83
+ break;
84
+ }
85
+ }
86
+ }
62
87
  });
63
88
  }
64
89
  return _codec;
65
90
  };
66
- Message.encode = (obj) => {
91
+ function encode(obj) {
67
92
  return encodeMessage(obj, Message.codec());
68
- };
69
- Message.decode = (buf, opts) => {
93
+ }
94
+ Message.encode = encode;
95
+ function decode(buf, opts) {
70
96
  return decodeMessage(buf, Message.codec(), opts);
71
- };
97
+ }
98
+ Message.decode = decode;
99
+ function stream(buf, opts) {
100
+ return streamMessage(buf, Message.codec(), opts);
101
+ }
102
+ Message.stream = stream;
72
103
  })(Message || (Message = {}));
73
104
  //# sourceMappingURL=message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../src/private-to-public/pb/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AASpF,MAAM,KAAW,OAAO,CAiFvB;AAjFD,WAAiB,OAAO;IACtB,IAA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CAAC,CAAA;IAClD,CAAC;IAFe,cAAM,SAErB,CAAA;IAED,SAAgB,MAAM,CAAE,GAAgC,EAAE,IAA6B;QACrF,OAAO,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;IAClD,CAAC;IAFe,cAAM,SAErB,CAAA;AACH,CAAC,EA1HgB,OAAO,KAAP,OAAO,QA0HvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/webrtc",
3
- "version": "6.0.14",
3
+ "version": "6.0.15",
4
4
  "description": "A libp2p transport using WebRTC connections",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc#readme",
@@ -30,7 +30,7 @@
30
30
  }
31
31
  },
32
32
  "scripts": {
33
- "generate": "protons src/private-to-private/pb/message.proto",
33
+ "generate": "protons src/private-to-private/pb/message.proto src/private-to-public/pb/message.proto",
34
34
  "build": "aegir build",
35
35
  "test": "aegir test -t node -t browser",
36
36
  "test:node": "aegir test -t node --cov -- --exit",
@@ -45,13 +45,13 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@chainsafe/is-ip": "^2.1.0",
48
- "@libp2p/crypto": "^5.1.13",
49
- "@libp2p/interface": "^3.1.0",
50
- "@libp2p/interface-internal": "^3.0.13",
51
- "@libp2p/keychain": "^6.0.10",
48
+ "@libp2p/crypto": "^5.1.14",
49
+ "@libp2p/interface": "^3.1.1",
50
+ "@libp2p/interface-internal": "^3.0.14",
51
+ "@libp2p/keychain": "^6.0.11",
52
52
  "@chainsafe/libp2p-noise": "^17.0.0",
53
- "@libp2p/peer-id": "^6.0.4",
54
- "@libp2p/utils": "^7.0.13",
53
+ "@libp2p/peer-id": "^6.0.5",
54
+ "@libp2p/utils": "^7.0.14",
55
55
  "@multiformats/multiaddr": "^13.0.1",
56
56
  "@multiformats/multiaddr-matcher": "^3.0.1",
57
57
  "@peculiar/webcrypto": "^1.5.0",
@@ -71,7 +71,7 @@
71
71
  "p-timeout": "^7.0.0",
72
72
  "p-wait-for": "^6.0.0",
73
73
  "progress-events": "^1.0.1",
74
- "protons-runtime": "^5.6.0",
74
+ "protons-runtime": "^6.0.1",
75
75
  "race-signal": "^2.0.0",
76
76
  "react-native-webrtc": "^124.0.6",
77
77
  "uint8-varint": "^2.0.4",
@@ -79,14 +79,14 @@
79
79
  "uint8arrays": "^5.1.0"
80
80
  },
81
81
  "devDependencies": {
82
- "@libp2p/logger": "^6.2.2",
82
+ "@libp2p/logger": "^6.2.3",
83
83
  "@types/sinon": "^20.0.0",
84
84
  "aegir": "^47.0.22",
85
85
  "any-signal": "^4.1.1",
86
86
  "datastore-core": "^11.0.1",
87
87
  "delay": "^7.0.0",
88
88
  "p-retry": "^7.0.0",
89
- "protons": "^7.7.0",
89
+ "protons": "^8.1.1",
90
90
  "sinon": "^21.0.0",
91
91
  "sinon-ts": "^2.0.0",
92
92
  "wherearewe": "^2.0.1"
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebRTC data channels](https://webrtc.org/).
4
+ * A [libp2p transport](https://libp2p.io/docs/transports-overview/) based on [WebRTC data channels](https://webrtc.org/).
5
5
  *
6
- * [WebRTC](https://www.w3.org/TR/webrtc/) is a specification that allows real-time communication between nodes - it's commonly used in browser video conferencing applications but it also provides a reliable data transport mechanism called [data channels](https://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which libp2p uses to facilitate [protocol streams](https://docs.libp2p.io/concepts/multiplex/overview/) between peers.
6
+ * [WebRTC](https://www.w3.org/TR/webrtc/) is a specification that allows real-time communication between nodes - it's commonly used in browser video conferencing applications but it also provides a reliable data transport mechanism called [data channels](https://www.w3.org/TR/webrtc/#peer-to-peer-data-api) which libp2p uses to facilitate [protocol streams](https://libp2p.io/docs/multiplexing-overview/) between peers.
7
7
  *
8
8
  * There are two transports exposed by this module, [webRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md) and [webRTCDirect](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md).
9
9
  *
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * A third party is usually necessary to carry out this handshake, forwarding messages between the two peers until they can make a direct connection between themselves.
15
15
  *
16
- * The WebRTC transport uses libp2p [Circuit Relay](https://docs.libp2p.io/concepts/nat/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange.
16
+ * The WebRTC transport uses libp2p [Circuit Relay](https://libp2p.io/docs/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange.
17
17
  *
18
18
  * WebRTC Direct uses a technique known as [SDP munging](https://webrtchacks.com/not-a-guide-to-sdp-munging/) to skip the handshake step, instead encoding enough information in the connection request that the responder can derive what would have been in the handshake messages and so requires no third parties to establish a connection.
19
19
  *
@@ -1,4 +1,4 @@
1
- import { decodeMessage, encodeMessage, enumeration, message } from 'protons-runtime'
1
+ import { decodeMessage, encodeMessage, enumeration, message, streamMessage } from 'protons-runtime'
2
2
  import type { Codec, DecodeOptions } from 'protons-runtime'
3
3
  import type { Uint8ArrayList } from 'uint8arraylist'
4
4
 
@@ -73,17 +73,58 @@ export namespace Message {
73
73
  }
74
74
 
75
75
  return obj
76
+ }, function * (reader, length, prefix, opts = {}) {
77
+ const end = length == null ? reader.len : reader.pos + length
78
+
79
+ while (reader.pos < end) {
80
+ const tag = reader.uint32()
81
+
82
+ switch (tag >>> 3) {
83
+ case 1: {
84
+ yield {
85
+ field: `${prefix}.type`,
86
+ value: Message.Type.codec().decode(reader)
87
+ }
88
+ break
89
+ }
90
+ case 2: {
91
+ yield {
92
+ field: `${prefix}.data`,
93
+ value: reader.string()
94
+ }
95
+ break
96
+ }
97
+ default: {
98
+ reader.skipType(tag & 7)
99
+ break
100
+ }
101
+ }
102
+ }
76
103
  })
77
104
  }
78
105
 
79
106
  return _codec
80
107
  }
81
108
 
82
- export const encode = (obj: Partial<Message>): Uint8Array => {
109
+ export interface MessageTypeFieldEvent {
110
+ field: '$.type'
111
+ value: Message.Type
112
+ }
113
+
114
+ export interface MessageDataFieldEvent {
115
+ field: '$.data'
116
+ value: string
117
+ }
118
+
119
+ export function encode (obj: Partial<Message>): Uint8Array {
83
120
  return encodeMessage(obj, Message.codec())
84
121
  }
85
122
 
86
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message => {
123
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message {
87
124
  return decodeMessage(buf, Message.codec(), opts)
88
125
  }
126
+
127
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Generator<MessageTypeFieldEvent | MessageDataFieldEvent> {
128
+ return streamMessage(buf, Message.codec(), opts)
129
+ }
89
130
  }
@@ -1,4 +1,4 @@
1
- import { decodeMessage, encodeMessage, enumeration, message } from 'protons-runtime'
1
+ import { decodeMessage, encodeMessage, enumeration, message, streamMessage } from 'protons-runtime'
2
2
  import type { Codec, DecodeOptions } from 'protons-runtime'
3
3
  import type { Uint8ArrayList } from 'uint8arraylist'
4
4
 
@@ -75,17 +75,58 @@ export namespace Message {
75
75
  }
76
76
 
77
77
  return obj
78
+ }, function * (reader, length, prefix, opts = {}) {
79
+ const end = length == null ? reader.len : reader.pos + length
80
+
81
+ while (reader.pos < end) {
82
+ const tag = reader.uint32()
83
+
84
+ switch (tag >>> 3) {
85
+ case 1: {
86
+ yield {
87
+ field: `${prefix}.flag`,
88
+ value: Message.Flag.codec().decode(reader)
89
+ }
90
+ break
91
+ }
92
+ case 2: {
93
+ yield {
94
+ field: `${prefix}.message`,
95
+ value: reader.bytes()
96
+ }
97
+ break
98
+ }
99
+ default: {
100
+ reader.skipType(tag & 7)
101
+ break
102
+ }
103
+ }
104
+ }
78
105
  })
79
106
  }
80
107
 
81
108
  return _codec
82
109
  }
83
110
 
84
- export const encode = (obj: Partial<Message>): Uint8Array => {
111
+ export interface MessageFlagFieldEvent {
112
+ field: '$.flag'
113
+ value: Message.Flag
114
+ }
115
+
116
+ export interface MessageMessageFieldEvent {
117
+ field: '$.message'
118
+ value: Uint8Array
119
+ }
120
+
121
+ export function encode (obj: Partial<Message>): Uint8Array {
85
122
  return encodeMessage(obj, Message.codec())
86
123
  }
87
124
 
88
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message => {
125
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message {
89
126
  return decodeMessage(buf, Message.codec(), opts)
90
127
  }
128
+
129
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Generator<MessageFlagFieldEvent | MessageMessageFieldEvent> {
130
+ return streamMessage(buf, Message.codec(), opts)
131
+ }
91
132
  }