From daa72fe17c67a6bfbb8620e35f441c85372db879 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 1 Aug 2022 13:26:46 +0700 Subject: [PATCH 1/4] feat: migrate to protobufjs --- package.json | 4 +- src/index.ts | 121 +- src/message-cache.ts | 10 +- src/message/index.ts | 1 - src/message/rpc.d.ts | 666 +++++++++++ src/message/rpc.js | 1878 ++++++++++++++++++++++++++++++++ src/message/rpc.ts | 215 ---- src/metrics.ts | 30 +- src/types.ts | 2 +- src/utils/buildRawMessage.ts | 12 +- src/utils/create-gossip-rpc.ts | 4 +- test/e2e/go-gossipsub.spec.ts | 4 +- test/message-cache.spec.ts | 4 +- test/utils/index.ts | 2 +- test/utils/msgId.ts | 6 +- 15 files changed, 2646 insertions(+), 313 deletions(-) delete mode 100644 src/message/index.ts create mode 100644 src/message/rpc.d.ts create mode 100644 src/message/rpc.js delete mode 100644 src/message/rpc.ts diff --git a/package.json b/package.json index 4cbfe6c7..88bf86b4 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "lint": "eslint --ext .ts src test", "release": "aegir release --no-types", "build": "aegir build", - "generate": "protons ./src/message/rpc.proto", "prepare": "npm run build", "pretest": "npm run build", "pretest:e2e": "npm run build", @@ -85,7 +84,7 @@ "it-pipe": "^2.0.3", "it-pushable": "^3.0.0", "multiformats": "^9.6.4", - "protons-runtime": "^1.0.4", + "protobufjs": "^6.11.2", "uint8arrays": "^3.0.0" }, "devDependencies": { @@ -122,7 +121,6 @@ "p-wait-for": "^3.2.0", "prettier": "^2.0.5", "promisify-es6": "^1.0.3", - "protons": "^3.0.4", "sinon": "^11.1.1", "time-cache": "^0.3.0", "ts-node": "^10.7.0", diff --git a/src/index.ts b/src/index.ts index 273541f1..3662d3f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { MessageCache } from './message-cache.js' -import { RPC } from './message/rpc.js' +import { RPC, IRPC } from './message/rpc.js' import * as constants from './constants.js' import { createGossipRpc, shuffle, messageIdToString } from './utils/index.js' import { @@ -263,13 +263,13 @@ export class GossipSub extends EventEmitter implements Initiali * Map of pending messages to gossip * peer id => control messages */ - public readonly gossip = new Map() + public readonly gossip = new Map() /** * Map of control messages * peer id => control message */ - public readonly control = new Map() + public readonly control = new Map() /** * Number of IHAVEs received from peer in the last heartbeat @@ -910,7 +910,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Handles an rpc request from a peer */ - public async handleReceivedRpc(from: PeerId, rpc: RPC): Promise { + public async handleReceivedRpc(from: PeerId, rpc: IRPC): Promise { // Check if peer is graylisted in which case we ignore the event if (!this.acceptFrom(from.toString())) { this.log('received message from unacceptable peer %p', from) @@ -921,7 +921,7 @@ export class GossipSub extends EventEmitter implements Initiali this.log('rpc from %p', from) // Handle received subscriptions - if (rpc.subscriptions.length > 0) { + if (rpc.subscriptions && rpc.subscriptions.length > 0) { // update peer subscriptions rpc.subscriptions.forEach((subOpt) => { this.handleReceivedSubscription(from, subOpt) @@ -946,13 +946,15 @@ export class GossipSub extends EventEmitter implements Initiali // Handle messages // TODO: (up to limit) - for (const message of rpc.messages) { - const handleReceivedMessagePromise = this.handleReceivedMessage(from, message) - // Should never throw, but handle just in case - .catch((err) => this.log(err)) - - if (this.opts.awaitRpcMessageHandler) { - await handleReceivedMessagePromise + if (rpc.messages) { + for (const message of rpc.messages) { + const handleReceivedMessagePromise = this.handleReceivedMessage(from, message) + // Should never throw, but handle just in case + .catch((err) => this.log(err)) + + if (this.opts.awaitRpcMessageHandler) { + await handleReceivedMessagePromise + } } } @@ -965,7 +967,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Handles a subscription change from a peer */ - private handleReceivedSubscription(from: PeerId, subOpt: RPC.SubOpts): void { + private handleReceivedSubscription(from: PeerId, subOpt: RPC.ISubOpts): void { if (subOpt.topic == null) { return } @@ -993,7 +995,7 @@ export class GossipSub extends EventEmitter implements Initiali * Handles a newly received message from an RPC. * May forward to all peers in the mesh. */ - private async handleReceivedMessage(from: PeerId, rpcMsg: RPC.Message): Promise { + private async handleReceivedMessage(from: PeerId, rpcMsg: RPC.IMessage): Promise { this.metrics?.onMsgRecvPreValidation(rpcMsg.topic) const validationResult = await this.validateReceivedMessage(from, rpcMsg) @@ -1068,7 +1070,7 @@ export class GossipSub extends EventEmitter implements Initiali */ private async validateReceivedMessage( propagationSource: PeerId, - rpcMsg: RPC.Message + rpcMsg: RPC.IMessage ): Promise { // Fast message ID stuff const fastMsgIdStr = this.fastMsgIdFn?.(rpcMsg) @@ -1167,15 +1169,15 @@ export class GossipSub extends EventEmitter implements Initiali /** * Handles an rpc control message from a peer */ - private async handleControlMessage(id: PeerIdStr, controlMsg: RPC.ControlMessage): Promise { + private async handleControlMessage(id: PeerIdStr, controlMsg: RPC.IControlMessage): Promise { if (controlMsg === undefined) { return } - const iwant = this.handleIHave(id, controlMsg.ihave) - const ihave = this.handleIWant(id, controlMsg.iwant) - const prune = await this.handleGraft(id, controlMsg.graft) - await this.handlePrune(id, controlMsg.prune) + const iwant = controlMsg.ihave ? this.handleIHave(id, controlMsg.ihave) : [] + const ihave = controlMsg.iwant ? this.handleIWant(id, controlMsg.iwant) : [] + const prune = controlMsg.graft ? await this.handleGraft(id, controlMsg.graft) : [] + controlMsg.prune && (await this.handlePrune(id, controlMsg.prune)) if (!iwant.length && !ihave.length && !prune.length) { return @@ -1218,7 +1220,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Handles IHAVE messages */ - private handleIHave(id: PeerIdStr, ihave: RPC.ControlIHave[]): RPC.ControlIWant[] { + private handleIHave(id: PeerIdStr, ihave: RPC.IControlIHave[]): RPC.IControlIWant[] { if (!ihave.length) { return [] } @@ -1255,7 +1257,7 @@ export class GossipSub extends EventEmitter implements Initiali const iwant = new Map() ihave.forEach(({ topicID, messageIDs }) => { - if (!topicID || !this.mesh.has(topicID)) { + if (!topicID || !messageIDs || !this.mesh.has(topicID)) { return } @@ -1304,7 +1306,7 @@ export class GossipSub extends EventEmitter implements Initiali * Handles IWANT messages * Returns messages to send back to peer */ - private handleIWant(id: PeerIdStr, iwant: RPC.ControlIWant[]): RPC.Message[] { + private handleIWant(id: PeerIdStr, iwant: RPC.IControlIWant[]): RPC.IMessage[] { if (!iwant.length) { return [] } @@ -1316,28 +1318,29 @@ export class GossipSub extends EventEmitter implements Initiali return [] } - const ihave = new Map() + const ihave = new Map() const iwantByTopic = new Map() let iwantDonthave = 0 iwant.forEach(({ messageIDs }) => { - messageIDs.forEach((msgId) => { - const msgIdStr = this.msgIdToStrFn(msgId) - const entry = this.mcache.getWithIWantCount(msgIdStr, id) - if (entry == null) { - iwantDonthave++ - return - } + messageIDs && + messageIDs.forEach((msgId) => { + const msgIdStr = this.msgIdToStrFn(msgId) + const entry = this.mcache.getWithIWantCount(msgIdStr, id) + if (entry == null) { + iwantDonthave++ + return + } - iwantByTopic.set(entry.msg.topic, 1 + (iwantByTopic.get(entry.msg.topic) ?? 0)) + iwantByTopic.set(entry.msg.topic, 1 + (iwantByTopic.get(entry.msg.topic) ?? 0)) - if (entry.count > constants.GossipsubGossipRetransmission) { - this.log('IWANT: Peer %s has asked for message %s too many times: ignoring request', id, msgId) - return - } + if (entry.count > constants.GossipsubGossipRetransmission) { + this.log('IWANT: Peer %s has asked for message %s too many times: ignoring request', id, msgId) + return + } - ihave.set(msgIdStr, entry.msg) - }) + ihave.set(msgIdStr, entry.msg) + }) }) this.metrics?.onIwantRcv(iwantByTopic, iwantDonthave) @@ -1355,7 +1358,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Handles Graft messages */ - private async handleGraft(id: PeerIdStr, graft: RPC.ControlGraft[]): Promise { + private async handleGraft(id: PeerIdStr, graft: RPC.IControlGraft[]): Promise { const prune: TopicStr[] = [] const score = this.score.score(id) const now = Date.now() @@ -1447,7 +1450,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Handles Prune messages */ - private async handlePrune(id: PeerIdStr, prune: RPC.ControlPrune[]): Promise { + private async handlePrune(id: PeerIdStr, prune: RPC.IControlPrune[]): Promise { const score = this.score.score(id) for (const { topicID, backoff, peers } of prune) { @@ -1475,7 +1478,7 @@ export class GossipSub extends EventEmitter implements Initiali } // PX - if (peers.length) { + if (peers && peers.length) { // we ignore PX from peers with insufficient scores if (score < this.opts.scoreThresholds.acceptPXThreshold) { this.log( @@ -1567,7 +1570,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Maybe attempt connection given signed peer records */ - private async pxConnect(peers: RPC.PeerInfo[]): Promise { + private async pxConnect(peers: RPC.IPeerInfo[]): Promise { if (peers.length > this.opts.prunePeers) { shuffle(peers) peers = peers.slice(0, this.opts.prunePeers) @@ -1909,7 +1912,7 @@ export class GossipSub extends EventEmitter implements Initiali */ private forwardMessage( msgIdStr: string, - rawMsg: RPC.Message, + rawMsg: RPC.IMessage, propagationSource?: PeerIdStr, excludePeers?: Set ): void { @@ -1955,8 +1958,8 @@ export class GossipSub extends EventEmitter implements Initiali data, // the uncompressed form sequenceNumber: rawMsg.seqno == null ? undefined : BigInt(`0x${uint8ArrayToString(rawMsg.seqno, 'base16')}`), topic, - signature: rawMsg.signature, - key: rawMsg.key + signature: rawMsg.signature ?? undefined, + key: rawMsg.key ?? undefined } const msgId = await this.msgIdFn(msg) const msgIdStr = this.msgIdToStrFn(msgId) @@ -2106,7 +2109,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Send an rpc object to a peer */ - private sendRpc(id: PeerIdStr, rpc: RPC): boolean { + private sendRpc(id: PeerIdStr, rpc: IRPC): boolean { const outboundStream = this.streamsOutbound.get(id) if (!outboundStream) { this.log(`Cannot send RPC to ${id} as there is no open stream to it available`) @@ -2127,7 +2130,7 @@ export class GossipSub extends EventEmitter implements Initiali this.gossip.delete(id) } - const rpcBytes = RPC.encode(rpc) + const rpcBytes = RPC.encode(rpc).finish() outboundStream.push(rpcBytes) this.metrics?.onRpcSent(rpc, rpcBytes.length) @@ -2135,23 +2138,27 @@ export class GossipSub extends EventEmitter implements Initiali return true } - public piggybackControl(id: PeerIdStr, outRpc: RPC, ctrl: RPC.ControlMessage): void { - const tograft = ctrl.graft.filter(({ topicID }) => ((topicID && this.mesh.get(topicID)) || new Set()).has(id)) - const toprune = ctrl.prune.filter(({ topicID }) => !((topicID && this.mesh.get(topicID)) || new Set()).has(id)) + public piggybackControl(id: PeerIdStr, outRpc: IRPC, ctrl: RPC.IControlMessage): void { + const tograft = (ctrl.graft || []).filter(({ topicID }) => + ((topicID && this.mesh.get(topicID)) || new Set()).has(id) + ) + const toprune = (ctrl.prune || []).filter( + ({ topicID }) => !((topicID && this.mesh.get(topicID)) || new Set()).has(id) + ) if (!tograft.length && !toprune.length) { return } if (outRpc.control) { - outRpc.control.graft = outRpc.control.graft.concat(tograft) - outRpc.control.prune = outRpc.control.prune.concat(toprune) + outRpc.control.graft = outRpc.control.graft && outRpc.control.graft.concat(tograft) + outRpc.control.prune = outRpc.control.prune && outRpc.control.prune.concat(toprune) } else { outRpc.control = { graft: tograft, prune: toprune, ihave: [], iwant: [] } } } - private piggybackGossip(id: PeerIdStr, outRpc: RPC, ihave: RPC.ControlIHave[]): void { + private piggybackGossip(id: PeerIdStr, outRpc: IRPC, ihave: RPC.IControlIHave[]): void { if (!outRpc.control) { outRpc.control = { ihave: [], iwant: [], graft: [], prune: [] } } @@ -2172,7 +2179,7 @@ export class GossipSub extends EventEmitter implements Initiali const doPX = this.opts.doPX for (const [id, topics] of tograft) { const graft = topics.map((topicID) => ({ topicID })) - let prune: RPC.ControlPrune[] = [] + let prune: RPC.IControlPrune[] = [] // If a peer also has prunes, process them now const pruning = toprune.get(id) if (pruning) { @@ -2275,7 +2282,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Adds new IHAVE messages to pending gossip */ - private pushGossip(id: PeerIdStr, controlIHaveMsgs: RPC.ControlIHave): void { + private pushGossip(id: PeerIdStr, controlIHaveMsgs: RPC.IControlIHave): void { this.log('Add gossip to %s', id) const gossip = this.gossip.get(id) || [] this.gossip.set(id, gossip.concat(controlIHaveMsgs)) @@ -2284,7 +2291,7 @@ export class GossipSub extends EventEmitter implements Initiali /** * Make a PRUNE control message for a peer in a topic */ - private async makePrune(id: PeerIdStr, topic: string, doPX: boolean): Promise { + private async makePrune(id: PeerIdStr, topic: string, doPX: boolean): Promise { this.score.prune(id, topic) if (this.streamsOutbound.get(id)!.protocol === constants.GossipsubIDv10) { // Gossipsub v1.0 -- no backoff, the peer won't be able to parse it anyway @@ -2296,7 +2303,7 @@ export class GossipSub extends EventEmitter implements Initiali // backoff is measured in seconds // GossipsubPruneBackoff is measured in milliseconds // The protobuf has it as a uint64 - const backoff = BigInt(this.opts.pruneBackoff / 1000) + const backoff = this.opts.pruneBackoff / 1000 if (!doPX) { return { topicID: topic, diff --git a/src/message-cache.ts b/src/message-cache.ts index 29033b6f..b33fc79e 100644 --- a/src/message-cache.ts +++ b/src/message-cache.ts @@ -6,7 +6,7 @@ export type CacheEntry = MessageId & { } interface MessageCacheEntry { - message: RPC.Message + message: RPC.IMessage /** * Tracks if the message has been validated by the app layer and thus forwarded */ @@ -55,7 +55,7 @@ export class MessageCache { * Adds a message to the current window and the cache * Returns true if the message is not known and is inserted in the cache */ - put(messageId: MessageId, msg: RPC.Message, validated = false): boolean { + put(messageId: MessageId, msg: RPC.IMessage, validated = false): boolean { const { msgIdStr } = messageId // Don't add duplicate entries to the cache. if (this.msgs.has(msgIdStr)) { @@ -90,7 +90,7 @@ export class MessageCache { /** * Retrieves a message from the cache by its ID, if it is still present */ - get(msgId: Uint8Array): RPC.Message | undefined { + get(msgId: Uint8Array): RPC.IMessage | undefined { return this.msgs.get(this.msgIdToStrFn(msgId))?.message } @@ -98,7 +98,7 @@ export class MessageCache { * Increases the iwant count for the given message by one and returns the message together * with the iwant if the message exists. */ - getWithIWantCount(msgIdStr: string, p: string): { msg: RPC.Message; count: number } | null { + getWithIWantCount(msgIdStr: string, p: string): { msg: RPC.IMessage; count: number } | null { const msg = this.msgs.get(msgIdStr) if (!msg) { return null @@ -137,7 +137,7 @@ export class MessageCache { * This function also returns the known peers that have sent us this message. This is used to * prevent us sending redundant messages to peers who have already propagated it. */ - validate(msgId: MsgIdStr): { message: RPC.Message; originatingPeers: Set } | null { + validate(msgId: MsgIdStr): { message: RPC.IMessage; originatingPeers: Set } | null { const entry = this.msgs.get(msgId) if (!entry) { return null diff --git a/src/message/index.ts b/src/message/index.ts deleted file mode 100644 index d1e0e360..00000000 --- a/src/message/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './rpc.js' diff --git a/src/message/rpc.d.ts b/src/message/rpc.d.ts new file mode 100644 index 00000000..3716d3cc --- /dev/null +++ b/src/message/rpc.d.ts @@ -0,0 +1,666 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a RPC. */ +export interface IRPC { + + /** RPC subscriptions */ + subscriptions?: (RPC.ISubOpts[]|null); + + /** RPC messages */ + messages?: (RPC.IMessage[]|null); + + /** RPC control */ + control?: (RPC.IControlMessage|null); +} + +/** Represents a RPC. */ +export class RPC implements IRPC { + + /** + * Constructs a new RPC. + * @param [p] Properties to set + */ + constructor(p?: IRPC); + + /** RPC subscriptions. */ + public subscriptions: RPC.ISubOpts[]; + + /** RPC messages. */ + public messages: RPC.IMessage[]; + + /** RPC control. */ + public control?: (RPC.IControlMessage|null); + + /** RPC _control. */ + public _control?: "control"; + + /** + * Encodes the specified RPC message. Does not implicitly {@link RPC.verify|verify} messages. + * @param m RPC message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IRPC, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a RPC message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns RPC + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC; + + /** + * Creates a RPC message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns RPC + */ + public static fromObject(d: { [k: string]: any }): RPC; + + /** + * Creates a plain object from a RPC message. Also converts values to other types if specified. + * @param m RPC + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this RPC to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +export namespace RPC { + + /** Properties of a SubOpts. */ + interface ISubOpts { + + /** SubOpts subscribe */ + subscribe?: (boolean|null); + + /** SubOpts topic */ + topic?: (string|null); + } + + /** Represents a SubOpts. */ + class SubOpts implements ISubOpts { + + /** + * Constructs a new SubOpts. + * @param [p] Properties to set + */ + constructor(p?: RPC.ISubOpts); + + /** SubOpts subscribe. */ + public subscribe?: (boolean|null); + + /** SubOpts topic. */ + public topic?: (string|null); + + /** SubOpts _subscribe. */ + public _subscribe?: "subscribe"; + + /** SubOpts _topic. */ + public _topic?: "topic"; + + /** + * Encodes the specified SubOpts message. Does not implicitly {@link RPC.SubOpts.verify|verify} messages. + * @param m SubOpts message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.ISubOpts, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a SubOpts message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns SubOpts + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.SubOpts; + + /** + * Creates a SubOpts message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns SubOpts + */ + public static fromObject(d: { [k: string]: any }): RPC.SubOpts; + + /** + * Creates a plain object from a SubOpts message. Also converts values to other types if specified. + * @param m SubOpts + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.SubOpts, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this SubOpts to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a Message. */ + interface IMessage { + + /** Message from */ + from?: (Uint8Array|null); + + /** Message data */ + data?: (Uint8Array|null); + + /** Message seqno */ + seqno?: (Uint8Array|null); + + /** Message topic */ + topic: string; + + /** Message signature */ + signature?: (Uint8Array|null); + + /** Message key */ + key?: (Uint8Array|null); + } + + /** Represents a Message. */ + class Message implements IMessage { + + /** + * Constructs a new Message. + * @param [p] Properties to set + */ + constructor(p?: RPC.IMessage); + + /** Message from. */ + public from?: (Uint8Array|null); + + /** Message data. */ + public data?: (Uint8Array|null); + + /** Message seqno. */ + public seqno?: (Uint8Array|null); + + /** Message topic. */ + public topic: string; + + /** Message signature. */ + public signature?: (Uint8Array|null); + + /** Message key. */ + public key?: (Uint8Array|null); + + /** Message _from. */ + public _from?: "from"; + + /** Message _data. */ + public _data?: "data"; + + /** Message _seqno. */ + public _seqno?: "seqno"; + + /** Message _signature. */ + public _signature?: "signature"; + + /** Message _key. */ + public _key?: "key"; + + /** + * Encodes the specified Message message. Does not implicitly {@link RPC.Message.verify|verify} messages. + * @param m Message message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.IMessage, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Message message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Message + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.Message; + + /** + * Creates a Message message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Message + */ + public static fromObject(d: { [k: string]: any }): RPC.Message; + + /** + * Creates a plain object from a Message message. Also converts values to other types if specified. + * @param m Message + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.Message, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Message to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a ControlMessage. */ + interface IControlMessage { + + /** ControlMessage ihave */ + ihave?: (RPC.IControlIHave[]|null); + + /** ControlMessage iwant */ + iwant?: (RPC.IControlIWant[]|null); + + /** ControlMessage graft */ + graft?: (RPC.IControlGraft[]|null); + + /** ControlMessage prune */ + prune?: (RPC.IControlPrune[]|null); + } + + /** Represents a ControlMessage. */ + class ControlMessage implements IControlMessage { + + /** + * Constructs a new ControlMessage. + * @param [p] Properties to set + */ + constructor(p?: RPC.IControlMessage); + + /** ControlMessage ihave. */ + public ihave: RPC.IControlIHave[]; + + /** ControlMessage iwant. */ + public iwant: RPC.IControlIWant[]; + + /** ControlMessage graft. */ + public graft: RPC.IControlGraft[]; + + /** ControlMessage prune. */ + public prune: RPC.IControlPrune[]; + + /** + * Encodes the specified ControlMessage message. Does not implicitly {@link RPC.ControlMessage.verify|verify} messages. + * @param m ControlMessage message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.IControlMessage, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a ControlMessage message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns ControlMessage + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.ControlMessage; + + /** + * Creates a ControlMessage message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns ControlMessage + */ + public static fromObject(d: { [k: string]: any }): RPC.ControlMessage; + + /** + * Creates a plain object from a ControlMessage message. Also converts values to other types if specified. + * @param m ControlMessage + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.ControlMessage, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ControlMessage to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a ControlIHave. */ + interface IControlIHave { + + /** ControlIHave topicID */ + topicID?: (string|null); + + /** ControlIHave messageIDs */ + messageIDs?: (Uint8Array[]|null); + } + + /** Represents a ControlIHave. */ + class ControlIHave implements IControlIHave { + + /** + * Constructs a new ControlIHave. + * @param [p] Properties to set + */ + constructor(p?: RPC.IControlIHave); + + /** ControlIHave topicID. */ + public topicID?: (string|null); + + /** ControlIHave messageIDs. */ + public messageIDs: Uint8Array[]; + + /** ControlIHave _topicID. */ + public _topicID?: "topicID"; + + /** + * Encodes the specified ControlIHave message. Does not implicitly {@link RPC.ControlIHave.verify|verify} messages. + * @param m ControlIHave message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.IControlIHave, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a ControlIHave message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns ControlIHave + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.ControlIHave; + + /** + * Creates a ControlIHave message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns ControlIHave + */ + public static fromObject(d: { [k: string]: any }): RPC.ControlIHave; + + /** + * Creates a plain object from a ControlIHave message. Also converts values to other types if specified. + * @param m ControlIHave + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.ControlIHave, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ControlIHave to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a ControlIWant. */ + interface IControlIWant { + + /** ControlIWant messageIDs */ + messageIDs?: (Uint8Array[]|null); + } + + /** Represents a ControlIWant. */ + class ControlIWant implements IControlIWant { + + /** + * Constructs a new ControlIWant. + * @param [p] Properties to set + */ + constructor(p?: RPC.IControlIWant); + + /** ControlIWant messageIDs. */ + public messageIDs: Uint8Array[]; + + /** + * Encodes the specified ControlIWant message. Does not implicitly {@link RPC.ControlIWant.verify|verify} messages. + * @param m ControlIWant message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.IControlIWant, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a ControlIWant message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns ControlIWant + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.ControlIWant; + + /** + * Creates a ControlIWant message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns ControlIWant + */ + public static fromObject(d: { [k: string]: any }): RPC.ControlIWant; + + /** + * Creates a plain object from a ControlIWant message. Also converts values to other types if specified. + * @param m ControlIWant + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.ControlIWant, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ControlIWant to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a ControlGraft. */ + interface IControlGraft { + + /** ControlGraft topicID */ + topicID?: (string|null); + } + + /** Represents a ControlGraft. */ + class ControlGraft implements IControlGraft { + + /** + * Constructs a new ControlGraft. + * @param [p] Properties to set + */ + constructor(p?: RPC.IControlGraft); + + /** ControlGraft topicID. */ + public topicID?: (string|null); + + /** ControlGraft _topicID. */ + public _topicID?: "topicID"; + + /** + * Encodes the specified ControlGraft message. Does not implicitly {@link RPC.ControlGraft.verify|verify} messages. + * @param m ControlGraft message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.IControlGraft, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a ControlGraft message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns ControlGraft + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.ControlGraft; + + /** + * Creates a ControlGraft message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns ControlGraft + */ + public static fromObject(d: { [k: string]: any }): RPC.ControlGraft; + + /** + * Creates a plain object from a ControlGraft message. Also converts values to other types if specified. + * @param m ControlGraft + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.ControlGraft, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ControlGraft to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a ControlPrune. */ + interface IControlPrune { + + /** ControlPrune topicID */ + topicID?: (string|null); + + /** ControlPrune peers */ + peers?: (RPC.IPeerInfo[]|null); + + /** ControlPrune backoff */ + backoff?: (number|null); + } + + /** Represents a ControlPrune. */ + class ControlPrune implements IControlPrune { + + /** + * Constructs a new ControlPrune. + * @param [p] Properties to set + */ + constructor(p?: RPC.IControlPrune); + + /** ControlPrune topicID. */ + public topicID?: (string|null); + + /** ControlPrune peers. */ + public peers: RPC.IPeerInfo[]; + + /** ControlPrune backoff. */ + public backoff?: (number|null); + + /** ControlPrune _topicID. */ + public _topicID?: "topicID"; + + /** ControlPrune _backoff. */ + public _backoff?: "backoff"; + + /** + * Encodes the specified ControlPrune message. Does not implicitly {@link RPC.ControlPrune.verify|verify} messages. + * @param m ControlPrune message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.IControlPrune, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a ControlPrune message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns ControlPrune + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.ControlPrune; + + /** + * Creates a ControlPrune message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns ControlPrune + */ + public static fromObject(d: { [k: string]: any }): RPC.ControlPrune; + + /** + * Creates a plain object from a ControlPrune message. Also converts values to other types if specified. + * @param m ControlPrune + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.ControlPrune, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ControlPrune to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a PeerInfo. */ + interface IPeerInfo { + + /** PeerInfo peerID */ + peerID?: (Uint8Array|null); + + /** PeerInfo signedPeerRecord */ + signedPeerRecord?: (Uint8Array|null); + } + + /** Represents a PeerInfo. */ + class PeerInfo implements IPeerInfo { + + /** + * Constructs a new PeerInfo. + * @param [p] Properties to set + */ + constructor(p?: RPC.IPeerInfo); + + /** PeerInfo peerID. */ + public peerID?: (Uint8Array|null); + + /** PeerInfo signedPeerRecord. */ + public signedPeerRecord?: (Uint8Array|null); + + /** PeerInfo _peerID. */ + public _peerID?: "peerID"; + + /** PeerInfo _signedPeerRecord. */ + public _signedPeerRecord?: "signedPeerRecord"; + + /** + * Encodes the specified PeerInfo message. Does not implicitly {@link RPC.PeerInfo.verify|verify} messages. + * @param m PeerInfo message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.IPeerInfo, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a PeerInfo message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns PeerInfo + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.PeerInfo; + + /** + * Creates a PeerInfo message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns PeerInfo + */ + public static fromObject(d: { [k: string]: any }): RPC.PeerInfo; + + /** + * Creates a plain object from a PeerInfo message. Also converts values to other types if specified. + * @param m PeerInfo + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.PeerInfo, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this PeerInfo to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } +} diff --git a/src/message/rpc.js b/src/message/rpc.js new file mode 100644 index 00000000..4f5f4ce6 --- /dev/null +++ b/src/message/rpc.js @@ -0,0 +1,1878 @@ +// @ts-nocheck +/*eslint-disable*/ +(function(global, factory) { /* global define, require, module */ + + /* AMD */ if (typeof define === 'function' && define.amd) + define(["protobufjs/minimal"], factory); + + /* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports) + module.exports = factory(require("protobufjs/minimal")); + +})(this, function($protobuf) { + "use strict"; + + // Common aliases + var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + + // Exported root namespace + var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + + $root.RPC = (function() { + + /** + * Properties of a RPC. + * @exports IRPC + * @interface IRPC + * @property {Array.|null} [subscriptions] RPC subscriptions + * @property {Array.|null} [messages] RPC messages + * @property {RPC.IControlMessage|null} [control] RPC control + */ + + /** + * Constructs a new RPC. + * @exports RPC + * @classdesc Represents a RPC. + * @implements IRPC + * @constructor + * @param {IRPC=} [p] Properties to set + */ + function RPC(p) { + this.subscriptions = []; + this.messages = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * RPC subscriptions. + * @member {Array.} subscriptions + * @memberof RPC + * @instance + */ + RPC.prototype.subscriptions = $util.emptyArray; + + /** + * RPC messages. + * @member {Array.} messages + * @memberof RPC + * @instance + */ + RPC.prototype.messages = $util.emptyArray; + + /** + * RPC control. + * @member {RPC.IControlMessage|null|undefined} control + * @memberof RPC + * @instance + */ + RPC.prototype.control = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * RPC _control. + * @member {"control"|undefined} _control + * @memberof RPC + * @instance + */ + Object.defineProperty(RPC.prototype, "_control", { + get: $util.oneOfGetter($oneOfFields = ["control"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified RPC message. Does not implicitly {@link RPC.verify|verify} messages. + * @function encode + * @memberof RPC + * @static + * @param {IRPC} m RPC message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + RPC.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.subscriptions != null && m.subscriptions.length) { + for (var i = 0; i < m.subscriptions.length; ++i) + $root.RPC.SubOpts.encode(m.subscriptions[i], w.uint32(10).fork()).ldelim(); + } + if (m.messages != null && m.messages.length) { + for (var i = 0; i < m.messages.length; ++i) + $root.RPC.Message.encode(m.messages[i], w.uint32(18).fork()).ldelim(); + } + if (m.control != null && Object.hasOwnProperty.call(m, "control")) + $root.RPC.ControlMessage.encode(m.control, w.uint32(26).fork()).ldelim(); + return w; + }; + + /** + * Decodes a RPC message from the specified reader or buffer. + * @function decode + * @memberof RPC + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC} RPC + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + RPC.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.subscriptions && m.subscriptions.length)) + m.subscriptions = []; + m.subscriptions.push($root.RPC.SubOpts.decode(r, r.uint32())); + break; + case 2: + if (!(m.messages && m.messages.length)) + m.messages = []; + m.messages.push($root.RPC.Message.decode(r, r.uint32())); + break; + case 3: + m.control = $root.RPC.ControlMessage.decode(r, r.uint32()); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a RPC message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC + * @static + * @param {Object.} d Plain object + * @returns {RPC} RPC + */ + RPC.fromObject = function fromObject(d) { + if (d instanceof $root.RPC) + return d; + var m = new $root.RPC(); + if (d.subscriptions) { + if (!Array.isArray(d.subscriptions)) + throw TypeError(".RPC.subscriptions: array expected"); + m.subscriptions = []; + for (var i = 0; i < d.subscriptions.length; ++i) { + if (typeof d.subscriptions[i] !== "object") + throw TypeError(".RPC.subscriptions: object expected"); + m.subscriptions[i] = $root.RPC.SubOpts.fromObject(d.subscriptions[i]); + } + } + if (d.messages) { + if (!Array.isArray(d.messages)) + throw TypeError(".RPC.messages: array expected"); + m.messages = []; + for (var i = 0; i < d.messages.length; ++i) { + if (typeof d.messages[i] !== "object") + throw TypeError(".RPC.messages: object expected"); + m.messages[i] = $root.RPC.Message.fromObject(d.messages[i]); + } + } + if (d.control != null) { + if (typeof d.control !== "object") + throw TypeError(".RPC.control: object expected"); + m.control = $root.RPC.ControlMessage.fromObject(d.control); + } + return m; + }; + + /** + * Creates a plain object from a RPC message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC + * @static + * @param {RPC} m RPC + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + RPC.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.subscriptions = []; + d.messages = []; + } + if (m.subscriptions && m.subscriptions.length) { + d.subscriptions = []; + for (var j = 0; j < m.subscriptions.length; ++j) { + d.subscriptions[j] = $root.RPC.SubOpts.toObject(m.subscriptions[j], o); + } + } + if (m.messages && m.messages.length) { + d.messages = []; + for (var j = 0; j < m.messages.length; ++j) { + d.messages[j] = $root.RPC.Message.toObject(m.messages[j], o); + } + } + if (m.control != null && m.hasOwnProperty("control")) { + d.control = $root.RPC.ControlMessage.toObject(m.control, o); + if (o.oneofs) + d._control = "control"; + } + return d; + }; + + /** + * Converts this RPC to JSON. + * @function toJSON + * @memberof RPC + * @instance + * @returns {Object.} JSON object + */ + RPC.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + RPC.SubOpts = (function() { + + /** + * Properties of a SubOpts. + * @memberof RPC + * @interface ISubOpts + * @property {boolean|null} [subscribe] SubOpts subscribe + * @property {string|null} [topic] SubOpts topic + */ + + /** + * Constructs a new SubOpts. + * @memberof RPC + * @classdesc Represents a SubOpts. + * @implements ISubOpts + * @constructor + * @param {RPC.ISubOpts=} [p] Properties to set + */ + function SubOpts(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * SubOpts subscribe. + * @member {boolean|null|undefined} subscribe + * @memberof RPC.SubOpts + * @instance + */ + SubOpts.prototype.subscribe = null; + + /** + * SubOpts topic. + * @member {string|null|undefined} topic + * @memberof RPC.SubOpts + * @instance + */ + SubOpts.prototype.topic = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * SubOpts _subscribe. + * @member {"subscribe"|undefined} _subscribe + * @memberof RPC.SubOpts + * @instance + */ + Object.defineProperty(SubOpts.prototype, "_subscribe", { + get: $util.oneOfGetter($oneOfFields = ["subscribe"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * SubOpts _topic. + * @member {"topic"|undefined} _topic + * @memberof RPC.SubOpts + * @instance + */ + Object.defineProperty(SubOpts.prototype, "_topic", { + get: $util.oneOfGetter($oneOfFields = ["topic"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified SubOpts message. Does not implicitly {@link RPC.SubOpts.verify|verify} messages. + * @function encode + * @memberof RPC.SubOpts + * @static + * @param {RPC.ISubOpts} m SubOpts message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SubOpts.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.subscribe != null && Object.hasOwnProperty.call(m, "subscribe")) + w.uint32(8).bool(m.subscribe); + if (m.topic != null && Object.hasOwnProperty.call(m, "topic")) + w.uint32(18).string(m.topic); + return w; + }; + + /** + * Decodes a SubOpts message from the specified reader or buffer. + * @function decode + * @memberof RPC.SubOpts + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.SubOpts} SubOpts + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SubOpts.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.SubOpts(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.subscribe = r.bool(); + break; + case 2: + m.topic = r.string(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a SubOpts message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.SubOpts + * @static + * @param {Object.} d Plain object + * @returns {RPC.SubOpts} SubOpts + */ + SubOpts.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.SubOpts) + return d; + var m = new $root.RPC.SubOpts(); + if (d.subscribe != null) { + m.subscribe = Boolean(d.subscribe); + } + if (d.topic != null) { + m.topic = String(d.topic); + } + return m; + }; + + /** + * Creates a plain object from a SubOpts message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.SubOpts + * @static + * @param {RPC.SubOpts} m SubOpts + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + SubOpts.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (m.subscribe != null && m.hasOwnProperty("subscribe")) { + d.subscribe = m.subscribe; + if (o.oneofs) + d._subscribe = "subscribe"; + } + if (m.topic != null && m.hasOwnProperty("topic")) { + d.topic = m.topic; + if (o.oneofs) + d._topic = "topic"; + } + return d; + }; + + /** + * Converts this SubOpts to JSON. + * @function toJSON + * @memberof RPC.SubOpts + * @instance + * @returns {Object.} JSON object + */ + SubOpts.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return SubOpts; + })(); + + RPC.Message = (function() { + + /** + * Properties of a Message. + * @memberof RPC + * @interface IMessage + * @property {Uint8Array|null} [from] Message from + * @property {Uint8Array|null} [data] Message data + * @property {Uint8Array|null} [seqno] Message seqno + * @property {string} topic Message topic + * @property {Uint8Array|null} [signature] Message signature + * @property {Uint8Array|null} [key] Message key + */ + + /** + * Constructs a new Message. + * @memberof RPC + * @classdesc Represents a Message. + * @implements IMessage + * @constructor + * @param {RPC.IMessage=} [p] Properties to set + */ + function Message(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Message from. + * @member {Uint8Array|null|undefined} from + * @memberof RPC.Message + * @instance + */ + Message.prototype.from = null; + + /** + * Message data. + * @member {Uint8Array|null|undefined} data + * @memberof RPC.Message + * @instance + */ + Message.prototype.data = null; + + /** + * Message seqno. + * @member {Uint8Array|null|undefined} seqno + * @memberof RPC.Message + * @instance + */ + Message.prototype.seqno = null; + + /** + * Message topic. + * @member {string} topic + * @memberof RPC.Message + * @instance + */ + Message.prototype.topic = ""; + + /** + * Message signature. + * @member {Uint8Array|null|undefined} signature + * @memberof RPC.Message + * @instance + */ + Message.prototype.signature = null; + + /** + * Message key. + * @member {Uint8Array|null|undefined} key + * @memberof RPC.Message + * @instance + */ + Message.prototype.key = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * Message _from. + * @member {"from"|undefined} _from + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_from", { + get: $util.oneOfGetter($oneOfFields = ["from"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Message _data. + * @member {"data"|undefined} _data + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_data", { + get: $util.oneOfGetter($oneOfFields = ["data"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Message _seqno. + * @member {"seqno"|undefined} _seqno + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_seqno", { + get: $util.oneOfGetter($oneOfFields = ["seqno"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Message _signature. + * @member {"signature"|undefined} _signature + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_signature", { + get: $util.oneOfGetter($oneOfFields = ["signature"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Message _key. + * @member {"key"|undefined} _key + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_key", { + get: $util.oneOfGetter($oneOfFields = ["key"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified Message message. Does not implicitly {@link RPC.Message.verify|verify} messages. + * @function encode + * @memberof RPC.Message + * @static + * @param {RPC.IMessage} m Message message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Message.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.from != null && Object.hasOwnProperty.call(m, "from")) + w.uint32(10).bytes(m.from); + if (m.data != null && Object.hasOwnProperty.call(m, "data")) + w.uint32(18).bytes(m.data); + if (m.seqno != null && Object.hasOwnProperty.call(m, "seqno")) + w.uint32(26).bytes(m.seqno); + w.uint32(34).string(m.topic); + if (m.signature != null && Object.hasOwnProperty.call(m, "signature")) + w.uint32(42).bytes(m.signature); + if (m.key != null && Object.hasOwnProperty.call(m, "key")) + w.uint32(50).bytes(m.key); + return w; + }; + + /** + * Decodes a Message message from the specified reader or buffer. + * @function decode + * @memberof RPC.Message + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.Message} Message + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Message.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.Message(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.from = r.bytes(); + break; + case 2: + m.data = r.bytes(); + break; + case 3: + m.seqno = r.bytes(); + break; + case 4: + m.topic = r.string(); + break; + case 5: + m.signature = r.bytes(); + break; + case 6: + m.key = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + if (!m.hasOwnProperty("topic")) + throw $util.ProtocolError("missing required 'topic'", { instance: m }); + return m; + }; + + /** + * Creates a Message message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.Message + * @static + * @param {Object.} d Plain object + * @returns {RPC.Message} Message + */ + Message.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.Message) + return d; + var m = new $root.RPC.Message(); + if (d.from != null) { + if (typeof d.from === "string") + $util.base64.decode(d.from, m.from = $util.newBuffer($util.base64.length(d.from)), 0); + else if (d.from.length) + m.from = d.from; + } + if (d.data != null) { + if (typeof d.data === "string") + $util.base64.decode(d.data, m.data = $util.newBuffer($util.base64.length(d.data)), 0); + else if (d.data.length) + m.data = d.data; + } + if (d.seqno != null) { + if (typeof d.seqno === "string") + $util.base64.decode(d.seqno, m.seqno = $util.newBuffer($util.base64.length(d.seqno)), 0); + else if (d.seqno.length) + m.seqno = d.seqno; + } + if (d.topic != null) { + m.topic = String(d.topic); + } + if (d.signature != null) { + if (typeof d.signature === "string") + $util.base64.decode(d.signature, m.signature = $util.newBuffer($util.base64.length(d.signature)), 0); + else if (d.signature.length) + m.signature = d.signature; + } + if (d.key != null) { + if (typeof d.key === "string") + $util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0); + else if (d.key.length) + m.key = d.key; + } + return m; + }; + + /** + * Creates a plain object from a Message message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.Message + * @static + * @param {RPC.Message} m Message + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Message.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.defaults) { + d.topic = ""; + } + if (m.from != null && m.hasOwnProperty("from")) { + d.from = o.bytes === String ? $util.base64.encode(m.from, 0, m.from.length) : o.bytes === Array ? Array.prototype.slice.call(m.from) : m.from; + if (o.oneofs) + d._from = "from"; + } + if (m.data != null && m.hasOwnProperty("data")) { + d.data = o.bytes === String ? $util.base64.encode(m.data, 0, m.data.length) : o.bytes === Array ? Array.prototype.slice.call(m.data) : m.data; + if (o.oneofs) + d._data = "data"; + } + if (m.seqno != null && m.hasOwnProperty("seqno")) { + d.seqno = o.bytes === String ? $util.base64.encode(m.seqno, 0, m.seqno.length) : o.bytes === Array ? Array.prototype.slice.call(m.seqno) : m.seqno; + if (o.oneofs) + d._seqno = "seqno"; + } + if (m.topic != null && m.hasOwnProperty("topic")) { + d.topic = m.topic; + } + if (m.signature != null && m.hasOwnProperty("signature")) { + d.signature = o.bytes === String ? $util.base64.encode(m.signature, 0, m.signature.length) : o.bytes === Array ? Array.prototype.slice.call(m.signature) : m.signature; + if (o.oneofs) + d._signature = "signature"; + } + if (m.key != null && m.hasOwnProperty("key")) { + d.key = o.bytes === String ? $util.base64.encode(m.key, 0, m.key.length) : o.bytes === Array ? Array.prototype.slice.call(m.key) : m.key; + if (o.oneofs) + d._key = "key"; + } + return d; + }; + + /** + * Converts this Message to JSON. + * @function toJSON + * @memberof RPC.Message + * @instance + * @returns {Object.} JSON object + */ + Message.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Message; + })(); + + RPC.ControlMessage = (function() { + + /** + * Properties of a ControlMessage. + * @memberof RPC + * @interface IControlMessage + * @property {Array.|null} [ihave] ControlMessage ihave + * @property {Array.|null} [iwant] ControlMessage iwant + * @property {Array.|null} [graft] ControlMessage graft + * @property {Array.|null} [prune] ControlMessage prune + */ + + /** + * Constructs a new ControlMessage. + * @memberof RPC + * @classdesc Represents a ControlMessage. + * @implements IControlMessage + * @constructor + * @param {RPC.IControlMessage=} [p] Properties to set + */ + function ControlMessage(p) { + this.ihave = []; + this.iwant = []; + this.graft = []; + this.prune = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlMessage ihave. + * @member {Array.} ihave + * @memberof RPC.ControlMessage + * @instance + */ + ControlMessage.prototype.ihave = $util.emptyArray; + + /** + * ControlMessage iwant. + * @member {Array.} iwant + * @memberof RPC.ControlMessage + * @instance + */ + ControlMessage.prototype.iwant = $util.emptyArray; + + /** + * ControlMessage graft. + * @member {Array.} graft + * @memberof RPC.ControlMessage + * @instance + */ + ControlMessage.prototype.graft = $util.emptyArray; + + /** + * ControlMessage prune. + * @member {Array.} prune + * @memberof RPC.ControlMessage + * @instance + */ + ControlMessage.prototype.prune = $util.emptyArray; + + /** + * Encodes the specified ControlMessage message. Does not implicitly {@link RPC.ControlMessage.verify|verify} messages. + * @function encode + * @memberof RPC.ControlMessage + * @static + * @param {RPC.IControlMessage} m ControlMessage message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlMessage.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.ihave != null && m.ihave.length) { + for (var i = 0; i < m.ihave.length; ++i) + $root.RPC.ControlIHave.encode(m.ihave[i], w.uint32(10).fork()).ldelim(); + } + if (m.iwant != null && m.iwant.length) { + for (var i = 0; i < m.iwant.length; ++i) + $root.RPC.ControlIWant.encode(m.iwant[i], w.uint32(18).fork()).ldelim(); + } + if (m.graft != null && m.graft.length) { + for (var i = 0; i < m.graft.length; ++i) + $root.RPC.ControlGraft.encode(m.graft[i], w.uint32(26).fork()).ldelim(); + } + if (m.prune != null && m.prune.length) { + for (var i = 0; i < m.prune.length; ++i) + $root.RPC.ControlPrune.encode(m.prune[i], w.uint32(34).fork()).ldelim(); + } + return w; + }; + + /** + * Decodes a ControlMessage message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlMessage + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlMessage} ControlMessage + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlMessage.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlMessage(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.ihave && m.ihave.length)) + m.ihave = []; + m.ihave.push($root.RPC.ControlIHave.decode(r, r.uint32())); + break; + case 2: + if (!(m.iwant && m.iwant.length)) + m.iwant = []; + m.iwant.push($root.RPC.ControlIWant.decode(r, r.uint32())); + break; + case 3: + if (!(m.graft && m.graft.length)) + m.graft = []; + m.graft.push($root.RPC.ControlGraft.decode(r, r.uint32())); + break; + case 4: + if (!(m.prune && m.prune.length)) + m.prune = []; + m.prune.push($root.RPC.ControlPrune.decode(r, r.uint32())); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlMessage message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlMessage + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlMessage} ControlMessage + */ + ControlMessage.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlMessage) + return d; + var m = new $root.RPC.ControlMessage(); + if (d.ihave) { + if (!Array.isArray(d.ihave)) + throw TypeError(".RPC.ControlMessage.ihave: array expected"); + m.ihave = []; + for (var i = 0; i < d.ihave.length; ++i) { + if (typeof d.ihave[i] !== "object") + throw TypeError(".RPC.ControlMessage.ihave: object expected"); + m.ihave[i] = $root.RPC.ControlIHave.fromObject(d.ihave[i]); + } + } + if (d.iwant) { + if (!Array.isArray(d.iwant)) + throw TypeError(".RPC.ControlMessage.iwant: array expected"); + m.iwant = []; + for (var i = 0; i < d.iwant.length; ++i) { + if (typeof d.iwant[i] !== "object") + throw TypeError(".RPC.ControlMessage.iwant: object expected"); + m.iwant[i] = $root.RPC.ControlIWant.fromObject(d.iwant[i]); + } + } + if (d.graft) { + if (!Array.isArray(d.graft)) + throw TypeError(".RPC.ControlMessage.graft: array expected"); + m.graft = []; + for (var i = 0; i < d.graft.length; ++i) { + if (typeof d.graft[i] !== "object") + throw TypeError(".RPC.ControlMessage.graft: object expected"); + m.graft[i] = $root.RPC.ControlGraft.fromObject(d.graft[i]); + } + } + if (d.prune) { + if (!Array.isArray(d.prune)) + throw TypeError(".RPC.ControlMessage.prune: array expected"); + m.prune = []; + for (var i = 0; i < d.prune.length; ++i) { + if (typeof d.prune[i] !== "object") + throw TypeError(".RPC.ControlMessage.prune: object expected"); + m.prune[i] = $root.RPC.ControlPrune.fromObject(d.prune[i]); + } + } + return m; + }; + + /** + * Creates a plain object from a ControlMessage message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlMessage + * @static + * @param {RPC.ControlMessage} m ControlMessage + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlMessage.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.ihave = []; + d.iwant = []; + d.graft = []; + d.prune = []; + } + if (m.ihave && m.ihave.length) { + d.ihave = []; + for (var j = 0; j < m.ihave.length; ++j) { + d.ihave[j] = $root.RPC.ControlIHave.toObject(m.ihave[j], o); + } + } + if (m.iwant && m.iwant.length) { + d.iwant = []; + for (var j = 0; j < m.iwant.length; ++j) { + d.iwant[j] = $root.RPC.ControlIWant.toObject(m.iwant[j], o); + } + } + if (m.graft && m.graft.length) { + d.graft = []; + for (var j = 0; j < m.graft.length; ++j) { + d.graft[j] = $root.RPC.ControlGraft.toObject(m.graft[j], o); + } + } + if (m.prune && m.prune.length) { + d.prune = []; + for (var j = 0; j < m.prune.length; ++j) { + d.prune[j] = $root.RPC.ControlPrune.toObject(m.prune[j], o); + } + } + return d; + }; + + /** + * Converts this ControlMessage to JSON. + * @function toJSON + * @memberof RPC.ControlMessage + * @instance + * @returns {Object.} JSON object + */ + ControlMessage.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlMessage; + })(); + + RPC.ControlIHave = (function() { + + /** + * Properties of a ControlIHave. + * @memberof RPC + * @interface IControlIHave + * @property {string|null} [topicID] ControlIHave topicID + * @property {Array.|null} [messageIDs] ControlIHave messageIDs + */ + + /** + * Constructs a new ControlIHave. + * @memberof RPC + * @classdesc Represents a ControlIHave. + * @implements IControlIHave + * @constructor + * @param {RPC.IControlIHave=} [p] Properties to set + */ + function ControlIHave(p) { + this.messageIDs = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlIHave topicID. + * @member {string|null|undefined} topicID + * @memberof RPC.ControlIHave + * @instance + */ + ControlIHave.prototype.topicID = null; + + /** + * ControlIHave messageIDs. + * @member {Array.} messageIDs + * @memberof RPC.ControlIHave + * @instance + */ + ControlIHave.prototype.messageIDs = $util.emptyArray; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * ControlIHave _topicID. + * @member {"topicID"|undefined} _topicID + * @memberof RPC.ControlIHave + * @instance + */ + Object.defineProperty(ControlIHave.prototype, "_topicID", { + get: $util.oneOfGetter($oneOfFields = ["topicID"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified ControlIHave message. Does not implicitly {@link RPC.ControlIHave.verify|verify} messages. + * @function encode + * @memberof RPC.ControlIHave + * @static + * @param {RPC.IControlIHave} m ControlIHave message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlIHave.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) + w.uint32(10).string(m.topicID); + if (m.messageIDs != null && m.messageIDs.length) { + for (var i = 0; i < m.messageIDs.length; ++i) + w.uint32(18).bytes(m.messageIDs[i]); + } + return w; + }; + + /** + * Decodes a ControlIHave message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlIHave + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlIHave} ControlIHave + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlIHave.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlIHave(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.topicID = r.string(); + break; + case 2: + if (!(m.messageIDs && m.messageIDs.length)) + m.messageIDs = []; + m.messageIDs.push(r.bytes()); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlIHave message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlIHave + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlIHave} ControlIHave + */ + ControlIHave.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlIHave) + return d; + var m = new $root.RPC.ControlIHave(); + if (d.topicID != null) { + m.topicID = String(d.topicID); + } + if (d.messageIDs) { + if (!Array.isArray(d.messageIDs)) + throw TypeError(".RPC.ControlIHave.messageIDs: array expected"); + m.messageIDs = []; + for (var i = 0; i < d.messageIDs.length; ++i) { + if (typeof d.messageIDs[i] === "string") + $util.base64.decode(d.messageIDs[i], m.messageIDs[i] = $util.newBuffer($util.base64.length(d.messageIDs[i])), 0); + else if (d.messageIDs[i].length) + m.messageIDs[i] = d.messageIDs[i]; + } + } + return m; + }; + + /** + * Creates a plain object from a ControlIHave message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlIHave + * @static + * @param {RPC.ControlIHave} m ControlIHave + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlIHave.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.messageIDs = []; + } + if (m.topicID != null && m.hasOwnProperty("topicID")) { + d.topicID = m.topicID; + if (o.oneofs) + d._topicID = "topicID"; + } + if (m.messageIDs && m.messageIDs.length) { + d.messageIDs = []; + for (var j = 0; j < m.messageIDs.length; ++j) { + d.messageIDs[j] = o.bytes === String ? $util.base64.encode(m.messageIDs[j], 0, m.messageIDs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.messageIDs[j]) : m.messageIDs[j]; + } + } + return d; + }; + + /** + * Converts this ControlIHave to JSON. + * @function toJSON + * @memberof RPC.ControlIHave + * @instance + * @returns {Object.} JSON object + */ + ControlIHave.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlIHave; + })(); + + RPC.ControlIWant = (function() { + + /** + * Properties of a ControlIWant. + * @memberof RPC + * @interface IControlIWant + * @property {Array.|null} [messageIDs] ControlIWant messageIDs + */ + + /** + * Constructs a new ControlIWant. + * @memberof RPC + * @classdesc Represents a ControlIWant. + * @implements IControlIWant + * @constructor + * @param {RPC.IControlIWant=} [p] Properties to set + */ + function ControlIWant(p) { + this.messageIDs = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlIWant messageIDs. + * @member {Array.} messageIDs + * @memberof RPC.ControlIWant + * @instance + */ + ControlIWant.prototype.messageIDs = $util.emptyArray; + + /** + * Encodes the specified ControlIWant message. Does not implicitly {@link RPC.ControlIWant.verify|verify} messages. + * @function encode + * @memberof RPC.ControlIWant + * @static + * @param {RPC.IControlIWant} m ControlIWant message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlIWant.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.messageIDs != null && m.messageIDs.length) { + for (var i = 0; i < m.messageIDs.length; ++i) + w.uint32(10).bytes(m.messageIDs[i]); + } + return w; + }; + + /** + * Decodes a ControlIWant message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlIWant + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlIWant} ControlIWant + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlIWant.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlIWant(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.messageIDs && m.messageIDs.length)) + m.messageIDs = []; + m.messageIDs.push(r.bytes()); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlIWant message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlIWant + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlIWant} ControlIWant + */ + ControlIWant.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlIWant) + return d; + var m = new $root.RPC.ControlIWant(); + if (d.messageIDs) { + if (!Array.isArray(d.messageIDs)) + throw TypeError(".RPC.ControlIWant.messageIDs: array expected"); + m.messageIDs = []; + for (var i = 0; i < d.messageIDs.length; ++i) { + if (typeof d.messageIDs[i] === "string") + $util.base64.decode(d.messageIDs[i], m.messageIDs[i] = $util.newBuffer($util.base64.length(d.messageIDs[i])), 0); + else if (d.messageIDs[i].length) + m.messageIDs[i] = d.messageIDs[i]; + } + } + return m; + }; + + /** + * Creates a plain object from a ControlIWant message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlIWant + * @static + * @param {RPC.ControlIWant} m ControlIWant + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlIWant.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.messageIDs = []; + } + if (m.messageIDs && m.messageIDs.length) { + d.messageIDs = []; + for (var j = 0; j < m.messageIDs.length; ++j) { + d.messageIDs[j] = o.bytes === String ? $util.base64.encode(m.messageIDs[j], 0, m.messageIDs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.messageIDs[j]) : m.messageIDs[j]; + } + } + return d; + }; + + /** + * Converts this ControlIWant to JSON. + * @function toJSON + * @memberof RPC.ControlIWant + * @instance + * @returns {Object.} JSON object + */ + ControlIWant.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlIWant; + })(); + + RPC.ControlGraft = (function() { + + /** + * Properties of a ControlGraft. + * @memberof RPC + * @interface IControlGraft + * @property {string|null} [topicID] ControlGraft topicID + */ + + /** + * Constructs a new ControlGraft. + * @memberof RPC + * @classdesc Represents a ControlGraft. + * @implements IControlGraft + * @constructor + * @param {RPC.IControlGraft=} [p] Properties to set + */ + function ControlGraft(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlGraft topicID. + * @member {string|null|undefined} topicID + * @memberof RPC.ControlGraft + * @instance + */ + ControlGraft.prototype.topicID = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * ControlGraft _topicID. + * @member {"topicID"|undefined} _topicID + * @memberof RPC.ControlGraft + * @instance + */ + Object.defineProperty(ControlGraft.prototype, "_topicID", { + get: $util.oneOfGetter($oneOfFields = ["topicID"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified ControlGraft message. Does not implicitly {@link RPC.ControlGraft.verify|verify} messages. + * @function encode + * @memberof RPC.ControlGraft + * @static + * @param {RPC.IControlGraft} m ControlGraft message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlGraft.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) + w.uint32(10).string(m.topicID); + return w; + }; + + /** + * Decodes a ControlGraft message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlGraft + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlGraft} ControlGraft + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlGraft.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlGraft(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.topicID = r.string(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlGraft message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlGraft + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlGraft} ControlGraft + */ + ControlGraft.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlGraft) + return d; + var m = new $root.RPC.ControlGraft(); + if (d.topicID != null) { + m.topicID = String(d.topicID); + } + return m; + }; + + /** + * Creates a plain object from a ControlGraft message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlGraft + * @static + * @param {RPC.ControlGraft} m ControlGraft + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlGraft.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (m.topicID != null && m.hasOwnProperty("topicID")) { + d.topicID = m.topicID; + if (o.oneofs) + d._topicID = "topicID"; + } + return d; + }; + + /** + * Converts this ControlGraft to JSON. + * @function toJSON + * @memberof RPC.ControlGraft + * @instance + * @returns {Object.} JSON object + */ + ControlGraft.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlGraft; + })(); + + RPC.ControlPrune = (function() { + + /** + * Properties of a ControlPrune. + * @memberof RPC + * @interface IControlPrune + * @property {string|null} [topicID] ControlPrune topicID + * @property {Array.|null} [peers] ControlPrune peers + * @property {number|null} [backoff] ControlPrune backoff + */ + + /** + * Constructs a new ControlPrune. + * @memberof RPC + * @classdesc Represents a ControlPrune. + * @implements IControlPrune + * @constructor + * @param {RPC.IControlPrune=} [p] Properties to set + */ + function ControlPrune(p) { + this.peers = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlPrune topicID. + * @member {string|null|undefined} topicID + * @memberof RPC.ControlPrune + * @instance + */ + ControlPrune.prototype.topicID = null; + + /** + * ControlPrune peers. + * @member {Array.} peers + * @memberof RPC.ControlPrune + * @instance + */ + ControlPrune.prototype.peers = $util.emptyArray; + + /** + * ControlPrune backoff. + * @member {number|null|undefined} backoff + * @memberof RPC.ControlPrune + * @instance + */ + ControlPrune.prototype.backoff = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * ControlPrune _topicID. + * @member {"topicID"|undefined} _topicID + * @memberof RPC.ControlPrune + * @instance + */ + Object.defineProperty(ControlPrune.prototype, "_topicID", { + get: $util.oneOfGetter($oneOfFields = ["topicID"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * ControlPrune _backoff. + * @member {"backoff"|undefined} _backoff + * @memberof RPC.ControlPrune + * @instance + */ + Object.defineProperty(ControlPrune.prototype, "_backoff", { + get: $util.oneOfGetter($oneOfFields = ["backoff"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified ControlPrune message. Does not implicitly {@link RPC.ControlPrune.verify|verify} messages. + * @function encode + * @memberof RPC.ControlPrune + * @static + * @param {RPC.IControlPrune} m ControlPrune message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlPrune.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) + w.uint32(10).string(m.topicID); + if (m.peers != null && m.peers.length) { + for (var i = 0; i < m.peers.length; ++i) + $root.RPC.PeerInfo.encode(m.peers[i], w.uint32(18).fork()).ldelim(); + } + if (m.backoff != null && Object.hasOwnProperty.call(m, "backoff")) + w.uint32(24).uint64(m.backoff); + return w; + }; + + /** + * Decodes a ControlPrune message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlPrune + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlPrune} ControlPrune + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlPrune.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlPrune(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.topicID = r.string(); + break; + case 2: + if (!(m.peers && m.peers.length)) + m.peers = []; + m.peers.push($root.RPC.PeerInfo.decode(r, r.uint32())); + break; + case 3: + m.backoff = r.uint64(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlPrune message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlPrune + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlPrune} ControlPrune + */ + ControlPrune.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlPrune) + return d; + var m = new $root.RPC.ControlPrune(); + if (d.topicID != null) { + m.topicID = String(d.topicID); + } + if (d.peers) { + if (!Array.isArray(d.peers)) + throw TypeError(".RPC.ControlPrune.peers: array expected"); + m.peers = []; + for (var i = 0; i < d.peers.length; ++i) { + if (typeof d.peers[i] !== "object") + throw TypeError(".RPC.ControlPrune.peers: object expected"); + m.peers[i] = $root.RPC.PeerInfo.fromObject(d.peers[i]); + } + } + if (d.backoff != null) { + if ($util.Long) + (m.backoff = $util.Long.fromValue(d.backoff)).unsigned = true; + else if (typeof d.backoff === "string") + m.backoff = parseInt(d.backoff, 10); + else if (typeof d.backoff === "number") + m.backoff = d.backoff; + else if (typeof d.backoff === "object") + m.backoff = new $util.LongBits(d.backoff.low >>> 0, d.backoff.high >>> 0).toNumber(true); + } + return m; + }; + + /** + * Creates a plain object from a ControlPrune message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlPrune + * @static + * @param {RPC.ControlPrune} m ControlPrune + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlPrune.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.peers = []; + } + if (m.topicID != null && m.hasOwnProperty("topicID")) { + d.topicID = m.topicID; + if (o.oneofs) + d._topicID = "topicID"; + } + if (m.peers && m.peers.length) { + d.peers = []; + for (var j = 0; j < m.peers.length; ++j) { + d.peers[j] = $root.RPC.PeerInfo.toObject(m.peers[j], o); + } + } + if (m.backoff != null && m.hasOwnProperty("backoff")) { + if (typeof m.backoff === "number") + d.backoff = o.longs === String ? String(m.backoff) : m.backoff; + else + d.backoff = o.longs === String ? $util.Long.prototype.toString.call(m.backoff) : o.longs === Number ? new $util.LongBits(m.backoff.low >>> 0, m.backoff.high >>> 0).toNumber(true) : m.backoff; + if (o.oneofs) + d._backoff = "backoff"; + } + return d; + }; + + /** + * Converts this ControlPrune to JSON. + * @function toJSON + * @memberof RPC.ControlPrune + * @instance + * @returns {Object.} JSON object + */ + ControlPrune.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlPrune; + })(); + + RPC.PeerInfo = (function() { + + /** + * Properties of a PeerInfo. + * @memberof RPC + * @interface IPeerInfo + * @property {Uint8Array|null} [peerID] PeerInfo peerID + * @property {Uint8Array|null} [signedPeerRecord] PeerInfo signedPeerRecord + */ + + /** + * Constructs a new PeerInfo. + * @memberof RPC + * @classdesc Represents a PeerInfo. + * @implements IPeerInfo + * @constructor + * @param {RPC.IPeerInfo=} [p] Properties to set + */ + function PeerInfo(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * PeerInfo peerID. + * @member {Uint8Array|null|undefined} peerID + * @memberof RPC.PeerInfo + * @instance + */ + PeerInfo.prototype.peerID = null; + + /** + * PeerInfo signedPeerRecord. + * @member {Uint8Array|null|undefined} signedPeerRecord + * @memberof RPC.PeerInfo + * @instance + */ + PeerInfo.prototype.signedPeerRecord = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * PeerInfo _peerID. + * @member {"peerID"|undefined} _peerID + * @memberof RPC.PeerInfo + * @instance + */ + Object.defineProperty(PeerInfo.prototype, "_peerID", { + get: $util.oneOfGetter($oneOfFields = ["peerID"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * PeerInfo _signedPeerRecord. + * @member {"signedPeerRecord"|undefined} _signedPeerRecord + * @memberof RPC.PeerInfo + * @instance + */ + Object.defineProperty(PeerInfo.prototype, "_signedPeerRecord", { + get: $util.oneOfGetter($oneOfFields = ["signedPeerRecord"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified PeerInfo message. Does not implicitly {@link RPC.PeerInfo.verify|verify} messages. + * @function encode + * @memberof RPC.PeerInfo + * @static + * @param {RPC.IPeerInfo} m PeerInfo message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + PeerInfo.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.peerID != null && Object.hasOwnProperty.call(m, "peerID")) + w.uint32(10).bytes(m.peerID); + if (m.signedPeerRecord != null && Object.hasOwnProperty.call(m, "signedPeerRecord")) + w.uint32(18).bytes(m.signedPeerRecord); + return w; + }; + + /** + * Decodes a PeerInfo message from the specified reader or buffer. + * @function decode + * @memberof RPC.PeerInfo + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.PeerInfo} PeerInfo + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + PeerInfo.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.PeerInfo(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.peerID = r.bytes(); + break; + case 2: + m.signedPeerRecord = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a PeerInfo message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.PeerInfo + * @static + * @param {Object.} d Plain object + * @returns {RPC.PeerInfo} PeerInfo + */ + PeerInfo.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.PeerInfo) + return d; + var m = new $root.RPC.PeerInfo(); + if (d.peerID != null) { + if (typeof d.peerID === "string") + $util.base64.decode(d.peerID, m.peerID = $util.newBuffer($util.base64.length(d.peerID)), 0); + else if (d.peerID.length) + m.peerID = d.peerID; + } + if (d.signedPeerRecord != null) { + if (typeof d.signedPeerRecord === "string") + $util.base64.decode(d.signedPeerRecord, m.signedPeerRecord = $util.newBuffer($util.base64.length(d.signedPeerRecord)), 0); + else if (d.signedPeerRecord.length) + m.signedPeerRecord = d.signedPeerRecord; + } + return m; + }; + + /** + * Creates a plain object from a PeerInfo message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.PeerInfo + * @static + * @param {RPC.PeerInfo} m PeerInfo + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + PeerInfo.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (m.peerID != null && m.hasOwnProperty("peerID")) { + 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; + if (o.oneofs) + d._peerID = "peerID"; + } + if (m.signedPeerRecord != null && m.hasOwnProperty("signedPeerRecord")) { + d.signedPeerRecord = o.bytes === String ? $util.base64.encode(m.signedPeerRecord, 0, m.signedPeerRecord.length) : o.bytes === Array ? Array.prototype.slice.call(m.signedPeerRecord) : m.signedPeerRecord; + if (o.oneofs) + d._signedPeerRecord = "signedPeerRecord"; + } + return d; + }; + + /** + * Converts this PeerInfo to JSON. + * @function toJSON + * @memberof RPC.PeerInfo + * @instance + * @returns {Object.} JSON object + */ + PeerInfo.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return PeerInfo; + })(); + + return RPC; + })(); + + return $root; +}); diff --git a/src/message/rpc.ts b/src/message/rpc.ts deleted file mode 100644 index ecee1f9e..00000000 --- a/src/message/rpc.ts +++ /dev/null @@ -1,215 +0,0 @@ -/* eslint-disable import/export */ -/* eslint-disable @typescript-eslint/no-namespace */ - -import { encodeMessage, decodeMessage, message, bool, string, bytes, uint64 } from 'protons-runtime' -import type { Codec } from 'protons-runtime' - -export interface RPC { - subscriptions: RPC.SubOpts[] - messages: RPC.Message[] - control?: RPC.ControlMessage -} - -export namespace RPC { - export interface SubOpts { - subscribe?: boolean - topic?: string - } - - export namespace SubOpts { - export const codec = (): Codec => { - return message({ - 1: { name: 'subscribe', codec: bool, optional: true }, - 2: { name: 'topic', codec: string, optional: true } - }) - } - - export const encode = (obj: SubOpts): Uint8Array => { - return encodeMessage(obj, SubOpts.codec()) - } - - export const decode = (buf: Uint8Array): SubOpts => { - return decodeMessage(buf, SubOpts.codec()) - } - } - - export interface Message { - from?: Uint8Array - data?: Uint8Array - seqno?: Uint8Array - topic: string - signature?: Uint8Array - key?: Uint8Array - } - - export namespace Message { - export const codec = (): Codec => { - return message({ - 1: { name: 'from', codec: bytes, optional: true }, - 2: { name: 'data', codec: bytes, optional: true }, - 3: { name: 'seqno', codec: bytes, optional: true }, - 4: { name: 'topic', codec: string }, - 5: { name: 'signature', codec: bytes, optional: true }, - 6: { name: 'key', codec: bytes, optional: true } - }) - } - - export const encode = (obj: Message): Uint8Array => { - return encodeMessage(obj, Message.codec()) - } - - export const decode = (buf: Uint8Array): Message => { - return decodeMessage(buf, Message.codec()) - } - } - - export interface ControlMessage { - ihave: RPC.ControlIHave[] - iwant: RPC.ControlIWant[] - graft: RPC.ControlGraft[] - prune: RPC.ControlPrune[] - } - - export namespace ControlMessage { - export const codec = (): Codec => { - return message({ - 1: { name: 'ihave', codec: RPC.ControlIHave.codec(), repeats: true }, - 2: { name: 'iwant', codec: RPC.ControlIWant.codec(), repeats: true }, - 3: { name: 'graft', codec: RPC.ControlGraft.codec(), repeats: true }, - 4: { name: 'prune', codec: RPC.ControlPrune.codec(), repeats: true } - }) - } - - export const encode = (obj: ControlMessage): Uint8Array => { - return encodeMessage(obj, ControlMessage.codec()) - } - - export const decode = (buf: Uint8Array): ControlMessage => { - return decodeMessage(buf, ControlMessage.codec()) - } - } - - export interface ControlIHave { - topicID?: string - messageIDs: Uint8Array[] - } - - export namespace ControlIHave { - export const codec = (): Codec => { - return message({ - 1: { name: 'topicID', codec: string, optional: true }, - 2: { name: 'messageIDs', codec: bytes, repeats: true } - }) - } - - export const encode = (obj: ControlIHave): Uint8Array => { - return encodeMessage(obj, ControlIHave.codec()) - } - - export const decode = (buf: Uint8Array): ControlIHave => { - return decodeMessage(buf, ControlIHave.codec()) - } - } - - export interface ControlIWant { - messageIDs: Uint8Array[] - } - - export namespace ControlIWant { - export const codec = (): Codec => { - return message({ - 1: { name: 'messageIDs', codec: bytes, repeats: true } - }) - } - - export const encode = (obj: ControlIWant): Uint8Array => { - return encodeMessage(obj, ControlIWant.codec()) - } - - export const decode = (buf: Uint8Array): ControlIWant => { - return decodeMessage(buf, ControlIWant.codec()) - } - } - - export interface ControlGraft { - topicID?: string - } - - export namespace ControlGraft { - export const codec = (): Codec => { - return message({ - 1: { name: 'topicID', codec: string, optional: true } - }) - } - - export const encode = (obj: ControlGraft): Uint8Array => { - return encodeMessage(obj, ControlGraft.codec()) - } - - export const decode = (buf: Uint8Array): ControlGraft => { - return decodeMessage(buf, ControlGraft.codec()) - } - } - - export interface ControlPrune { - topicID?: string - peers: RPC.PeerInfo[] - backoff?: bigint - } - - export namespace ControlPrune { - export const codec = (): Codec => { - return message({ - 1: { name: 'topicID', codec: string, optional: true }, - 2: { name: 'peers', codec: RPC.PeerInfo.codec(), repeats: true }, - 3: { name: 'backoff', codec: uint64, optional: true } - }) - } - - export const encode = (obj: ControlPrune): Uint8Array => { - return encodeMessage(obj, ControlPrune.codec()) - } - - export const decode = (buf: Uint8Array): ControlPrune => { - return decodeMessage(buf, ControlPrune.codec()) - } - } - - export interface PeerInfo { - peerID?: Uint8Array - signedPeerRecord?: Uint8Array - } - - export namespace PeerInfo { - export const codec = (): Codec => { - return message({ - 1: { name: 'peerID', codec: bytes, optional: true }, - 2: { name: 'signedPeerRecord', codec: bytes, optional: true } - }) - } - - export const encode = (obj: PeerInfo): Uint8Array => { - return encodeMessage(obj, PeerInfo.codec()) - } - - export const decode = (buf: Uint8Array): PeerInfo => { - return decodeMessage(buf, PeerInfo.codec()) - } - } - - export const codec = (): Codec => { - return message({ - 1: { name: 'subscriptions', codec: RPC.SubOpts.codec(), repeats: true }, - 2: { name: 'messages', codec: RPC.Message.codec(), repeats: true }, - 3: { name: 'control', codec: RPC.ControlMessage.codec(), optional: true } - }) - } - - export const encode = (obj: RPC): Uint8Array => { - return encodeMessage(obj, RPC.codec()) - } - - export const decode = (buf: Uint8Array): RPC => { - return decodeMessage(buf, RPC.codec()) - } -} diff --git a/src/metrics.ts b/src/metrics.ts index d0795fca..0d47f8ea 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -1,4 +1,4 @@ -import type { RPC } from './message/rpc.js' +import type { IRPC } from './message/rpc.js' import type { PeerScoreThresholds } from './score/peer-score-thresholds.js' import { MessageAcceptance, @@ -612,30 +612,30 @@ export function getMetrics( } }, - onRpcRecv(rpc: RPC, rpcBytes: number): void { + onRpcRecv(rpc: IRPC, rpcBytes: number): void { this.rpcRecvBytes.inc(rpcBytes) this.rpcRecvCount.inc(1) - this.rpcRecvSubscription.inc(rpc.subscriptions.length) - this.rpcRecvMessage.inc(rpc.messages.length) + if (rpc.subscriptions) this.rpcRecvSubscription.inc(rpc.subscriptions.length) + if (rpc.messages) this.rpcRecvMessage.inc(rpc.messages.length) if (rpc.control) { this.rpcRecvControl.inc(1) - this.rpcRecvIHave.inc(rpc.control.ihave.length) - this.rpcRecvIWant.inc(rpc.control.iwant.length) - this.rpcRecvGraft.inc(rpc.control.graft.length) - this.rpcRecvPrune.inc(rpc.control.prune.length) + if (rpc.control.ihave) this.rpcRecvIHave.inc(rpc.control.ihave.length) + if (rpc.control.iwant) this.rpcRecvIWant.inc(rpc.control.iwant.length) + if (rpc.control.graft) this.rpcRecvGraft.inc(rpc.control.graft.length) + if (rpc.control.prune) this.rpcRecvPrune.inc(rpc.control.prune.length) } }, - onRpcSent(rpc: RPC, rpcBytes: number): void { + onRpcSent(rpc: IRPC, rpcBytes: number): void { this.rpcSentBytes.inc(rpcBytes) this.rpcSentCount.inc(1) - this.rpcSentSubscription.inc(rpc.subscriptions.length) - this.rpcSentMessage.inc(rpc.messages.length) + if (rpc.subscriptions) this.rpcSentSubscription.inc(rpc.subscriptions.length) + if (rpc.messages) this.rpcSentMessage.inc(rpc.messages.length) if (rpc.control) { - const ihave = rpc.control.ihave.length - const iwant = rpc.control.iwant.length - const graft = rpc.control.graft.length - const prune = rpc.control.prune.length + const ihave = rpc.control.ihave?.length ?? 0 + const iwant = rpc.control.iwant?.length ?? 0 + const graft = rpc.control.graft?.length ?? 0 + const prune = rpc.control.prune?.length ?? 0 if (ihave > 0) this.rpcSentIHave.inc(ihave) if (iwant > 0) this.rpcSentIWant.inc(iwant) if (graft > 0) this.rpcSentGraft.inc(graft) diff --git a/src/types.ts b/src/types.ts index b060730c..89ef3bb7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,7 +18,7 @@ export interface AddrInfo { * Compute a local non-spec'ed msg-id for faster de-duplication of seen messages. * Used exclusively for a local seen_cache */ -export type FastMsgIdFn = (msg: RPC.Message) => string +export type FastMsgIdFn = (msg: RPC.IMessage) => string /** * By default, gossipsub only provide a browser friendly function to convert Uint8Array message id to string. diff --git a/src/utils/buildRawMessage.ts b/src/utils/buildRawMessage.ts index b0705336..c79795f1 100644 --- a/src/utils/buildRawMessage.ts +++ b/src/utils/buildRawMessage.ts @@ -16,10 +16,10 @@ export async function buildRawMessage( publishConfig: PublishConfig, topic: TopicStr, transformedData: Uint8Array -): Promise { +): Promise { switch (publishConfig.type) { case PublishConfigType.Signing: { - const rpcMsg: RPC.Message = { + const rpcMsg: RPC.IMessage = { from: publishConfig.author.toBytes(), data: transformedData, seqno: randomBytes(8), @@ -30,7 +30,7 @@ export async function buildRawMessage( // Get the message in bytes, and prepend with the pubsub prefix // the signature is over the bytes "libp2p-pubsub:" - const bytes = uint8ArrayConcat([SignPrefix, RPC.Message.encode(rpcMsg)]) + const bytes = uint8ArrayConcat([SignPrefix, RPC.Message.encode(rpcMsg).finish()]) rpcMsg.signature = await publishConfig.privateKey.sign(bytes) rpcMsg.key = publishConfig.key @@ -66,7 +66,7 @@ export type ValidationResult = { valid: true; fromPeerId: PeerId | null } | { va export async function validateToRawMessage( signaturePolicy: typeof StrictNoSign | typeof StrictSign, - msg: RPC.Message + msg: RPC.IMessage ): Promise { // If strict-sign, verify all // If anonymous (no-sign), ensure no preven @@ -118,7 +118,7 @@ export async function validateToRawMessage( publicKey = unmarshalPublicKey(fromPeerId.publicKey) } - const rpcMsgPreSign: RPC.Message = { + const rpcMsgPreSign: RPC.IMessage = { from: msg.from, data: msg.data, seqno: msg.seqno, @@ -129,7 +129,7 @@ export async function validateToRawMessage( // Get the message in bytes, and prepend with the pubsub prefix // the signature is over the bytes "libp2p-pubsub:" - const bytes = uint8ArrayConcat([SignPrefix, RPC.Message.encode(rpcMsgPreSign)]) + const bytes = uint8ArrayConcat([SignPrefix, RPC.Message.encode(rpcMsgPreSign).finish()]) if (!(await publicKey.verify(bytes, msg.signature))) { return { valid: false, error: ValidateError.InvalidSignature } diff --git a/src/utils/create-gossip-rpc.ts b/src/utils/create-gossip-rpc.ts index d7b2e596..6cf521dc 100644 --- a/src/utils/create-gossip-rpc.ts +++ b/src/utils/create-gossip-rpc.ts @@ -1,9 +1,9 @@ -import type { RPC } from '../message/rpc.js' +import type { IRPC, RPC } from '../message/rpc.js' /** * Create a gossipsub RPC object */ -export function createGossipRpc(messages: RPC.Message[] = [], control?: Partial): RPC { +export function createGossipRpc(messages: RPC.IMessage[] = [], control?: Partial): IRPC { return { subscriptions: [], messages, diff --git a/test/e2e/go-gossipsub.spec.ts b/test/e2e/go-gossipsub.spec.ts index 044507be..780dc763 100644 --- a/test/e2e/go-gossipsub.spec.ts +++ b/test/e2e/go-gossipsub.spec.ts @@ -8,7 +8,7 @@ import { MessageAcceptance } from '../../src/types.js' import { GossipsubD } from '../../src/constants.js' import { fastMsgIdFn } from '../utils/index.js' import type { Message } from '@libp2p/interface-pubsub' -import type { RPC } from '../../src/message/rpc.js' +import type { IRPC } from '../../src/message/rpc.js' import type { ConnectionManagerEvents } from '@libp2p/interface-connection-manager' import pWaitFor from 'p-wait-for' import { Components } from '@libp2p/components' @@ -1182,7 +1182,7 @@ describe('go-libp2p-pubsub gossipsub tests', function () { psub.mesh.set(test1, new Set([otherId])) psub.mesh.set(test2, new Set()) - const rpc: RPC = { + const rpc: IRPC = { subscriptions: [], messages: [] } diff --git a/test/message-cache.spec.ts b/test/message-cache.spec.ts index 1dff6fe9..b8f1ebad 100644 --- a/test/message-cache.spec.ts +++ b/test/message-cache.spec.ts @@ -16,7 +16,7 @@ const toMessageId = (msgId: Uint8Array): MessageId => { describe('Testing Message Cache Operations', () => { const messageCache = new MessageCache(3, 5, messageIdToString) - const testMessages: RPC.Message[] = [] + const testMessages: RPC.IMessage[] = [] const topic = 'test' const getGossipIDs = (mcache: MessageCache, topic: string): Uint8Array[] => { const gossipIDsByTopic = mcache.getGossipIDs(new Set([topic])) @@ -24,7 +24,7 @@ describe('Testing Message Cache Operations', () => { } before(async () => { - const makeTestMessage = (n: number): RPC.Message => { + const makeTestMessage = (n: number): RPC.IMessage => { return { from: new Uint8Array(0), data: uint8ArrayFromString(n.toString()), diff --git a/test/utils/index.ts b/test/utils/index.ts index e00079f4..0e03e4e6 100644 --- a/test/utils/index.ts +++ b/test/utils/index.ts @@ -15,7 +15,7 @@ export const createPeerId = async (): Promise => { let seq = 0n const defaultPeer = uint8ArrayFromString('12D3KooWBsYhazxNL7aeisdwttzc6DejNaM48889t5ifiS6tTrBf', 'base58btc') -export function makeTestMessage(i: number, topic: TopicStr, from?: PeerId): RPC.Message { +export function makeTestMessage(i: number, topic: TopicStr, from?: PeerId): RPC.IMessage { return { seqno: uint8ArrayFromString((seq++).toString(16).padStart(16, '0'), 'base16'), data: Uint8Array.from([i]), diff --git a/test/utils/msgId.ts b/test/utils/msgId.ts index 1a5f463d..b3d445b0 100644 --- a/test/utils/msgId.ts +++ b/test/utils/msgId.ts @@ -3,7 +3,7 @@ import type { RPC } from '../../src/message/rpc.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { messageIdToString } from '../../src/utils/messageIdToString.js' -export const getMsgId = (msg: RPC.Message): Uint8Array => { +export const getMsgId = (msg: RPC.IMessage): Uint8Array => { const from = msg.from != null ? msg.from : new Uint8Array(0) const seqno = msg.seqno instanceof Uint8Array ? msg.seqno : uint8ArrayFromString(msg.seqno ?? '') const result = new Uint8Array(from.length + seqno.length) @@ -12,9 +12,9 @@ export const getMsgId = (msg: RPC.Message): Uint8Array => { return result } -export const getMsgIdStr = (msg: RPC.Message): string => messageIdToString(getMsgId(msg)) +export const getMsgIdStr = (msg: RPC.IMessage): string => messageIdToString(getMsgId(msg)) -export const fastMsgIdFn = (msg: RPC.Message): string => +export const fastMsgIdFn = (msg: RPC.IMessage): string => // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error @chainsafe/as-sha256 types are wrong msg.data != null ? messageIdToString(SHA256.default.digest(msg.data)) : '0' From 52f833dcad9001a62a0e623129363b10fb48418d Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 1 Aug 2022 14:43:02 +0700 Subject: [PATCH 2/4] feat: reexport RPC from commonjs --- src/message/rpc.cjs | 1878 ++++++++++++++++++++++++++++++++++++++++++ src/message/rpc.js | 1879 +------------------------------------------ tsconfig.json | 1 + 3 files changed, 1881 insertions(+), 1877 deletions(-) create mode 100644 src/message/rpc.cjs diff --git a/src/message/rpc.cjs b/src/message/rpc.cjs new file mode 100644 index 00000000..4f5f4ce6 --- /dev/null +++ b/src/message/rpc.cjs @@ -0,0 +1,1878 @@ +// @ts-nocheck +/*eslint-disable*/ +(function(global, factory) { /* global define, require, module */ + + /* AMD */ if (typeof define === 'function' && define.amd) + define(["protobufjs/minimal"], factory); + + /* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports) + module.exports = factory(require("protobufjs/minimal")); + +})(this, function($protobuf) { + "use strict"; + + // Common aliases + var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + + // Exported root namespace + var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + + $root.RPC = (function() { + + /** + * Properties of a RPC. + * @exports IRPC + * @interface IRPC + * @property {Array.|null} [subscriptions] RPC subscriptions + * @property {Array.|null} [messages] RPC messages + * @property {RPC.IControlMessage|null} [control] RPC control + */ + + /** + * Constructs a new RPC. + * @exports RPC + * @classdesc Represents a RPC. + * @implements IRPC + * @constructor + * @param {IRPC=} [p] Properties to set + */ + function RPC(p) { + this.subscriptions = []; + this.messages = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * RPC subscriptions. + * @member {Array.} subscriptions + * @memberof RPC + * @instance + */ + RPC.prototype.subscriptions = $util.emptyArray; + + /** + * RPC messages. + * @member {Array.} messages + * @memberof RPC + * @instance + */ + RPC.prototype.messages = $util.emptyArray; + + /** + * RPC control. + * @member {RPC.IControlMessage|null|undefined} control + * @memberof RPC + * @instance + */ + RPC.prototype.control = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * RPC _control. + * @member {"control"|undefined} _control + * @memberof RPC + * @instance + */ + Object.defineProperty(RPC.prototype, "_control", { + get: $util.oneOfGetter($oneOfFields = ["control"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified RPC message. Does not implicitly {@link RPC.verify|verify} messages. + * @function encode + * @memberof RPC + * @static + * @param {IRPC} m RPC message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + RPC.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.subscriptions != null && m.subscriptions.length) { + for (var i = 0; i < m.subscriptions.length; ++i) + $root.RPC.SubOpts.encode(m.subscriptions[i], w.uint32(10).fork()).ldelim(); + } + if (m.messages != null && m.messages.length) { + for (var i = 0; i < m.messages.length; ++i) + $root.RPC.Message.encode(m.messages[i], w.uint32(18).fork()).ldelim(); + } + if (m.control != null && Object.hasOwnProperty.call(m, "control")) + $root.RPC.ControlMessage.encode(m.control, w.uint32(26).fork()).ldelim(); + return w; + }; + + /** + * Decodes a RPC message from the specified reader or buffer. + * @function decode + * @memberof RPC + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC} RPC + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + RPC.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.subscriptions && m.subscriptions.length)) + m.subscriptions = []; + m.subscriptions.push($root.RPC.SubOpts.decode(r, r.uint32())); + break; + case 2: + if (!(m.messages && m.messages.length)) + m.messages = []; + m.messages.push($root.RPC.Message.decode(r, r.uint32())); + break; + case 3: + m.control = $root.RPC.ControlMessage.decode(r, r.uint32()); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a RPC message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC + * @static + * @param {Object.} d Plain object + * @returns {RPC} RPC + */ + RPC.fromObject = function fromObject(d) { + if (d instanceof $root.RPC) + return d; + var m = new $root.RPC(); + if (d.subscriptions) { + if (!Array.isArray(d.subscriptions)) + throw TypeError(".RPC.subscriptions: array expected"); + m.subscriptions = []; + for (var i = 0; i < d.subscriptions.length; ++i) { + if (typeof d.subscriptions[i] !== "object") + throw TypeError(".RPC.subscriptions: object expected"); + m.subscriptions[i] = $root.RPC.SubOpts.fromObject(d.subscriptions[i]); + } + } + if (d.messages) { + if (!Array.isArray(d.messages)) + throw TypeError(".RPC.messages: array expected"); + m.messages = []; + for (var i = 0; i < d.messages.length; ++i) { + if (typeof d.messages[i] !== "object") + throw TypeError(".RPC.messages: object expected"); + m.messages[i] = $root.RPC.Message.fromObject(d.messages[i]); + } + } + if (d.control != null) { + if (typeof d.control !== "object") + throw TypeError(".RPC.control: object expected"); + m.control = $root.RPC.ControlMessage.fromObject(d.control); + } + return m; + }; + + /** + * Creates a plain object from a RPC message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC + * @static + * @param {RPC} m RPC + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + RPC.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.subscriptions = []; + d.messages = []; + } + if (m.subscriptions && m.subscriptions.length) { + d.subscriptions = []; + for (var j = 0; j < m.subscriptions.length; ++j) { + d.subscriptions[j] = $root.RPC.SubOpts.toObject(m.subscriptions[j], o); + } + } + if (m.messages && m.messages.length) { + d.messages = []; + for (var j = 0; j < m.messages.length; ++j) { + d.messages[j] = $root.RPC.Message.toObject(m.messages[j], o); + } + } + if (m.control != null && m.hasOwnProperty("control")) { + d.control = $root.RPC.ControlMessage.toObject(m.control, o); + if (o.oneofs) + d._control = "control"; + } + return d; + }; + + /** + * Converts this RPC to JSON. + * @function toJSON + * @memberof RPC + * @instance + * @returns {Object.} JSON object + */ + RPC.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + RPC.SubOpts = (function() { + + /** + * Properties of a SubOpts. + * @memberof RPC + * @interface ISubOpts + * @property {boolean|null} [subscribe] SubOpts subscribe + * @property {string|null} [topic] SubOpts topic + */ + + /** + * Constructs a new SubOpts. + * @memberof RPC + * @classdesc Represents a SubOpts. + * @implements ISubOpts + * @constructor + * @param {RPC.ISubOpts=} [p] Properties to set + */ + function SubOpts(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * SubOpts subscribe. + * @member {boolean|null|undefined} subscribe + * @memberof RPC.SubOpts + * @instance + */ + SubOpts.prototype.subscribe = null; + + /** + * SubOpts topic. + * @member {string|null|undefined} topic + * @memberof RPC.SubOpts + * @instance + */ + SubOpts.prototype.topic = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * SubOpts _subscribe. + * @member {"subscribe"|undefined} _subscribe + * @memberof RPC.SubOpts + * @instance + */ + Object.defineProperty(SubOpts.prototype, "_subscribe", { + get: $util.oneOfGetter($oneOfFields = ["subscribe"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * SubOpts _topic. + * @member {"topic"|undefined} _topic + * @memberof RPC.SubOpts + * @instance + */ + Object.defineProperty(SubOpts.prototype, "_topic", { + get: $util.oneOfGetter($oneOfFields = ["topic"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified SubOpts message. Does not implicitly {@link RPC.SubOpts.verify|verify} messages. + * @function encode + * @memberof RPC.SubOpts + * @static + * @param {RPC.ISubOpts} m SubOpts message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SubOpts.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.subscribe != null && Object.hasOwnProperty.call(m, "subscribe")) + w.uint32(8).bool(m.subscribe); + if (m.topic != null && Object.hasOwnProperty.call(m, "topic")) + w.uint32(18).string(m.topic); + return w; + }; + + /** + * Decodes a SubOpts message from the specified reader or buffer. + * @function decode + * @memberof RPC.SubOpts + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.SubOpts} SubOpts + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SubOpts.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.SubOpts(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.subscribe = r.bool(); + break; + case 2: + m.topic = r.string(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a SubOpts message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.SubOpts + * @static + * @param {Object.} d Plain object + * @returns {RPC.SubOpts} SubOpts + */ + SubOpts.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.SubOpts) + return d; + var m = new $root.RPC.SubOpts(); + if (d.subscribe != null) { + m.subscribe = Boolean(d.subscribe); + } + if (d.topic != null) { + m.topic = String(d.topic); + } + return m; + }; + + /** + * Creates a plain object from a SubOpts message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.SubOpts + * @static + * @param {RPC.SubOpts} m SubOpts + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + SubOpts.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (m.subscribe != null && m.hasOwnProperty("subscribe")) { + d.subscribe = m.subscribe; + if (o.oneofs) + d._subscribe = "subscribe"; + } + if (m.topic != null && m.hasOwnProperty("topic")) { + d.topic = m.topic; + if (o.oneofs) + d._topic = "topic"; + } + return d; + }; + + /** + * Converts this SubOpts to JSON. + * @function toJSON + * @memberof RPC.SubOpts + * @instance + * @returns {Object.} JSON object + */ + SubOpts.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return SubOpts; + })(); + + RPC.Message = (function() { + + /** + * Properties of a Message. + * @memberof RPC + * @interface IMessage + * @property {Uint8Array|null} [from] Message from + * @property {Uint8Array|null} [data] Message data + * @property {Uint8Array|null} [seqno] Message seqno + * @property {string} topic Message topic + * @property {Uint8Array|null} [signature] Message signature + * @property {Uint8Array|null} [key] Message key + */ + + /** + * Constructs a new Message. + * @memberof RPC + * @classdesc Represents a Message. + * @implements IMessage + * @constructor + * @param {RPC.IMessage=} [p] Properties to set + */ + function Message(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * Message from. + * @member {Uint8Array|null|undefined} from + * @memberof RPC.Message + * @instance + */ + Message.prototype.from = null; + + /** + * Message data. + * @member {Uint8Array|null|undefined} data + * @memberof RPC.Message + * @instance + */ + Message.prototype.data = null; + + /** + * Message seqno. + * @member {Uint8Array|null|undefined} seqno + * @memberof RPC.Message + * @instance + */ + Message.prototype.seqno = null; + + /** + * Message topic. + * @member {string} topic + * @memberof RPC.Message + * @instance + */ + Message.prototype.topic = ""; + + /** + * Message signature. + * @member {Uint8Array|null|undefined} signature + * @memberof RPC.Message + * @instance + */ + Message.prototype.signature = null; + + /** + * Message key. + * @member {Uint8Array|null|undefined} key + * @memberof RPC.Message + * @instance + */ + Message.prototype.key = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * Message _from. + * @member {"from"|undefined} _from + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_from", { + get: $util.oneOfGetter($oneOfFields = ["from"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Message _data. + * @member {"data"|undefined} _data + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_data", { + get: $util.oneOfGetter($oneOfFields = ["data"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Message _seqno. + * @member {"seqno"|undefined} _seqno + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_seqno", { + get: $util.oneOfGetter($oneOfFields = ["seqno"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Message _signature. + * @member {"signature"|undefined} _signature + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_signature", { + get: $util.oneOfGetter($oneOfFields = ["signature"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Message _key. + * @member {"key"|undefined} _key + * @memberof RPC.Message + * @instance + */ + Object.defineProperty(Message.prototype, "_key", { + get: $util.oneOfGetter($oneOfFields = ["key"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified Message message. Does not implicitly {@link RPC.Message.verify|verify} messages. + * @function encode + * @memberof RPC.Message + * @static + * @param {RPC.IMessage} m Message message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Message.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.from != null && Object.hasOwnProperty.call(m, "from")) + w.uint32(10).bytes(m.from); + if (m.data != null && Object.hasOwnProperty.call(m, "data")) + w.uint32(18).bytes(m.data); + if (m.seqno != null && Object.hasOwnProperty.call(m, "seqno")) + w.uint32(26).bytes(m.seqno); + w.uint32(34).string(m.topic); + if (m.signature != null && Object.hasOwnProperty.call(m, "signature")) + w.uint32(42).bytes(m.signature); + if (m.key != null && Object.hasOwnProperty.call(m, "key")) + w.uint32(50).bytes(m.key); + return w; + }; + + /** + * Decodes a Message message from the specified reader or buffer. + * @function decode + * @memberof RPC.Message + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.Message} Message + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Message.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.Message(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.from = r.bytes(); + break; + case 2: + m.data = r.bytes(); + break; + case 3: + m.seqno = r.bytes(); + break; + case 4: + m.topic = r.string(); + break; + case 5: + m.signature = r.bytes(); + break; + case 6: + m.key = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + if (!m.hasOwnProperty("topic")) + throw $util.ProtocolError("missing required 'topic'", { instance: m }); + return m; + }; + + /** + * Creates a Message message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.Message + * @static + * @param {Object.} d Plain object + * @returns {RPC.Message} Message + */ + Message.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.Message) + return d; + var m = new $root.RPC.Message(); + if (d.from != null) { + if (typeof d.from === "string") + $util.base64.decode(d.from, m.from = $util.newBuffer($util.base64.length(d.from)), 0); + else if (d.from.length) + m.from = d.from; + } + if (d.data != null) { + if (typeof d.data === "string") + $util.base64.decode(d.data, m.data = $util.newBuffer($util.base64.length(d.data)), 0); + else if (d.data.length) + m.data = d.data; + } + if (d.seqno != null) { + if (typeof d.seqno === "string") + $util.base64.decode(d.seqno, m.seqno = $util.newBuffer($util.base64.length(d.seqno)), 0); + else if (d.seqno.length) + m.seqno = d.seqno; + } + if (d.topic != null) { + m.topic = String(d.topic); + } + if (d.signature != null) { + if (typeof d.signature === "string") + $util.base64.decode(d.signature, m.signature = $util.newBuffer($util.base64.length(d.signature)), 0); + else if (d.signature.length) + m.signature = d.signature; + } + if (d.key != null) { + if (typeof d.key === "string") + $util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0); + else if (d.key.length) + m.key = d.key; + } + return m; + }; + + /** + * Creates a plain object from a Message message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.Message + * @static + * @param {RPC.Message} m Message + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + Message.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.defaults) { + d.topic = ""; + } + if (m.from != null && m.hasOwnProperty("from")) { + d.from = o.bytes === String ? $util.base64.encode(m.from, 0, m.from.length) : o.bytes === Array ? Array.prototype.slice.call(m.from) : m.from; + if (o.oneofs) + d._from = "from"; + } + if (m.data != null && m.hasOwnProperty("data")) { + d.data = o.bytes === String ? $util.base64.encode(m.data, 0, m.data.length) : o.bytes === Array ? Array.prototype.slice.call(m.data) : m.data; + if (o.oneofs) + d._data = "data"; + } + if (m.seqno != null && m.hasOwnProperty("seqno")) { + d.seqno = o.bytes === String ? $util.base64.encode(m.seqno, 0, m.seqno.length) : o.bytes === Array ? Array.prototype.slice.call(m.seqno) : m.seqno; + if (o.oneofs) + d._seqno = "seqno"; + } + if (m.topic != null && m.hasOwnProperty("topic")) { + d.topic = m.topic; + } + if (m.signature != null && m.hasOwnProperty("signature")) { + d.signature = o.bytes === String ? $util.base64.encode(m.signature, 0, m.signature.length) : o.bytes === Array ? Array.prototype.slice.call(m.signature) : m.signature; + if (o.oneofs) + d._signature = "signature"; + } + if (m.key != null && m.hasOwnProperty("key")) { + d.key = o.bytes === String ? $util.base64.encode(m.key, 0, m.key.length) : o.bytes === Array ? Array.prototype.slice.call(m.key) : m.key; + if (o.oneofs) + d._key = "key"; + } + return d; + }; + + /** + * Converts this Message to JSON. + * @function toJSON + * @memberof RPC.Message + * @instance + * @returns {Object.} JSON object + */ + Message.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Message; + })(); + + RPC.ControlMessage = (function() { + + /** + * Properties of a ControlMessage. + * @memberof RPC + * @interface IControlMessage + * @property {Array.|null} [ihave] ControlMessage ihave + * @property {Array.|null} [iwant] ControlMessage iwant + * @property {Array.|null} [graft] ControlMessage graft + * @property {Array.|null} [prune] ControlMessage prune + */ + + /** + * Constructs a new ControlMessage. + * @memberof RPC + * @classdesc Represents a ControlMessage. + * @implements IControlMessage + * @constructor + * @param {RPC.IControlMessage=} [p] Properties to set + */ + function ControlMessage(p) { + this.ihave = []; + this.iwant = []; + this.graft = []; + this.prune = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlMessage ihave. + * @member {Array.} ihave + * @memberof RPC.ControlMessage + * @instance + */ + ControlMessage.prototype.ihave = $util.emptyArray; + + /** + * ControlMessage iwant. + * @member {Array.} iwant + * @memberof RPC.ControlMessage + * @instance + */ + ControlMessage.prototype.iwant = $util.emptyArray; + + /** + * ControlMessage graft. + * @member {Array.} graft + * @memberof RPC.ControlMessage + * @instance + */ + ControlMessage.prototype.graft = $util.emptyArray; + + /** + * ControlMessage prune. + * @member {Array.} prune + * @memberof RPC.ControlMessage + * @instance + */ + ControlMessage.prototype.prune = $util.emptyArray; + + /** + * Encodes the specified ControlMessage message. Does not implicitly {@link RPC.ControlMessage.verify|verify} messages. + * @function encode + * @memberof RPC.ControlMessage + * @static + * @param {RPC.IControlMessage} m ControlMessage message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlMessage.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.ihave != null && m.ihave.length) { + for (var i = 0; i < m.ihave.length; ++i) + $root.RPC.ControlIHave.encode(m.ihave[i], w.uint32(10).fork()).ldelim(); + } + if (m.iwant != null && m.iwant.length) { + for (var i = 0; i < m.iwant.length; ++i) + $root.RPC.ControlIWant.encode(m.iwant[i], w.uint32(18).fork()).ldelim(); + } + if (m.graft != null && m.graft.length) { + for (var i = 0; i < m.graft.length; ++i) + $root.RPC.ControlGraft.encode(m.graft[i], w.uint32(26).fork()).ldelim(); + } + if (m.prune != null && m.prune.length) { + for (var i = 0; i < m.prune.length; ++i) + $root.RPC.ControlPrune.encode(m.prune[i], w.uint32(34).fork()).ldelim(); + } + return w; + }; + + /** + * Decodes a ControlMessage message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlMessage + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlMessage} ControlMessage + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlMessage.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlMessage(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.ihave && m.ihave.length)) + m.ihave = []; + m.ihave.push($root.RPC.ControlIHave.decode(r, r.uint32())); + break; + case 2: + if (!(m.iwant && m.iwant.length)) + m.iwant = []; + m.iwant.push($root.RPC.ControlIWant.decode(r, r.uint32())); + break; + case 3: + if (!(m.graft && m.graft.length)) + m.graft = []; + m.graft.push($root.RPC.ControlGraft.decode(r, r.uint32())); + break; + case 4: + if (!(m.prune && m.prune.length)) + m.prune = []; + m.prune.push($root.RPC.ControlPrune.decode(r, r.uint32())); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlMessage message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlMessage + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlMessage} ControlMessage + */ + ControlMessage.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlMessage) + return d; + var m = new $root.RPC.ControlMessage(); + if (d.ihave) { + if (!Array.isArray(d.ihave)) + throw TypeError(".RPC.ControlMessage.ihave: array expected"); + m.ihave = []; + for (var i = 0; i < d.ihave.length; ++i) { + if (typeof d.ihave[i] !== "object") + throw TypeError(".RPC.ControlMessage.ihave: object expected"); + m.ihave[i] = $root.RPC.ControlIHave.fromObject(d.ihave[i]); + } + } + if (d.iwant) { + if (!Array.isArray(d.iwant)) + throw TypeError(".RPC.ControlMessage.iwant: array expected"); + m.iwant = []; + for (var i = 0; i < d.iwant.length; ++i) { + if (typeof d.iwant[i] !== "object") + throw TypeError(".RPC.ControlMessage.iwant: object expected"); + m.iwant[i] = $root.RPC.ControlIWant.fromObject(d.iwant[i]); + } + } + if (d.graft) { + if (!Array.isArray(d.graft)) + throw TypeError(".RPC.ControlMessage.graft: array expected"); + m.graft = []; + for (var i = 0; i < d.graft.length; ++i) { + if (typeof d.graft[i] !== "object") + throw TypeError(".RPC.ControlMessage.graft: object expected"); + m.graft[i] = $root.RPC.ControlGraft.fromObject(d.graft[i]); + } + } + if (d.prune) { + if (!Array.isArray(d.prune)) + throw TypeError(".RPC.ControlMessage.prune: array expected"); + m.prune = []; + for (var i = 0; i < d.prune.length; ++i) { + if (typeof d.prune[i] !== "object") + throw TypeError(".RPC.ControlMessage.prune: object expected"); + m.prune[i] = $root.RPC.ControlPrune.fromObject(d.prune[i]); + } + } + return m; + }; + + /** + * Creates a plain object from a ControlMessage message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlMessage + * @static + * @param {RPC.ControlMessage} m ControlMessage + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlMessage.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.ihave = []; + d.iwant = []; + d.graft = []; + d.prune = []; + } + if (m.ihave && m.ihave.length) { + d.ihave = []; + for (var j = 0; j < m.ihave.length; ++j) { + d.ihave[j] = $root.RPC.ControlIHave.toObject(m.ihave[j], o); + } + } + if (m.iwant && m.iwant.length) { + d.iwant = []; + for (var j = 0; j < m.iwant.length; ++j) { + d.iwant[j] = $root.RPC.ControlIWant.toObject(m.iwant[j], o); + } + } + if (m.graft && m.graft.length) { + d.graft = []; + for (var j = 0; j < m.graft.length; ++j) { + d.graft[j] = $root.RPC.ControlGraft.toObject(m.graft[j], o); + } + } + if (m.prune && m.prune.length) { + d.prune = []; + for (var j = 0; j < m.prune.length; ++j) { + d.prune[j] = $root.RPC.ControlPrune.toObject(m.prune[j], o); + } + } + return d; + }; + + /** + * Converts this ControlMessage to JSON. + * @function toJSON + * @memberof RPC.ControlMessage + * @instance + * @returns {Object.} JSON object + */ + ControlMessage.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlMessage; + })(); + + RPC.ControlIHave = (function() { + + /** + * Properties of a ControlIHave. + * @memberof RPC + * @interface IControlIHave + * @property {string|null} [topicID] ControlIHave topicID + * @property {Array.|null} [messageIDs] ControlIHave messageIDs + */ + + /** + * Constructs a new ControlIHave. + * @memberof RPC + * @classdesc Represents a ControlIHave. + * @implements IControlIHave + * @constructor + * @param {RPC.IControlIHave=} [p] Properties to set + */ + function ControlIHave(p) { + this.messageIDs = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlIHave topicID. + * @member {string|null|undefined} topicID + * @memberof RPC.ControlIHave + * @instance + */ + ControlIHave.prototype.topicID = null; + + /** + * ControlIHave messageIDs. + * @member {Array.} messageIDs + * @memberof RPC.ControlIHave + * @instance + */ + ControlIHave.prototype.messageIDs = $util.emptyArray; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * ControlIHave _topicID. + * @member {"topicID"|undefined} _topicID + * @memberof RPC.ControlIHave + * @instance + */ + Object.defineProperty(ControlIHave.prototype, "_topicID", { + get: $util.oneOfGetter($oneOfFields = ["topicID"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified ControlIHave message. Does not implicitly {@link RPC.ControlIHave.verify|verify} messages. + * @function encode + * @memberof RPC.ControlIHave + * @static + * @param {RPC.IControlIHave} m ControlIHave message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlIHave.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) + w.uint32(10).string(m.topicID); + if (m.messageIDs != null && m.messageIDs.length) { + for (var i = 0; i < m.messageIDs.length; ++i) + w.uint32(18).bytes(m.messageIDs[i]); + } + return w; + }; + + /** + * Decodes a ControlIHave message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlIHave + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlIHave} ControlIHave + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlIHave.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlIHave(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.topicID = r.string(); + break; + case 2: + if (!(m.messageIDs && m.messageIDs.length)) + m.messageIDs = []; + m.messageIDs.push(r.bytes()); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlIHave message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlIHave + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlIHave} ControlIHave + */ + ControlIHave.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlIHave) + return d; + var m = new $root.RPC.ControlIHave(); + if (d.topicID != null) { + m.topicID = String(d.topicID); + } + if (d.messageIDs) { + if (!Array.isArray(d.messageIDs)) + throw TypeError(".RPC.ControlIHave.messageIDs: array expected"); + m.messageIDs = []; + for (var i = 0; i < d.messageIDs.length; ++i) { + if (typeof d.messageIDs[i] === "string") + $util.base64.decode(d.messageIDs[i], m.messageIDs[i] = $util.newBuffer($util.base64.length(d.messageIDs[i])), 0); + else if (d.messageIDs[i].length) + m.messageIDs[i] = d.messageIDs[i]; + } + } + return m; + }; + + /** + * Creates a plain object from a ControlIHave message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlIHave + * @static + * @param {RPC.ControlIHave} m ControlIHave + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlIHave.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.messageIDs = []; + } + if (m.topicID != null && m.hasOwnProperty("topicID")) { + d.topicID = m.topicID; + if (o.oneofs) + d._topicID = "topicID"; + } + if (m.messageIDs && m.messageIDs.length) { + d.messageIDs = []; + for (var j = 0; j < m.messageIDs.length; ++j) { + d.messageIDs[j] = o.bytes === String ? $util.base64.encode(m.messageIDs[j], 0, m.messageIDs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.messageIDs[j]) : m.messageIDs[j]; + } + } + return d; + }; + + /** + * Converts this ControlIHave to JSON. + * @function toJSON + * @memberof RPC.ControlIHave + * @instance + * @returns {Object.} JSON object + */ + ControlIHave.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlIHave; + })(); + + RPC.ControlIWant = (function() { + + /** + * Properties of a ControlIWant. + * @memberof RPC + * @interface IControlIWant + * @property {Array.|null} [messageIDs] ControlIWant messageIDs + */ + + /** + * Constructs a new ControlIWant. + * @memberof RPC + * @classdesc Represents a ControlIWant. + * @implements IControlIWant + * @constructor + * @param {RPC.IControlIWant=} [p] Properties to set + */ + function ControlIWant(p) { + this.messageIDs = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlIWant messageIDs. + * @member {Array.} messageIDs + * @memberof RPC.ControlIWant + * @instance + */ + ControlIWant.prototype.messageIDs = $util.emptyArray; + + /** + * Encodes the specified ControlIWant message. Does not implicitly {@link RPC.ControlIWant.verify|verify} messages. + * @function encode + * @memberof RPC.ControlIWant + * @static + * @param {RPC.IControlIWant} m ControlIWant message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlIWant.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.messageIDs != null && m.messageIDs.length) { + for (var i = 0; i < m.messageIDs.length; ++i) + w.uint32(10).bytes(m.messageIDs[i]); + } + return w; + }; + + /** + * Decodes a ControlIWant message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlIWant + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlIWant} ControlIWant + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlIWant.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlIWant(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + if (!(m.messageIDs && m.messageIDs.length)) + m.messageIDs = []; + m.messageIDs.push(r.bytes()); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlIWant message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlIWant + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlIWant} ControlIWant + */ + ControlIWant.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlIWant) + return d; + var m = new $root.RPC.ControlIWant(); + if (d.messageIDs) { + if (!Array.isArray(d.messageIDs)) + throw TypeError(".RPC.ControlIWant.messageIDs: array expected"); + m.messageIDs = []; + for (var i = 0; i < d.messageIDs.length; ++i) { + if (typeof d.messageIDs[i] === "string") + $util.base64.decode(d.messageIDs[i], m.messageIDs[i] = $util.newBuffer($util.base64.length(d.messageIDs[i])), 0); + else if (d.messageIDs[i].length) + m.messageIDs[i] = d.messageIDs[i]; + } + } + return m; + }; + + /** + * Creates a plain object from a ControlIWant message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlIWant + * @static + * @param {RPC.ControlIWant} m ControlIWant + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlIWant.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.messageIDs = []; + } + if (m.messageIDs && m.messageIDs.length) { + d.messageIDs = []; + for (var j = 0; j < m.messageIDs.length; ++j) { + d.messageIDs[j] = o.bytes === String ? $util.base64.encode(m.messageIDs[j], 0, m.messageIDs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.messageIDs[j]) : m.messageIDs[j]; + } + } + return d; + }; + + /** + * Converts this ControlIWant to JSON. + * @function toJSON + * @memberof RPC.ControlIWant + * @instance + * @returns {Object.} JSON object + */ + ControlIWant.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlIWant; + })(); + + RPC.ControlGraft = (function() { + + /** + * Properties of a ControlGraft. + * @memberof RPC + * @interface IControlGraft + * @property {string|null} [topicID] ControlGraft topicID + */ + + /** + * Constructs a new ControlGraft. + * @memberof RPC + * @classdesc Represents a ControlGraft. + * @implements IControlGraft + * @constructor + * @param {RPC.IControlGraft=} [p] Properties to set + */ + function ControlGraft(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlGraft topicID. + * @member {string|null|undefined} topicID + * @memberof RPC.ControlGraft + * @instance + */ + ControlGraft.prototype.topicID = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * ControlGraft _topicID. + * @member {"topicID"|undefined} _topicID + * @memberof RPC.ControlGraft + * @instance + */ + Object.defineProperty(ControlGraft.prototype, "_topicID", { + get: $util.oneOfGetter($oneOfFields = ["topicID"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified ControlGraft message. Does not implicitly {@link RPC.ControlGraft.verify|verify} messages. + * @function encode + * @memberof RPC.ControlGraft + * @static + * @param {RPC.IControlGraft} m ControlGraft message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlGraft.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) + w.uint32(10).string(m.topicID); + return w; + }; + + /** + * Decodes a ControlGraft message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlGraft + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlGraft} ControlGraft + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlGraft.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlGraft(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.topicID = r.string(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlGraft message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlGraft + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlGraft} ControlGraft + */ + ControlGraft.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlGraft) + return d; + var m = new $root.RPC.ControlGraft(); + if (d.topicID != null) { + m.topicID = String(d.topicID); + } + return m; + }; + + /** + * Creates a plain object from a ControlGraft message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlGraft + * @static + * @param {RPC.ControlGraft} m ControlGraft + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlGraft.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (m.topicID != null && m.hasOwnProperty("topicID")) { + d.topicID = m.topicID; + if (o.oneofs) + d._topicID = "topicID"; + } + return d; + }; + + /** + * Converts this ControlGraft to JSON. + * @function toJSON + * @memberof RPC.ControlGraft + * @instance + * @returns {Object.} JSON object + */ + ControlGraft.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlGraft; + })(); + + RPC.ControlPrune = (function() { + + /** + * Properties of a ControlPrune. + * @memberof RPC + * @interface IControlPrune + * @property {string|null} [topicID] ControlPrune topicID + * @property {Array.|null} [peers] ControlPrune peers + * @property {number|null} [backoff] ControlPrune backoff + */ + + /** + * Constructs a new ControlPrune. + * @memberof RPC + * @classdesc Represents a ControlPrune. + * @implements IControlPrune + * @constructor + * @param {RPC.IControlPrune=} [p] Properties to set + */ + function ControlPrune(p) { + this.peers = []; + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * ControlPrune topicID. + * @member {string|null|undefined} topicID + * @memberof RPC.ControlPrune + * @instance + */ + ControlPrune.prototype.topicID = null; + + /** + * ControlPrune peers. + * @member {Array.} peers + * @memberof RPC.ControlPrune + * @instance + */ + ControlPrune.prototype.peers = $util.emptyArray; + + /** + * ControlPrune backoff. + * @member {number|null|undefined} backoff + * @memberof RPC.ControlPrune + * @instance + */ + ControlPrune.prototype.backoff = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * ControlPrune _topicID. + * @member {"topicID"|undefined} _topicID + * @memberof RPC.ControlPrune + * @instance + */ + Object.defineProperty(ControlPrune.prototype, "_topicID", { + get: $util.oneOfGetter($oneOfFields = ["topicID"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * ControlPrune _backoff. + * @member {"backoff"|undefined} _backoff + * @memberof RPC.ControlPrune + * @instance + */ + Object.defineProperty(ControlPrune.prototype, "_backoff", { + get: $util.oneOfGetter($oneOfFields = ["backoff"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified ControlPrune message. Does not implicitly {@link RPC.ControlPrune.verify|verify} messages. + * @function encode + * @memberof RPC.ControlPrune + * @static + * @param {RPC.IControlPrune} m ControlPrune message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ControlPrune.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) + w.uint32(10).string(m.topicID); + if (m.peers != null && m.peers.length) { + for (var i = 0; i < m.peers.length; ++i) + $root.RPC.PeerInfo.encode(m.peers[i], w.uint32(18).fork()).ldelim(); + } + if (m.backoff != null && Object.hasOwnProperty.call(m, "backoff")) + w.uint32(24).uint64(m.backoff); + return w; + }; + + /** + * Decodes a ControlPrune message from the specified reader or buffer. + * @function decode + * @memberof RPC.ControlPrune + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.ControlPrune} ControlPrune + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ControlPrune.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlPrune(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.topicID = r.string(); + break; + case 2: + if (!(m.peers && m.peers.length)) + m.peers = []; + m.peers.push($root.RPC.PeerInfo.decode(r, r.uint32())); + break; + case 3: + m.backoff = r.uint64(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a ControlPrune message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.ControlPrune + * @static + * @param {Object.} d Plain object + * @returns {RPC.ControlPrune} ControlPrune + */ + ControlPrune.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.ControlPrune) + return d; + var m = new $root.RPC.ControlPrune(); + if (d.topicID != null) { + m.topicID = String(d.topicID); + } + if (d.peers) { + if (!Array.isArray(d.peers)) + throw TypeError(".RPC.ControlPrune.peers: array expected"); + m.peers = []; + for (var i = 0; i < d.peers.length; ++i) { + if (typeof d.peers[i] !== "object") + throw TypeError(".RPC.ControlPrune.peers: object expected"); + m.peers[i] = $root.RPC.PeerInfo.fromObject(d.peers[i]); + } + } + if (d.backoff != null) { + if ($util.Long) + (m.backoff = $util.Long.fromValue(d.backoff)).unsigned = true; + else if (typeof d.backoff === "string") + m.backoff = parseInt(d.backoff, 10); + else if (typeof d.backoff === "number") + m.backoff = d.backoff; + else if (typeof d.backoff === "object") + m.backoff = new $util.LongBits(d.backoff.low >>> 0, d.backoff.high >>> 0).toNumber(true); + } + return m; + }; + + /** + * Creates a plain object from a ControlPrune message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.ControlPrune + * @static + * @param {RPC.ControlPrune} m ControlPrune + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + ControlPrune.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (o.arrays || o.defaults) { + d.peers = []; + } + if (m.topicID != null && m.hasOwnProperty("topicID")) { + d.topicID = m.topicID; + if (o.oneofs) + d._topicID = "topicID"; + } + if (m.peers && m.peers.length) { + d.peers = []; + for (var j = 0; j < m.peers.length; ++j) { + d.peers[j] = $root.RPC.PeerInfo.toObject(m.peers[j], o); + } + } + if (m.backoff != null && m.hasOwnProperty("backoff")) { + if (typeof m.backoff === "number") + d.backoff = o.longs === String ? String(m.backoff) : m.backoff; + else + d.backoff = o.longs === String ? $util.Long.prototype.toString.call(m.backoff) : o.longs === Number ? new $util.LongBits(m.backoff.low >>> 0, m.backoff.high >>> 0).toNumber(true) : m.backoff; + if (o.oneofs) + d._backoff = "backoff"; + } + return d; + }; + + /** + * Converts this ControlPrune to JSON. + * @function toJSON + * @memberof RPC.ControlPrune + * @instance + * @returns {Object.} JSON object + */ + ControlPrune.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ControlPrune; + })(); + + RPC.PeerInfo = (function() { + + /** + * Properties of a PeerInfo. + * @memberof RPC + * @interface IPeerInfo + * @property {Uint8Array|null} [peerID] PeerInfo peerID + * @property {Uint8Array|null} [signedPeerRecord] PeerInfo signedPeerRecord + */ + + /** + * Constructs a new PeerInfo. + * @memberof RPC + * @classdesc Represents a PeerInfo. + * @implements IPeerInfo + * @constructor + * @param {RPC.IPeerInfo=} [p] Properties to set + */ + function PeerInfo(p) { + if (p) + for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) + if (p[ks[i]] != null) + this[ks[i]] = p[ks[i]]; + } + + /** + * PeerInfo peerID. + * @member {Uint8Array|null|undefined} peerID + * @memberof RPC.PeerInfo + * @instance + */ + PeerInfo.prototype.peerID = null; + + /** + * PeerInfo signedPeerRecord. + * @member {Uint8Array|null|undefined} signedPeerRecord + * @memberof RPC.PeerInfo + * @instance + */ + PeerInfo.prototype.signedPeerRecord = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * PeerInfo _peerID. + * @member {"peerID"|undefined} _peerID + * @memberof RPC.PeerInfo + * @instance + */ + Object.defineProperty(PeerInfo.prototype, "_peerID", { + get: $util.oneOfGetter($oneOfFields = ["peerID"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * PeerInfo _signedPeerRecord. + * @member {"signedPeerRecord"|undefined} _signedPeerRecord + * @memberof RPC.PeerInfo + * @instance + */ + Object.defineProperty(PeerInfo.prototype, "_signedPeerRecord", { + get: $util.oneOfGetter($oneOfFields = ["signedPeerRecord"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Encodes the specified PeerInfo message. Does not implicitly {@link RPC.PeerInfo.verify|verify} messages. + * @function encode + * @memberof RPC.PeerInfo + * @static + * @param {RPC.IPeerInfo} m PeerInfo message or plain object to encode + * @param {$protobuf.Writer} [w] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + PeerInfo.encode = function encode(m, w) { + if (!w) + w = $Writer.create(); + if (m.peerID != null && Object.hasOwnProperty.call(m, "peerID")) + w.uint32(10).bytes(m.peerID); + if (m.signedPeerRecord != null && Object.hasOwnProperty.call(m, "signedPeerRecord")) + w.uint32(18).bytes(m.signedPeerRecord); + return w; + }; + + /** + * Decodes a PeerInfo message from the specified reader or buffer. + * @function decode + * @memberof RPC.PeerInfo + * @static + * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from + * @param {number} [l] Message length if known beforehand + * @returns {RPC.PeerInfo} PeerInfo + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + PeerInfo.decode = function decode(r, l) { + if (!(r instanceof $Reader)) + r = $Reader.create(r); + var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.PeerInfo(); + while (r.pos < c) { + var t = r.uint32(); + switch (t >>> 3) { + case 1: + m.peerID = r.bytes(); + break; + case 2: + m.signedPeerRecord = r.bytes(); + break; + default: + r.skipType(t & 7); + break; + } + } + return m; + }; + + /** + * Creates a PeerInfo message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof RPC.PeerInfo + * @static + * @param {Object.} d Plain object + * @returns {RPC.PeerInfo} PeerInfo + */ + PeerInfo.fromObject = function fromObject(d) { + if (d instanceof $root.RPC.PeerInfo) + return d; + var m = new $root.RPC.PeerInfo(); + if (d.peerID != null) { + if (typeof d.peerID === "string") + $util.base64.decode(d.peerID, m.peerID = $util.newBuffer($util.base64.length(d.peerID)), 0); + else if (d.peerID.length) + m.peerID = d.peerID; + } + if (d.signedPeerRecord != null) { + if (typeof d.signedPeerRecord === "string") + $util.base64.decode(d.signedPeerRecord, m.signedPeerRecord = $util.newBuffer($util.base64.length(d.signedPeerRecord)), 0); + else if (d.signedPeerRecord.length) + m.signedPeerRecord = d.signedPeerRecord; + } + return m; + }; + + /** + * Creates a plain object from a PeerInfo message. Also converts values to other types if specified. + * @function toObject + * @memberof RPC.PeerInfo + * @static + * @param {RPC.PeerInfo} m PeerInfo + * @param {$protobuf.IConversionOptions} [o] Conversion options + * @returns {Object.} Plain object + */ + PeerInfo.toObject = function toObject(m, o) { + if (!o) + o = {}; + var d = {}; + if (m.peerID != null && m.hasOwnProperty("peerID")) { + 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; + if (o.oneofs) + d._peerID = "peerID"; + } + if (m.signedPeerRecord != null && m.hasOwnProperty("signedPeerRecord")) { + d.signedPeerRecord = o.bytes === String ? $util.base64.encode(m.signedPeerRecord, 0, m.signedPeerRecord.length) : o.bytes === Array ? Array.prototype.slice.call(m.signedPeerRecord) : m.signedPeerRecord; + if (o.oneofs) + d._signedPeerRecord = "signedPeerRecord"; + } + return d; + }; + + /** + * Converts this PeerInfo to JSON. + * @function toJSON + * @memberof RPC.PeerInfo + * @instance + * @returns {Object.} JSON object + */ + PeerInfo.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return PeerInfo; + })(); + + return RPC; + })(); + + return $root; +}); diff --git a/src/message/rpc.js b/src/message/rpc.js index 4f5f4ce6..b569a782 100644 --- a/src/message/rpc.js +++ b/src/message/rpc.js @@ -1,1878 +1,3 @@ -// @ts-nocheck -/*eslint-disable*/ -(function(global, factory) { /* global define, require, module */ +import cjs from "./rpc.cjs" - /* AMD */ if (typeof define === 'function' && define.amd) - define(["protobufjs/minimal"], factory); - - /* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports) - module.exports = factory(require("protobufjs/minimal")); - -})(this, function($protobuf) { - "use strict"; - - // Common aliases - var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; - - // Exported root namespace - var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); - - $root.RPC = (function() { - - /** - * Properties of a RPC. - * @exports IRPC - * @interface IRPC - * @property {Array.|null} [subscriptions] RPC subscriptions - * @property {Array.|null} [messages] RPC messages - * @property {RPC.IControlMessage|null} [control] RPC control - */ - - /** - * Constructs a new RPC. - * @exports RPC - * @classdesc Represents a RPC. - * @implements IRPC - * @constructor - * @param {IRPC=} [p] Properties to set - */ - function RPC(p) { - this.subscriptions = []; - this.messages = []; - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * RPC subscriptions. - * @member {Array.} subscriptions - * @memberof RPC - * @instance - */ - RPC.prototype.subscriptions = $util.emptyArray; - - /** - * RPC messages. - * @member {Array.} messages - * @memberof RPC - * @instance - */ - RPC.prototype.messages = $util.emptyArray; - - /** - * RPC control. - * @member {RPC.IControlMessage|null|undefined} control - * @memberof RPC - * @instance - */ - RPC.prototype.control = null; - - // OneOf field names bound to virtual getters and setters - var $oneOfFields; - - /** - * RPC _control. - * @member {"control"|undefined} _control - * @memberof RPC - * @instance - */ - Object.defineProperty(RPC.prototype, "_control", { - get: $util.oneOfGetter($oneOfFields = ["control"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Encodes the specified RPC message. Does not implicitly {@link RPC.verify|verify} messages. - * @function encode - * @memberof RPC - * @static - * @param {IRPC} m RPC message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - RPC.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.subscriptions != null && m.subscriptions.length) { - for (var i = 0; i < m.subscriptions.length; ++i) - $root.RPC.SubOpts.encode(m.subscriptions[i], w.uint32(10).fork()).ldelim(); - } - if (m.messages != null && m.messages.length) { - for (var i = 0; i < m.messages.length; ++i) - $root.RPC.Message.encode(m.messages[i], w.uint32(18).fork()).ldelim(); - } - if (m.control != null && Object.hasOwnProperty.call(m, "control")) - $root.RPC.ControlMessage.encode(m.control, w.uint32(26).fork()).ldelim(); - return w; - }; - - /** - * Decodes a RPC message from the specified reader or buffer. - * @function decode - * @memberof RPC - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC} RPC - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - RPC.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - if (!(m.subscriptions && m.subscriptions.length)) - m.subscriptions = []; - m.subscriptions.push($root.RPC.SubOpts.decode(r, r.uint32())); - break; - case 2: - if (!(m.messages && m.messages.length)) - m.messages = []; - m.messages.push($root.RPC.Message.decode(r, r.uint32())); - break; - case 3: - m.control = $root.RPC.ControlMessage.decode(r, r.uint32()); - break; - default: - r.skipType(t & 7); - break; - } - } - return m; - }; - - /** - * Creates a RPC message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC - * @static - * @param {Object.} d Plain object - * @returns {RPC} RPC - */ - RPC.fromObject = function fromObject(d) { - if (d instanceof $root.RPC) - return d; - var m = new $root.RPC(); - if (d.subscriptions) { - if (!Array.isArray(d.subscriptions)) - throw TypeError(".RPC.subscriptions: array expected"); - m.subscriptions = []; - for (var i = 0; i < d.subscriptions.length; ++i) { - if (typeof d.subscriptions[i] !== "object") - throw TypeError(".RPC.subscriptions: object expected"); - m.subscriptions[i] = $root.RPC.SubOpts.fromObject(d.subscriptions[i]); - } - } - if (d.messages) { - if (!Array.isArray(d.messages)) - throw TypeError(".RPC.messages: array expected"); - m.messages = []; - for (var i = 0; i < d.messages.length; ++i) { - if (typeof d.messages[i] !== "object") - throw TypeError(".RPC.messages: object expected"); - m.messages[i] = $root.RPC.Message.fromObject(d.messages[i]); - } - } - if (d.control != null) { - if (typeof d.control !== "object") - throw TypeError(".RPC.control: object expected"); - m.control = $root.RPC.ControlMessage.fromObject(d.control); - } - return m; - }; - - /** - * Creates a plain object from a RPC message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC - * @static - * @param {RPC} m RPC - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - RPC.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (o.arrays || o.defaults) { - d.subscriptions = []; - d.messages = []; - } - if (m.subscriptions && m.subscriptions.length) { - d.subscriptions = []; - for (var j = 0; j < m.subscriptions.length; ++j) { - d.subscriptions[j] = $root.RPC.SubOpts.toObject(m.subscriptions[j], o); - } - } - if (m.messages && m.messages.length) { - d.messages = []; - for (var j = 0; j < m.messages.length; ++j) { - d.messages[j] = $root.RPC.Message.toObject(m.messages[j], o); - } - } - if (m.control != null && m.hasOwnProperty("control")) { - d.control = $root.RPC.ControlMessage.toObject(m.control, o); - if (o.oneofs) - d._control = "control"; - } - return d; - }; - - /** - * Converts this RPC to JSON. - * @function toJSON - * @memberof RPC - * @instance - * @returns {Object.} JSON object - */ - RPC.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - RPC.SubOpts = (function() { - - /** - * Properties of a SubOpts. - * @memberof RPC - * @interface ISubOpts - * @property {boolean|null} [subscribe] SubOpts subscribe - * @property {string|null} [topic] SubOpts topic - */ - - /** - * Constructs a new SubOpts. - * @memberof RPC - * @classdesc Represents a SubOpts. - * @implements ISubOpts - * @constructor - * @param {RPC.ISubOpts=} [p] Properties to set - */ - function SubOpts(p) { - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * SubOpts subscribe. - * @member {boolean|null|undefined} subscribe - * @memberof RPC.SubOpts - * @instance - */ - SubOpts.prototype.subscribe = null; - - /** - * SubOpts topic. - * @member {string|null|undefined} topic - * @memberof RPC.SubOpts - * @instance - */ - SubOpts.prototype.topic = null; - - // OneOf field names bound to virtual getters and setters - var $oneOfFields; - - /** - * SubOpts _subscribe. - * @member {"subscribe"|undefined} _subscribe - * @memberof RPC.SubOpts - * @instance - */ - Object.defineProperty(SubOpts.prototype, "_subscribe", { - get: $util.oneOfGetter($oneOfFields = ["subscribe"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * SubOpts _topic. - * @member {"topic"|undefined} _topic - * @memberof RPC.SubOpts - * @instance - */ - Object.defineProperty(SubOpts.prototype, "_topic", { - get: $util.oneOfGetter($oneOfFields = ["topic"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Encodes the specified SubOpts message. Does not implicitly {@link RPC.SubOpts.verify|verify} messages. - * @function encode - * @memberof RPC.SubOpts - * @static - * @param {RPC.ISubOpts} m SubOpts message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - SubOpts.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.subscribe != null && Object.hasOwnProperty.call(m, "subscribe")) - w.uint32(8).bool(m.subscribe); - if (m.topic != null && Object.hasOwnProperty.call(m, "topic")) - w.uint32(18).string(m.topic); - return w; - }; - - /** - * Decodes a SubOpts message from the specified reader or buffer. - * @function decode - * @memberof RPC.SubOpts - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC.SubOpts} SubOpts - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - SubOpts.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.SubOpts(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - m.subscribe = r.bool(); - break; - case 2: - m.topic = r.string(); - break; - default: - r.skipType(t & 7); - break; - } - } - return m; - }; - - /** - * Creates a SubOpts message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC.SubOpts - * @static - * @param {Object.} d Plain object - * @returns {RPC.SubOpts} SubOpts - */ - SubOpts.fromObject = function fromObject(d) { - if (d instanceof $root.RPC.SubOpts) - return d; - var m = new $root.RPC.SubOpts(); - if (d.subscribe != null) { - m.subscribe = Boolean(d.subscribe); - } - if (d.topic != null) { - m.topic = String(d.topic); - } - return m; - }; - - /** - * Creates a plain object from a SubOpts message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC.SubOpts - * @static - * @param {RPC.SubOpts} m SubOpts - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - SubOpts.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (m.subscribe != null && m.hasOwnProperty("subscribe")) { - d.subscribe = m.subscribe; - if (o.oneofs) - d._subscribe = "subscribe"; - } - if (m.topic != null && m.hasOwnProperty("topic")) { - d.topic = m.topic; - if (o.oneofs) - d._topic = "topic"; - } - return d; - }; - - /** - * Converts this SubOpts to JSON. - * @function toJSON - * @memberof RPC.SubOpts - * @instance - * @returns {Object.} JSON object - */ - SubOpts.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - return SubOpts; - })(); - - RPC.Message = (function() { - - /** - * Properties of a Message. - * @memberof RPC - * @interface IMessage - * @property {Uint8Array|null} [from] Message from - * @property {Uint8Array|null} [data] Message data - * @property {Uint8Array|null} [seqno] Message seqno - * @property {string} topic Message topic - * @property {Uint8Array|null} [signature] Message signature - * @property {Uint8Array|null} [key] Message key - */ - - /** - * Constructs a new Message. - * @memberof RPC - * @classdesc Represents a Message. - * @implements IMessage - * @constructor - * @param {RPC.IMessage=} [p] Properties to set - */ - function Message(p) { - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * Message from. - * @member {Uint8Array|null|undefined} from - * @memberof RPC.Message - * @instance - */ - Message.prototype.from = null; - - /** - * Message data. - * @member {Uint8Array|null|undefined} data - * @memberof RPC.Message - * @instance - */ - Message.prototype.data = null; - - /** - * Message seqno. - * @member {Uint8Array|null|undefined} seqno - * @memberof RPC.Message - * @instance - */ - Message.prototype.seqno = null; - - /** - * Message topic. - * @member {string} topic - * @memberof RPC.Message - * @instance - */ - Message.prototype.topic = ""; - - /** - * Message signature. - * @member {Uint8Array|null|undefined} signature - * @memberof RPC.Message - * @instance - */ - Message.prototype.signature = null; - - /** - * Message key. - * @member {Uint8Array|null|undefined} key - * @memberof RPC.Message - * @instance - */ - Message.prototype.key = null; - - // OneOf field names bound to virtual getters and setters - var $oneOfFields; - - /** - * Message _from. - * @member {"from"|undefined} _from - * @memberof RPC.Message - * @instance - */ - Object.defineProperty(Message.prototype, "_from", { - get: $util.oneOfGetter($oneOfFields = ["from"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Message _data. - * @member {"data"|undefined} _data - * @memberof RPC.Message - * @instance - */ - Object.defineProperty(Message.prototype, "_data", { - get: $util.oneOfGetter($oneOfFields = ["data"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Message _seqno. - * @member {"seqno"|undefined} _seqno - * @memberof RPC.Message - * @instance - */ - Object.defineProperty(Message.prototype, "_seqno", { - get: $util.oneOfGetter($oneOfFields = ["seqno"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Message _signature. - * @member {"signature"|undefined} _signature - * @memberof RPC.Message - * @instance - */ - Object.defineProperty(Message.prototype, "_signature", { - get: $util.oneOfGetter($oneOfFields = ["signature"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Message _key. - * @member {"key"|undefined} _key - * @memberof RPC.Message - * @instance - */ - Object.defineProperty(Message.prototype, "_key", { - get: $util.oneOfGetter($oneOfFields = ["key"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Encodes the specified Message message. Does not implicitly {@link RPC.Message.verify|verify} messages. - * @function encode - * @memberof RPC.Message - * @static - * @param {RPC.IMessage} m Message message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - Message.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.from != null && Object.hasOwnProperty.call(m, "from")) - w.uint32(10).bytes(m.from); - if (m.data != null && Object.hasOwnProperty.call(m, "data")) - w.uint32(18).bytes(m.data); - if (m.seqno != null && Object.hasOwnProperty.call(m, "seqno")) - w.uint32(26).bytes(m.seqno); - w.uint32(34).string(m.topic); - if (m.signature != null && Object.hasOwnProperty.call(m, "signature")) - w.uint32(42).bytes(m.signature); - if (m.key != null && Object.hasOwnProperty.call(m, "key")) - w.uint32(50).bytes(m.key); - return w; - }; - - /** - * Decodes a Message message from the specified reader or buffer. - * @function decode - * @memberof RPC.Message - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC.Message} Message - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - Message.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.Message(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - m.from = r.bytes(); - break; - case 2: - m.data = r.bytes(); - break; - case 3: - m.seqno = r.bytes(); - break; - case 4: - m.topic = r.string(); - break; - case 5: - m.signature = r.bytes(); - break; - case 6: - m.key = r.bytes(); - break; - default: - r.skipType(t & 7); - break; - } - } - if (!m.hasOwnProperty("topic")) - throw $util.ProtocolError("missing required 'topic'", { instance: m }); - return m; - }; - - /** - * Creates a Message message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC.Message - * @static - * @param {Object.} d Plain object - * @returns {RPC.Message} Message - */ - Message.fromObject = function fromObject(d) { - if (d instanceof $root.RPC.Message) - return d; - var m = new $root.RPC.Message(); - if (d.from != null) { - if (typeof d.from === "string") - $util.base64.decode(d.from, m.from = $util.newBuffer($util.base64.length(d.from)), 0); - else if (d.from.length) - m.from = d.from; - } - if (d.data != null) { - if (typeof d.data === "string") - $util.base64.decode(d.data, m.data = $util.newBuffer($util.base64.length(d.data)), 0); - else if (d.data.length) - m.data = d.data; - } - if (d.seqno != null) { - if (typeof d.seqno === "string") - $util.base64.decode(d.seqno, m.seqno = $util.newBuffer($util.base64.length(d.seqno)), 0); - else if (d.seqno.length) - m.seqno = d.seqno; - } - if (d.topic != null) { - m.topic = String(d.topic); - } - if (d.signature != null) { - if (typeof d.signature === "string") - $util.base64.decode(d.signature, m.signature = $util.newBuffer($util.base64.length(d.signature)), 0); - else if (d.signature.length) - m.signature = d.signature; - } - if (d.key != null) { - if (typeof d.key === "string") - $util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0); - else if (d.key.length) - m.key = d.key; - } - return m; - }; - - /** - * Creates a plain object from a Message message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC.Message - * @static - * @param {RPC.Message} m Message - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - Message.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (o.defaults) { - d.topic = ""; - } - if (m.from != null && m.hasOwnProperty("from")) { - d.from = o.bytes === String ? $util.base64.encode(m.from, 0, m.from.length) : o.bytes === Array ? Array.prototype.slice.call(m.from) : m.from; - if (o.oneofs) - d._from = "from"; - } - if (m.data != null && m.hasOwnProperty("data")) { - d.data = o.bytes === String ? $util.base64.encode(m.data, 0, m.data.length) : o.bytes === Array ? Array.prototype.slice.call(m.data) : m.data; - if (o.oneofs) - d._data = "data"; - } - if (m.seqno != null && m.hasOwnProperty("seqno")) { - d.seqno = o.bytes === String ? $util.base64.encode(m.seqno, 0, m.seqno.length) : o.bytes === Array ? Array.prototype.slice.call(m.seqno) : m.seqno; - if (o.oneofs) - d._seqno = "seqno"; - } - if (m.topic != null && m.hasOwnProperty("topic")) { - d.topic = m.topic; - } - if (m.signature != null && m.hasOwnProperty("signature")) { - d.signature = o.bytes === String ? $util.base64.encode(m.signature, 0, m.signature.length) : o.bytes === Array ? Array.prototype.slice.call(m.signature) : m.signature; - if (o.oneofs) - d._signature = "signature"; - } - if (m.key != null && m.hasOwnProperty("key")) { - d.key = o.bytes === String ? $util.base64.encode(m.key, 0, m.key.length) : o.bytes === Array ? Array.prototype.slice.call(m.key) : m.key; - if (o.oneofs) - d._key = "key"; - } - return d; - }; - - /** - * Converts this Message to JSON. - * @function toJSON - * @memberof RPC.Message - * @instance - * @returns {Object.} JSON object - */ - Message.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - return Message; - })(); - - RPC.ControlMessage = (function() { - - /** - * Properties of a ControlMessage. - * @memberof RPC - * @interface IControlMessage - * @property {Array.|null} [ihave] ControlMessage ihave - * @property {Array.|null} [iwant] ControlMessage iwant - * @property {Array.|null} [graft] ControlMessage graft - * @property {Array.|null} [prune] ControlMessage prune - */ - - /** - * Constructs a new ControlMessage. - * @memberof RPC - * @classdesc Represents a ControlMessage. - * @implements IControlMessage - * @constructor - * @param {RPC.IControlMessage=} [p] Properties to set - */ - function ControlMessage(p) { - this.ihave = []; - this.iwant = []; - this.graft = []; - this.prune = []; - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * ControlMessage ihave. - * @member {Array.} ihave - * @memberof RPC.ControlMessage - * @instance - */ - ControlMessage.prototype.ihave = $util.emptyArray; - - /** - * ControlMessage iwant. - * @member {Array.} iwant - * @memberof RPC.ControlMessage - * @instance - */ - ControlMessage.prototype.iwant = $util.emptyArray; - - /** - * ControlMessage graft. - * @member {Array.} graft - * @memberof RPC.ControlMessage - * @instance - */ - ControlMessage.prototype.graft = $util.emptyArray; - - /** - * ControlMessage prune. - * @member {Array.} prune - * @memberof RPC.ControlMessage - * @instance - */ - ControlMessage.prototype.prune = $util.emptyArray; - - /** - * Encodes the specified ControlMessage message. Does not implicitly {@link RPC.ControlMessage.verify|verify} messages. - * @function encode - * @memberof RPC.ControlMessage - * @static - * @param {RPC.IControlMessage} m ControlMessage message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - ControlMessage.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.ihave != null && m.ihave.length) { - for (var i = 0; i < m.ihave.length; ++i) - $root.RPC.ControlIHave.encode(m.ihave[i], w.uint32(10).fork()).ldelim(); - } - if (m.iwant != null && m.iwant.length) { - for (var i = 0; i < m.iwant.length; ++i) - $root.RPC.ControlIWant.encode(m.iwant[i], w.uint32(18).fork()).ldelim(); - } - if (m.graft != null && m.graft.length) { - for (var i = 0; i < m.graft.length; ++i) - $root.RPC.ControlGraft.encode(m.graft[i], w.uint32(26).fork()).ldelim(); - } - if (m.prune != null && m.prune.length) { - for (var i = 0; i < m.prune.length; ++i) - $root.RPC.ControlPrune.encode(m.prune[i], w.uint32(34).fork()).ldelim(); - } - return w; - }; - - /** - * Decodes a ControlMessage message from the specified reader or buffer. - * @function decode - * @memberof RPC.ControlMessage - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC.ControlMessage} ControlMessage - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - ControlMessage.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlMessage(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - if (!(m.ihave && m.ihave.length)) - m.ihave = []; - m.ihave.push($root.RPC.ControlIHave.decode(r, r.uint32())); - break; - case 2: - if (!(m.iwant && m.iwant.length)) - m.iwant = []; - m.iwant.push($root.RPC.ControlIWant.decode(r, r.uint32())); - break; - case 3: - if (!(m.graft && m.graft.length)) - m.graft = []; - m.graft.push($root.RPC.ControlGraft.decode(r, r.uint32())); - break; - case 4: - if (!(m.prune && m.prune.length)) - m.prune = []; - m.prune.push($root.RPC.ControlPrune.decode(r, r.uint32())); - break; - default: - r.skipType(t & 7); - break; - } - } - return m; - }; - - /** - * Creates a ControlMessage message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC.ControlMessage - * @static - * @param {Object.} d Plain object - * @returns {RPC.ControlMessage} ControlMessage - */ - ControlMessage.fromObject = function fromObject(d) { - if (d instanceof $root.RPC.ControlMessage) - return d; - var m = new $root.RPC.ControlMessage(); - if (d.ihave) { - if (!Array.isArray(d.ihave)) - throw TypeError(".RPC.ControlMessage.ihave: array expected"); - m.ihave = []; - for (var i = 0; i < d.ihave.length; ++i) { - if (typeof d.ihave[i] !== "object") - throw TypeError(".RPC.ControlMessage.ihave: object expected"); - m.ihave[i] = $root.RPC.ControlIHave.fromObject(d.ihave[i]); - } - } - if (d.iwant) { - if (!Array.isArray(d.iwant)) - throw TypeError(".RPC.ControlMessage.iwant: array expected"); - m.iwant = []; - for (var i = 0; i < d.iwant.length; ++i) { - if (typeof d.iwant[i] !== "object") - throw TypeError(".RPC.ControlMessage.iwant: object expected"); - m.iwant[i] = $root.RPC.ControlIWant.fromObject(d.iwant[i]); - } - } - if (d.graft) { - if (!Array.isArray(d.graft)) - throw TypeError(".RPC.ControlMessage.graft: array expected"); - m.graft = []; - for (var i = 0; i < d.graft.length; ++i) { - if (typeof d.graft[i] !== "object") - throw TypeError(".RPC.ControlMessage.graft: object expected"); - m.graft[i] = $root.RPC.ControlGraft.fromObject(d.graft[i]); - } - } - if (d.prune) { - if (!Array.isArray(d.prune)) - throw TypeError(".RPC.ControlMessage.prune: array expected"); - m.prune = []; - for (var i = 0; i < d.prune.length; ++i) { - if (typeof d.prune[i] !== "object") - throw TypeError(".RPC.ControlMessage.prune: object expected"); - m.prune[i] = $root.RPC.ControlPrune.fromObject(d.prune[i]); - } - } - return m; - }; - - /** - * Creates a plain object from a ControlMessage message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC.ControlMessage - * @static - * @param {RPC.ControlMessage} m ControlMessage - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - ControlMessage.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (o.arrays || o.defaults) { - d.ihave = []; - d.iwant = []; - d.graft = []; - d.prune = []; - } - if (m.ihave && m.ihave.length) { - d.ihave = []; - for (var j = 0; j < m.ihave.length; ++j) { - d.ihave[j] = $root.RPC.ControlIHave.toObject(m.ihave[j], o); - } - } - if (m.iwant && m.iwant.length) { - d.iwant = []; - for (var j = 0; j < m.iwant.length; ++j) { - d.iwant[j] = $root.RPC.ControlIWant.toObject(m.iwant[j], o); - } - } - if (m.graft && m.graft.length) { - d.graft = []; - for (var j = 0; j < m.graft.length; ++j) { - d.graft[j] = $root.RPC.ControlGraft.toObject(m.graft[j], o); - } - } - if (m.prune && m.prune.length) { - d.prune = []; - for (var j = 0; j < m.prune.length; ++j) { - d.prune[j] = $root.RPC.ControlPrune.toObject(m.prune[j], o); - } - } - return d; - }; - - /** - * Converts this ControlMessage to JSON. - * @function toJSON - * @memberof RPC.ControlMessage - * @instance - * @returns {Object.} JSON object - */ - ControlMessage.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - return ControlMessage; - })(); - - RPC.ControlIHave = (function() { - - /** - * Properties of a ControlIHave. - * @memberof RPC - * @interface IControlIHave - * @property {string|null} [topicID] ControlIHave topicID - * @property {Array.|null} [messageIDs] ControlIHave messageIDs - */ - - /** - * Constructs a new ControlIHave. - * @memberof RPC - * @classdesc Represents a ControlIHave. - * @implements IControlIHave - * @constructor - * @param {RPC.IControlIHave=} [p] Properties to set - */ - function ControlIHave(p) { - this.messageIDs = []; - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * ControlIHave topicID. - * @member {string|null|undefined} topicID - * @memberof RPC.ControlIHave - * @instance - */ - ControlIHave.prototype.topicID = null; - - /** - * ControlIHave messageIDs. - * @member {Array.} messageIDs - * @memberof RPC.ControlIHave - * @instance - */ - ControlIHave.prototype.messageIDs = $util.emptyArray; - - // OneOf field names bound to virtual getters and setters - var $oneOfFields; - - /** - * ControlIHave _topicID. - * @member {"topicID"|undefined} _topicID - * @memberof RPC.ControlIHave - * @instance - */ - Object.defineProperty(ControlIHave.prototype, "_topicID", { - get: $util.oneOfGetter($oneOfFields = ["topicID"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Encodes the specified ControlIHave message. Does not implicitly {@link RPC.ControlIHave.verify|verify} messages. - * @function encode - * @memberof RPC.ControlIHave - * @static - * @param {RPC.IControlIHave} m ControlIHave message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - ControlIHave.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) - w.uint32(10).string(m.topicID); - if (m.messageIDs != null && m.messageIDs.length) { - for (var i = 0; i < m.messageIDs.length; ++i) - w.uint32(18).bytes(m.messageIDs[i]); - } - return w; - }; - - /** - * Decodes a ControlIHave message from the specified reader or buffer. - * @function decode - * @memberof RPC.ControlIHave - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC.ControlIHave} ControlIHave - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - ControlIHave.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlIHave(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - m.topicID = r.string(); - break; - case 2: - if (!(m.messageIDs && m.messageIDs.length)) - m.messageIDs = []; - m.messageIDs.push(r.bytes()); - break; - default: - r.skipType(t & 7); - break; - } - } - return m; - }; - - /** - * Creates a ControlIHave message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC.ControlIHave - * @static - * @param {Object.} d Plain object - * @returns {RPC.ControlIHave} ControlIHave - */ - ControlIHave.fromObject = function fromObject(d) { - if (d instanceof $root.RPC.ControlIHave) - return d; - var m = new $root.RPC.ControlIHave(); - if (d.topicID != null) { - m.topicID = String(d.topicID); - } - if (d.messageIDs) { - if (!Array.isArray(d.messageIDs)) - throw TypeError(".RPC.ControlIHave.messageIDs: array expected"); - m.messageIDs = []; - for (var i = 0; i < d.messageIDs.length; ++i) { - if (typeof d.messageIDs[i] === "string") - $util.base64.decode(d.messageIDs[i], m.messageIDs[i] = $util.newBuffer($util.base64.length(d.messageIDs[i])), 0); - else if (d.messageIDs[i].length) - m.messageIDs[i] = d.messageIDs[i]; - } - } - return m; - }; - - /** - * Creates a plain object from a ControlIHave message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC.ControlIHave - * @static - * @param {RPC.ControlIHave} m ControlIHave - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - ControlIHave.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (o.arrays || o.defaults) { - d.messageIDs = []; - } - if (m.topicID != null && m.hasOwnProperty("topicID")) { - d.topicID = m.topicID; - if (o.oneofs) - d._topicID = "topicID"; - } - if (m.messageIDs && m.messageIDs.length) { - d.messageIDs = []; - for (var j = 0; j < m.messageIDs.length; ++j) { - d.messageIDs[j] = o.bytes === String ? $util.base64.encode(m.messageIDs[j], 0, m.messageIDs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.messageIDs[j]) : m.messageIDs[j]; - } - } - return d; - }; - - /** - * Converts this ControlIHave to JSON. - * @function toJSON - * @memberof RPC.ControlIHave - * @instance - * @returns {Object.} JSON object - */ - ControlIHave.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - return ControlIHave; - })(); - - RPC.ControlIWant = (function() { - - /** - * Properties of a ControlIWant. - * @memberof RPC - * @interface IControlIWant - * @property {Array.|null} [messageIDs] ControlIWant messageIDs - */ - - /** - * Constructs a new ControlIWant. - * @memberof RPC - * @classdesc Represents a ControlIWant. - * @implements IControlIWant - * @constructor - * @param {RPC.IControlIWant=} [p] Properties to set - */ - function ControlIWant(p) { - this.messageIDs = []; - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * ControlIWant messageIDs. - * @member {Array.} messageIDs - * @memberof RPC.ControlIWant - * @instance - */ - ControlIWant.prototype.messageIDs = $util.emptyArray; - - /** - * Encodes the specified ControlIWant message. Does not implicitly {@link RPC.ControlIWant.verify|verify} messages. - * @function encode - * @memberof RPC.ControlIWant - * @static - * @param {RPC.IControlIWant} m ControlIWant message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - ControlIWant.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.messageIDs != null && m.messageIDs.length) { - for (var i = 0; i < m.messageIDs.length; ++i) - w.uint32(10).bytes(m.messageIDs[i]); - } - return w; - }; - - /** - * Decodes a ControlIWant message from the specified reader or buffer. - * @function decode - * @memberof RPC.ControlIWant - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC.ControlIWant} ControlIWant - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - ControlIWant.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlIWant(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - if (!(m.messageIDs && m.messageIDs.length)) - m.messageIDs = []; - m.messageIDs.push(r.bytes()); - break; - default: - r.skipType(t & 7); - break; - } - } - return m; - }; - - /** - * Creates a ControlIWant message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC.ControlIWant - * @static - * @param {Object.} d Plain object - * @returns {RPC.ControlIWant} ControlIWant - */ - ControlIWant.fromObject = function fromObject(d) { - if (d instanceof $root.RPC.ControlIWant) - return d; - var m = new $root.RPC.ControlIWant(); - if (d.messageIDs) { - if (!Array.isArray(d.messageIDs)) - throw TypeError(".RPC.ControlIWant.messageIDs: array expected"); - m.messageIDs = []; - for (var i = 0; i < d.messageIDs.length; ++i) { - if (typeof d.messageIDs[i] === "string") - $util.base64.decode(d.messageIDs[i], m.messageIDs[i] = $util.newBuffer($util.base64.length(d.messageIDs[i])), 0); - else if (d.messageIDs[i].length) - m.messageIDs[i] = d.messageIDs[i]; - } - } - return m; - }; - - /** - * Creates a plain object from a ControlIWant message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC.ControlIWant - * @static - * @param {RPC.ControlIWant} m ControlIWant - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - ControlIWant.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (o.arrays || o.defaults) { - d.messageIDs = []; - } - if (m.messageIDs && m.messageIDs.length) { - d.messageIDs = []; - for (var j = 0; j < m.messageIDs.length; ++j) { - d.messageIDs[j] = o.bytes === String ? $util.base64.encode(m.messageIDs[j], 0, m.messageIDs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.messageIDs[j]) : m.messageIDs[j]; - } - } - return d; - }; - - /** - * Converts this ControlIWant to JSON. - * @function toJSON - * @memberof RPC.ControlIWant - * @instance - * @returns {Object.} JSON object - */ - ControlIWant.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - return ControlIWant; - })(); - - RPC.ControlGraft = (function() { - - /** - * Properties of a ControlGraft. - * @memberof RPC - * @interface IControlGraft - * @property {string|null} [topicID] ControlGraft topicID - */ - - /** - * Constructs a new ControlGraft. - * @memberof RPC - * @classdesc Represents a ControlGraft. - * @implements IControlGraft - * @constructor - * @param {RPC.IControlGraft=} [p] Properties to set - */ - function ControlGraft(p) { - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * ControlGraft topicID. - * @member {string|null|undefined} topicID - * @memberof RPC.ControlGraft - * @instance - */ - ControlGraft.prototype.topicID = null; - - // OneOf field names bound to virtual getters and setters - var $oneOfFields; - - /** - * ControlGraft _topicID. - * @member {"topicID"|undefined} _topicID - * @memberof RPC.ControlGraft - * @instance - */ - Object.defineProperty(ControlGraft.prototype, "_topicID", { - get: $util.oneOfGetter($oneOfFields = ["topicID"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Encodes the specified ControlGraft message. Does not implicitly {@link RPC.ControlGraft.verify|verify} messages. - * @function encode - * @memberof RPC.ControlGraft - * @static - * @param {RPC.IControlGraft} m ControlGraft message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - ControlGraft.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) - w.uint32(10).string(m.topicID); - return w; - }; - - /** - * Decodes a ControlGraft message from the specified reader or buffer. - * @function decode - * @memberof RPC.ControlGraft - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC.ControlGraft} ControlGraft - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - ControlGraft.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlGraft(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - m.topicID = r.string(); - break; - default: - r.skipType(t & 7); - break; - } - } - return m; - }; - - /** - * Creates a ControlGraft message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC.ControlGraft - * @static - * @param {Object.} d Plain object - * @returns {RPC.ControlGraft} ControlGraft - */ - ControlGraft.fromObject = function fromObject(d) { - if (d instanceof $root.RPC.ControlGraft) - return d; - var m = new $root.RPC.ControlGraft(); - if (d.topicID != null) { - m.topicID = String(d.topicID); - } - return m; - }; - - /** - * Creates a plain object from a ControlGraft message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC.ControlGraft - * @static - * @param {RPC.ControlGraft} m ControlGraft - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - ControlGraft.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (m.topicID != null && m.hasOwnProperty("topicID")) { - d.topicID = m.topicID; - if (o.oneofs) - d._topicID = "topicID"; - } - return d; - }; - - /** - * Converts this ControlGraft to JSON. - * @function toJSON - * @memberof RPC.ControlGraft - * @instance - * @returns {Object.} JSON object - */ - ControlGraft.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - return ControlGraft; - })(); - - RPC.ControlPrune = (function() { - - /** - * Properties of a ControlPrune. - * @memberof RPC - * @interface IControlPrune - * @property {string|null} [topicID] ControlPrune topicID - * @property {Array.|null} [peers] ControlPrune peers - * @property {number|null} [backoff] ControlPrune backoff - */ - - /** - * Constructs a new ControlPrune. - * @memberof RPC - * @classdesc Represents a ControlPrune. - * @implements IControlPrune - * @constructor - * @param {RPC.IControlPrune=} [p] Properties to set - */ - function ControlPrune(p) { - this.peers = []; - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * ControlPrune topicID. - * @member {string|null|undefined} topicID - * @memberof RPC.ControlPrune - * @instance - */ - ControlPrune.prototype.topicID = null; - - /** - * ControlPrune peers. - * @member {Array.} peers - * @memberof RPC.ControlPrune - * @instance - */ - ControlPrune.prototype.peers = $util.emptyArray; - - /** - * ControlPrune backoff. - * @member {number|null|undefined} backoff - * @memberof RPC.ControlPrune - * @instance - */ - ControlPrune.prototype.backoff = null; - - // OneOf field names bound to virtual getters and setters - var $oneOfFields; - - /** - * ControlPrune _topicID. - * @member {"topicID"|undefined} _topicID - * @memberof RPC.ControlPrune - * @instance - */ - Object.defineProperty(ControlPrune.prototype, "_topicID", { - get: $util.oneOfGetter($oneOfFields = ["topicID"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * ControlPrune _backoff. - * @member {"backoff"|undefined} _backoff - * @memberof RPC.ControlPrune - * @instance - */ - Object.defineProperty(ControlPrune.prototype, "_backoff", { - get: $util.oneOfGetter($oneOfFields = ["backoff"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Encodes the specified ControlPrune message. Does not implicitly {@link RPC.ControlPrune.verify|verify} messages. - * @function encode - * @memberof RPC.ControlPrune - * @static - * @param {RPC.IControlPrune} m ControlPrune message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - ControlPrune.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) - w.uint32(10).string(m.topicID); - if (m.peers != null && m.peers.length) { - for (var i = 0; i < m.peers.length; ++i) - $root.RPC.PeerInfo.encode(m.peers[i], w.uint32(18).fork()).ldelim(); - } - if (m.backoff != null && Object.hasOwnProperty.call(m, "backoff")) - w.uint32(24).uint64(m.backoff); - return w; - }; - - /** - * Decodes a ControlPrune message from the specified reader or buffer. - * @function decode - * @memberof RPC.ControlPrune - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC.ControlPrune} ControlPrune - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - ControlPrune.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.ControlPrune(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - m.topicID = r.string(); - break; - case 2: - if (!(m.peers && m.peers.length)) - m.peers = []; - m.peers.push($root.RPC.PeerInfo.decode(r, r.uint32())); - break; - case 3: - m.backoff = r.uint64(); - break; - default: - r.skipType(t & 7); - break; - } - } - return m; - }; - - /** - * Creates a ControlPrune message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC.ControlPrune - * @static - * @param {Object.} d Plain object - * @returns {RPC.ControlPrune} ControlPrune - */ - ControlPrune.fromObject = function fromObject(d) { - if (d instanceof $root.RPC.ControlPrune) - return d; - var m = new $root.RPC.ControlPrune(); - if (d.topicID != null) { - m.topicID = String(d.topicID); - } - if (d.peers) { - if (!Array.isArray(d.peers)) - throw TypeError(".RPC.ControlPrune.peers: array expected"); - m.peers = []; - for (var i = 0; i < d.peers.length; ++i) { - if (typeof d.peers[i] !== "object") - throw TypeError(".RPC.ControlPrune.peers: object expected"); - m.peers[i] = $root.RPC.PeerInfo.fromObject(d.peers[i]); - } - } - if (d.backoff != null) { - if ($util.Long) - (m.backoff = $util.Long.fromValue(d.backoff)).unsigned = true; - else if (typeof d.backoff === "string") - m.backoff = parseInt(d.backoff, 10); - else if (typeof d.backoff === "number") - m.backoff = d.backoff; - else if (typeof d.backoff === "object") - m.backoff = new $util.LongBits(d.backoff.low >>> 0, d.backoff.high >>> 0).toNumber(true); - } - return m; - }; - - /** - * Creates a plain object from a ControlPrune message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC.ControlPrune - * @static - * @param {RPC.ControlPrune} m ControlPrune - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - ControlPrune.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (o.arrays || o.defaults) { - d.peers = []; - } - if (m.topicID != null && m.hasOwnProperty("topicID")) { - d.topicID = m.topicID; - if (o.oneofs) - d._topicID = "topicID"; - } - if (m.peers && m.peers.length) { - d.peers = []; - for (var j = 0; j < m.peers.length; ++j) { - d.peers[j] = $root.RPC.PeerInfo.toObject(m.peers[j], o); - } - } - if (m.backoff != null && m.hasOwnProperty("backoff")) { - if (typeof m.backoff === "number") - d.backoff = o.longs === String ? String(m.backoff) : m.backoff; - else - d.backoff = o.longs === String ? $util.Long.prototype.toString.call(m.backoff) : o.longs === Number ? new $util.LongBits(m.backoff.low >>> 0, m.backoff.high >>> 0).toNumber(true) : m.backoff; - if (o.oneofs) - d._backoff = "backoff"; - } - return d; - }; - - /** - * Converts this ControlPrune to JSON. - * @function toJSON - * @memberof RPC.ControlPrune - * @instance - * @returns {Object.} JSON object - */ - ControlPrune.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - return ControlPrune; - })(); - - RPC.PeerInfo = (function() { - - /** - * Properties of a PeerInfo. - * @memberof RPC - * @interface IPeerInfo - * @property {Uint8Array|null} [peerID] PeerInfo peerID - * @property {Uint8Array|null} [signedPeerRecord] PeerInfo signedPeerRecord - */ - - /** - * Constructs a new PeerInfo. - * @memberof RPC - * @classdesc Represents a PeerInfo. - * @implements IPeerInfo - * @constructor - * @param {RPC.IPeerInfo=} [p] Properties to set - */ - function PeerInfo(p) { - if (p) - for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) - if (p[ks[i]] != null) - this[ks[i]] = p[ks[i]]; - } - - /** - * PeerInfo peerID. - * @member {Uint8Array|null|undefined} peerID - * @memberof RPC.PeerInfo - * @instance - */ - PeerInfo.prototype.peerID = null; - - /** - * PeerInfo signedPeerRecord. - * @member {Uint8Array|null|undefined} signedPeerRecord - * @memberof RPC.PeerInfo - * @instance - */ - PeerInfo.prototype.signedPeerRecord = null; - - // OneOf field names bound to virtual getters and setters - var $oneOfFields; - - /** - * PeerInfo _peerID. - * @member {"peerID"|undefined} _peerID - * @memberof RPC.PeerInfo - * @instance - */ - Object.defineProperty(PeerInfo.prototype, "_peerID", { - get: $util.oneOfGetter($oneOfFields = ["peerID"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * PeerInfo _signedPeerRecord. - * @member {"signedPeerRecord"|undefined} _signedPeerRecord - * @memberof RPC.PeerInfo - * @instance - */ - Object.defineProperty(PeerInfo.prototype, "_signedPeerRecord", { - get: $util.oneOfGetter($oneOfFields = ["signedPeerRecord"]), - set: $util.oneOfSetter($oneOfFields) - }); - - /** - * Encodes the specified PeerInfo message. Does not implicitly {@link RPC.PeerInfo.verify|verify} messages. - * @function encode - * @memberof RPC.PeerInfo - * @static - * @param {RPC.IPeerInfo} m PeerInfo message or plain object to encode - * @param {$protobuf.Writer} [w] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - PeerInfo.encode = function encode(m, w) { - if (!w) - w = $Writer.create(); - if (m.peerID != null && Object.hasOwnProperty.call(m, "peerID")) - w.uint32(10).bytes(m.peerID); - if (m.signedPeerRecord != null && Object.hasOwnProperty.call(m, "signedPeerRecord")) - w.uint32(18).bytes(m.signedPeerRecord); - return w; - }; - - /** - * Decodes a PeerInfo message from the specified reader or buffer. - * @function decode - * @memberof RPC.PeerInfo - * @static - * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from - * @param {number} [l] Message length if known beforehand - * @returns {RPC.PeerInfo} PeerInfo - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - PeerInfo.decode = function decode(r, l) { - if (!(r instanceof $Reader)) - r = $Reader.create(r); - var c = l === undefined ? r.len : r.pos + l, m = new $root.RPC.PeerInfo(); - while (r.pos < c) { - var t = r.uint32(); - switch (t >>> 3) { - case 1: - m.peerID = r.bytes(); - break; - case 2: - m.signedPeerRecord = r.bytes(); - break; - default: - r.skipType(t & 7); - break; - } - } - return m; - }; - - /** - * Creates a PeerInfo message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof RPC.PeerInfo - * @static - * @param {Object.} d Plain object - * @returns {RPC.PeerInfo} PeerInfo - */ - PeerInfo.fromObject = function fromObject(d) { - if (d instanceof $root.RPC.PeerInfo) - return d; - var m = new $root.RPC.PeerInfo(); - if (d.peerID != null) { - if (typeof d.peerID === "string") - $util.base64.decode(d.peerID, m.peerID = $util.newBuffer($util.base64.length(d.peerID)), 0); - else if (d.peerID.length) - m.peerID = d.peerID; - } - if (d.signedPeerRecord != null) { - if (typeof d.signedPeerRecord === "string") - $util.base64.decode(d.signedPeerRecord, m.signedPeerRecord = $util.newBuffer($util.base64.length(d.signedPeerRecord)), 0); - else if (d.signedPeerRecord.length) - m.signedPeerRecord = d.signedPeerRecord; - } - return m; - }; - - /** - * Creates a plain object from a PeerInfo message. Also converts values to other types if specified. - * @function toObject - * @memberof RPC.PeerInfo - * @static - * @param {RPC.PeerInfo} m PeerInfo - * @param {$protobuf.IConversionOptions} [o] Conversion options - * @returns {Object.} Plain object - */ - PeerInfo.toObject = function toObject(m, o) { - if (!o) - o = {}; - var d = {}; - if (m.peerID != null && m.hasOwnProperty("peerID")) { - 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; - if (o.oneofs) - d._peerID = "peerID"; - } - if (m.signedPeerRecord != null && m.hasOwnProperty("signedPeerRecord")) { - d.signedPeerRecord = o.bytes === String ? $util.base64.encode(m.signedPeerRecord, 0, m.signedPeerRecord.length) : o.bytes === Array ? Array.prototype.slice.call(m.signedPeerRecord) : m.signedPeerRecord; - if (o.oneofs) - d._signedPeerRecord = "signedPeerRecord"; - } - return d; - }; - - /** - * Converts this PeerInfo to JSON. - * @function toJSON - * @memberof RPC.PeerInfo - * @instance - * @returns {Object.} JSON object - */ - PeerInfo.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; - - return PeerInfo; - })(); - - return RPC; - })(); - - return $root; -}); +export const {RPC} = cjs diff --git a/tsconfig.json b/tsconfig.json index 13e1e3bb..be923243 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "noImplicitReturns": true, "outDir": "dist", "useUnknownInCatchVariables": true, + "checkJs": false }, "include": [ "src", From 029d046b9cef98d01e75a5662315a454dd51fb71 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 2 Aug 2022 09:48:48 +0700 Subject: [PATCH 3/4] Restore src/message/index.ts --- src/message/index.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/message/index.ts diff --git a/src/message/index.ts b/src/message/index.ts new file mode 100644 index 00000000..d1e0e360 --- /dev/null +++ b/src/message/index.ts @@ -0,0 +1 @@ +export * from './rpc.js' From bef99b6e9ead760aa2a65654b3e26bea59812e09 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 2 Aug 2022 11:44:41 +0700 Subject: [PATCH 4/4] Manually copy rpc.d.ts from src/message to dist --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 88bf86b4..b22de0b6 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "scripts": { "lint": "eslint --ext .ts src test", "release": "aegir release --no-types", - "build": "aegir build", + "build": "aegir build && cp src/message/rpc.d.ts dist/src/message", "prepare": "npm run build", "pretest": "npm run build", "pretest:e2e": "npm run build",