@libp2p/peer-record 1.0.6 → 1.0.9

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,365 +0,0 @@
1
- /*eslint-disable*/
2
- import $protobuf from "protobufjs/minimal.js";
3
-
4
- // Common aliases
5
- const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
6
-
7
- // Exported root namespace
8
- const $root = $protobuf.roots["libp2p-peer-record"] || ($protobuf.roots["libp2p-peer-record"] = {});
9
-
10
- export const PeerRecord = $root.PeerRecord = (() => {
11
-
12
- /**
13
- * Properties of a PeerRecord.
14
- * @exports IPeerRecord
15
- * @interface IPeerRecord
16
- * @property {Uint8Array|null} [peerId] PeerRecord peerId
17
- * @property {number|null} [seq] PeerRecord seq
18
- * @property {Array.<PeerRecord.IAddressInfo>|null} [addresses] PeerRecord addresses
19
- */
20
-
21
- /**
22
- * Constructs a new PeerRecord.
23
- * @exports PeerRecord
24
- * @classdesc Represents a PeerRecord.
25
- * @implements IPeerRecord
26
- * @constructor
27
- * @param {IPeerRecord=} [p] Properties to set
28
- */
29
- function PeerRecord(p) {
30
- this.addresses = [];
31
- if (p)
32
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
33
- if (p[ks[i]] != null)
34
- this[ks[i]] = p[ks[i]];
35
- }
36
-
37
- /**
38
- * PeerRecord peerId.
39
- * @member {Uint8Array} peerId
40
- * @memberof PeerRecord
41
- * @instance
42
- */
43
- PeerRecord.prototype.peerId = $util.newBuffer([]);
44
-
45
- /**
46
- * PeerRecord seq.
47
- * @member {number} seq
48
- * @memberof PeerRecord
49
- * @instance
50
- */
51
- PeerRecord.prototype.seq = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
52
-
53
- /**
54
- * PeerRecord addresses.
55
- * @member {Array.<PeerRecord.IAddressInfo>} addresses
56
- * @memberof PeerRecord
57
- * @instance
58
- */
59
- PeerRecord.prototype.addresses = $util.emptyArray;
60
-
61
- /**
62
- * Encodes the specified PeerRecord message. Does not implicitly {@link PeerRecord.verify|verify} messages.
63
- * @function encode
64
- * @memberof PeerRecord
65
- * @static
66
- * @param {IPeerRecord} m PeerRecord message or plain object to encode
67
- * @param {$protobuf.Writer} [w] Writer to encode to
68
- * @returns {$protobuf.Writer} Writer
69
- */
70
- PeerRecord.encode = function encode(m, w) {
71
- if (!w)
72
- w = $Writer.create();
73
- if (m.peerId != null && Object.hasOwnProperty.call(m, "peerId"))
74
- w.uint32(10).bytes(m.peerId);
75
- if (m.seq != null && Object.hasOwnProperty.call(m, "seq"))
76
- w.uint32(16).uint64(m.seq);
77
- if (m.addresses != null && m.addresses.length) {
78
- for (var i = 0; i < m.addresses.length; ++i)
79
- $root.PeerRecord.AddressInfo.encode(m.addresses[i], w.uint32(26).fork()).ldelim();
80
- }
81
- return w;
82
- };
83
-
84
- /**
85
- * Decodes a PeerRecord message from the specified reader or buffer.
86
- * @function decode
87
- * @memberof PeerRecord
88
- * @static
89
- * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
90
- * @param {number} [l] Message length if known beforehand
91
- * @returns {PeerRecord} PeerRecord
92
- * @throws {Error} If the payload is not a reader or valid buffer
93
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
94
- */
95
- PeerRecord.decode = function decode(r, l) {
96
- if (!(r instanceof $Reader))
97
- r = $Reader.create(r);
98
- var c = l === undefined ? r.len : r.pos + l, m = new $root.PeerRecord();
99
- while (r.pos < c) {
100
- var t = r.uint32();
101
- switch (t >>> 3) {
102
- case 1:
103
- m.peerId = r.bytes();
104
- break;
105
- case 2:
106
- m.seq = r.uint64();
107
- break;
108
- case 3:
109
- if (!(m.addresses && m.addresses.length))
110
- m.addresses = [];
111
- m.addresses.push($root.PeerRecord.AddressInfo.decode(r, r.uint32()));
112
- break;
113
- default:
114
- r.skipType(t & 7);
115
- break;
116
- }
117
- }
118
- return m;
119
- };
120
-
121
- /**
122
- * Creates a PeerRecord message from a plain object. Also converts values to their respective internal types.
123
- * @function fromObject
124
- * @memberof PeerRecord
125
- * @static
126
- * @param {Object.<string,*>} d Plain object
127
- * @returns {PeerRecord} PeerRecord
128
- */
129
- PeerRecord.fromObject = function fromObject(d) {
130
- if (d instanceof $root.PeerRecord)
131
- return d;
132
- var m = new $root.PeerRecord();
133
- if (d.peerId != null) {
134
- if (typeof d.peerId === "string")
135
- $util.base64.decode(d.peerId, m.peerId = $util.newBuffer($util.base64.length(d.peerId)), 0);
136
- else if (d.peerId.length)
137
- m.peerId = d.peerId;
138
- }
139
- if (d.seq != null) {
140
- if ($util.Long)
141
- (m.seq = $util.Long.fromValue(d.seq)).unsigned = true;
142
- else if (typeof d.seq === "string")
143
- m.seq = parseInt(d.seq, 10);
144
- else if (typeof d.seq === "number")
145
- m.seq = d.seq;
146
- else if (typeof d.seq === "object")
147
- m.seq = new $util.LongBits(d.seq.low >>> 0, d.seq.high >>> 0).toNumber(true);
148
- }
149
- if (d.addresses) {
150
- if (!Array.isArray(d.addresses))
151
- throw TypeError(".PeerRecord.addresses: array expected");
152
- m.addresses = [];
153
- for (var i = 0; i < d.addresses.length; ++i) {
154
- if (typeof d.addresses[i] !== "object")
155
- throw TypeError(".PeerRecord.addresses: object expected");
156
- m.addresses[i] = $root.PeerRecord.AddressInfo.fromObject(d.addresses[i]);
157
- }
158
- }
159
- return m;
160
- };
161
-
162
- /**
163
- * Creates a plain object from a PeerRecord message. Also converts values to other types if specified.
164
- * @function toObject
165
- * @memberof PeerRecord
166
- * @static
167
- * @param {PeerRecord} m PeerRecord
168
- * @param {$protobuf.IConversionOptions} [o] Conversion options
169
- * @returns {Object.<string,*>} Plain object
170
- */
171
- PeerRecord.toObject = function toObject(m, o) {
172
- if (!o)
173
- o = {};
174
- var d = {};
175
- if (o.arrays || o.defaults) {
176
- d.addresses = [];
177
- }
178
- if (o.defaults) {
179
- if (o.bytes === String)
180
- d.peerId = "";
181
- else {
182
- d.peerId = [];
183
- if (o.bytes !== Array)
184
- d.peerId = $util.newBuffer(d.peerId);
185
- }
186
- if ($util.Long) {
187
- var n = new $util.Long(0, 0, true);
188
- d.seq = o.longs === String ? n.toString() : o.longs === Number ? n.toNumber() : n;
189
- } else
190
- d.seq = o.longs === String ? "0" : 0;
191
- }
192
- if (m.peerId != null && m.hasOwnProperty("peerId")) {
193
- d.peerId = o.bytes === String ? $util.base64.encode(m.peerId, 0, m.peerId.length) : o.bytes === Array ? Array.prototype.slice.call(m.peerId) : m.peerId;
194
- }
195
- if (m.seq != null && m.hasOwnProperty("seq")) {
196
- if (typeof m.seq === "number")
197
- d.seq = o.longs === String ? String(m.seq) : m.seq;
198
- else
199
- d.seq = o.longs === String ? $util.Long.prototype.toString.call(m.seq) : o.longs === Number ? new $util.LongBits(m.seq.low >>> 0, m.seq.high >>> 0).toNumber(true) : m.seq;
200
- }
201
- if (m.addresses && m.addresses.length) {
202
- d.addresses = [];
203
- for (var j = 0; j < m.addresses.length; ++j) {
204
- d.addresses[j] = $root.PeerRecord.AddressInfo.toObject(m.addresses[j], o);
205
- }
206
- }
207
- return d;
208
- };
209
-
210
- /**
211
- * Converts this PeerRecord to JSON.
212
- * @function toJSON
213
- * @memberof PeerRecord
214
- * @instance
215
- * @returns {Object.<string,*>} JSON object
216
- */
217
- PeerRecord.prototype.toJSON = function toJSON() {
218
- return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
219
- };
220
-
221
- PeerRecord.AddressInfo = (function() {
222
-
223
- /**
224
- * Properties of an AddressInfo.
225
- * @memberof PeerRecord
226
- * @interface IAddressInfo
227
- * @property {Uint8Array|null} [multiaddr] AddressInfo multiaddr
228
- */
229
-
230
- /**
231
- * Constructs a new AddressInfo.
232
- * @memberof PeerRecord
233
- * @classdesc Represents an AddressInfo.
234
- * @implements IAddressInfo
235
- * @constructor
236
- * @param {PeerRecord.IAddressInfo=} [p] Properties to set
237
- */
238
- function AddressInfo(p) {
239
- if (p)
240
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
241
- if (p[ks[i]] != null)
242
- this[ks[i]] = p[ks[i]];
243
- }
244
-
245
- /**
246
- * AddressInfo multiaddr.
247
- * @member {Uint8Array} multiaddr
248
- * @memberof PeerRecord.AddressInfo
249
- * @instance
250
- */
251
- AddressInfo.prototype.multiaddr = $util.newBuffer([]);
252
-
253
- /**
254
- * Encodes the specified AddressInfo message. Does not implicitly {@link PeerRecord.AddressInfo.verify|verify} messages.
255
- * @function encode
256
- * @memberof PeerRecord.AddressInfo
257
- * @static
258
- * @param {PeerRecord.IAddressInfo} m AddressInfo message or plain object to encode
259
- * @param {$protobuf.Writer} [w] Writer to encode to
260
- * @returns {$protobuf.Writer} Writer
261
- */
262
- AddressInfo.encode = function encode(m, w) {
263
- if (!w)
264
- w = $Writer.create();
265
- if (m.multiaddr != null && Object.hasOwnProperty.call(m, "multiaddr"))
266
- w.uint32(10).bytes(m.multiaddr);
267
- return w;
268
- };
269
-
270
- /**
271
- * Decodes an AddressInfo message from the specified reader or buffer.
272
- * @function decode
273
- * @memberof PeerRecord.AddressInfo
274
- * @static
275
- * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
276
- * @param {number} [l] Message length if known beforehand
277
- * @returns {PeerRecord.AddressInfo} AddressInfo
278
- * @throws {Error} If the payload is not a reader or valid buffer
279
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
280
- */
281
- AddressInfo.decode = function decode(r, l) {
282
- if (!(r instanceof $Reader))
283
- r = $Reader.create(r);
284
- var c = l === undefined ? r.len : r.pos + l, m = new $root.PeerRecord.AddressInfo();
285
- while (r.pos < c) {
286
- var t = r.uint32();
287
- switch (t >>> 3) {
288
- case 1:
289
- m.multiaddr = r.bytes();
290
- break;
291
- default:
292
- r.skipType(t & 7);
293
- break;
294
- }
295
- }
296
- return m;
297
- };
298
-
299
- /**
300
- * Creates an AddressInfo message from a plain object. Also converts values to their respective internal types.
301
- * @function fromObject
302
- * @memberof PeerRecord.AddressInfo
303
- * @static
304
- * @param {Object.<string,*>} d Plain object
305
- * @returns {PeerRecord.AddressInfo} AddressInfo
306
- */
307
- AddressInfo.fromObject = function fromObject(d) {
308
- if (d instanceof $root.PeerRecord.AddressInfo)
309
- return d;
310
- var m = new $root.PeerRecord.AddressInfo();
311
- if (d.multiaddr != null) {
312
- if (typeof d.multiaddr === "string")
313
- $util.base64.decode(d.multiaddr, m.multiaddr = $util.newBuffer($util.base64.length(d.multiaddr)), 0);
314
- else if (d.multiaddr.length)
315
- m.multiaddr = d.multiaddr;
316
- }
317
- return m;
318
- };
319
-
320
- /**
321
- * Creates a plain object from an AddressInfo message. Also converts values to other types if specified.
322
- * @function toObject
323
- * @memberof PeerRecord.AddressInfo
324
- * @static
325
- * @param {PeerRecord.AddressInfo} m AddressInfo
326
- * @param {$protobuf.IConversionOptions} [o] Conversion options
327
- * @returns {Object.<string,*>} Plain object
328
- */
329
- AddressInfo.toObject = function toObject(m, o) {
330
- if (!o)
331
- o = {};
332
- var d = {};
333
- if (o.defaults) {
334
- if (o.bytes === String)
335
- d.multiaddr = "";
336
- else {
337
- d.multiaddr = [];
338
- if (o.bytes !== Array)
339
- d.multiaddr = $util.newBuffer(d.multiaddr);
340
- }
341
- }
342
- if (m.multiaddr != null && m.hasOwnProperty("multiaddr")) {
343
- d.multiaddr = o.bytes === String ? $util.base64.encode(m.multiaddr, 0, m.multiaddr.length) : o.bytes === Array ? Array.prototype.slice.call(m.multiaddr) : m.multiaddr;
344
- }
345
- return d;
346
- };
347
-
348
- /**
349
- * Converts this AddressInfo to JSON.
350
- * @function toJSON
351
- * @memberof PeerRecord.AddressInfo
352
- * @instance
353
- * @returns {Object.<string,*>} JSON object
354
- */
355
- AddressInfo.prototype.toJSON = function toJSON() {
356
- return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
357
- };
358
-
359
- return AddressInfo;
360
- })();
361
-
362
- return PeerRecord;
363
- })();
364
-
365
- export { $root as default };