/* eslint-disable complexity */
import { decodeMessage, encodeMessage, MaxLengthError, message } from 'protons-runtime';
export var RPC;
(function (RPC) {
    let SubOpts;
    (function (SubOpts) {
        let _codec;
        SubOpts.codec = () => {
            if (_codec == null) {
                _codec = message((obj, w, opts = {}) => {
                    if (opts.lengthDelimited !== false) {
                        w.fork();
                    }
                    if (obj.subscribe != null) {
                        w.uint32(8);
                        w.bool(obj.subscribe);
                    }
                    if (obj.topic != null) {
                        w.uint32(18);
                        w.string(obj.topic);
                    }
                    if (opts.lengthDelimited !== false) {
                        w.ldelim();
                    }
                }, (reader, length, opts = {}) => {
                    const obj = {};
                    const end = length == null ? reader.len : reader.pos + length;
                    while (reader.pos < end) {
                        const tag = reader.uint32();
                        switch (tag >>> 3) {
                            case 1: {
                                obj.subscribe = reader.bool();
                                break;
                            }
                            case 2: {
                                obj.topic = reader.string();
                                break;
                            }
                            default: {
                                reader.skipType(tag & 7);
                                break;
                            }
                        }
                    }
                    return obj;
                });
            }
            return _codec;
        };
        SubOpts.encode = (obj) => {
            return encodeMessage(obj, SubOpts.codec());
        };
        SubOpts.decode = (buf, opts) => {
            return decodeMessage(buf, SubOpts.codec(), opts);
        };
    })(SubOpts = RPC.SubOpts || (RPC.SubOpts = {}));
    let Message;
    (function (Message) {
        let _codec;
        Message.codec = () => {
            if (_codec == null) {
                _codec = message((obj, w, opts = {}) => {
                    if (opts.lengthDelimited !== false) {
                        w.fork();
                    }
                    if (obj.from != null) {
                        w.uint32(10);
                        w.bytes(obj.from);
                    }
                    if (obj.data != null) {
                        w.uint32(18);
                        w.bytes(obj.data);
                    }
                    if (obj.sequenceNumber != null) {
                        w.uint32(26);
                        w.bytes(obj.sequenceNumber);
                    }
                    if (obj.topic != null) {
                        w.uint32(34);
                        w.string(obj.topic);
                    }
                    if (obj.signature != null) {
                        w.uint32(42);
                        w.bytes(obj.signature);
                    }
                    if (obj.key != null) {
                        w.uint32(50);
                        w.bytes(obj.key);
                    }
                    if (opts.lengthDelimited !== false) {
                        w.ldelim();
                    }
                }, (reader, length, opts = {}) => {
                    const obj = {};
                    const end = length == null ? reader.len : reader.pos + length;
                    while (reader.pos < end) {
                        const tag = reader.uint32();
                        switch (tag >>> 3) {
                            case 1: {
                                obj.from = reader.bytes();
                                break;
                            }
                            case 2: {
                                obj.data = reader.bytes();
                                break;
                            }
                            case 3: {
                                obj.sequenceNumber = reader.bytes();
                                break;
                            }
                            case 4: {
                                obj.topic = reader.string();
                                break;
                            }
                            case 5: {
                                obj.signature = reader.bytes();
                                break;
                            }
                            case 6: {
                                obj.key = reader.bytes();
                                break;
                            }
                            default: {
                                reader.skipType(tag & 7);
                                break;
                            }
                        }
                    }
                    return obj;
                });
            }
            return _codec;
        };
        Message.encode = (obj) => {
            return encodeMessage(obj, Message.codec());
        };
        Message.decode = (buf, opts) => {
            return decodeMessage(buf, Message.codec(), opts);
        };
    })(Message = RPC.Message || (RPC.Message = {}));
    let _codec;
    RPC.codec = () => {
        if (_codec == null) {
            _codec = message((obj, w, opts = {}) => {
                if (opts.lengthDelimited !== false) {
                    w.fork();
                }
                if (obj.subscriptions != null) {
                    for (const value of obj.subscriptions) {
                        w.uint32(10);
                        RPC.SubOpts.codec().encode(value, w);
                    }
                }
                if (obj.messages != null) {
                    for (const value of obj.messages) {
                        w.uint32(18);
                        RPC.Message.codec().encode(value, w);
                    }
                }
                if (obj.control != null) {
                    w.uint32(26);
                    ControlMessage.codec().encode(obj.control, w);
                }
                if (opts.lengthDelimited !== false) {
                    w.ldelim();
                }
            }, (reader, length, opts = {}) => {
                const obj = {
                    subscriptions: [],
                    messages: []
                };
                const end = length == null ? reader.len : reader.pos + length;
                while (reader.pos < end) {
                    const tag = reader.uint32();
                    switch (tag >>> 3) {
                        case 1: {
                            if (opts.limits?.subscriptions != null && obj.subscriptions.length === opts.limits.subscriptions) {
                                throw new MaxLengthError('Decode error - map field "subscriptions" had too many elements');
                            }
                            obj.subscriptions.push(RPC.SubOpts.codec().decode(reader, reader.uint32(), {
                                limits: opts.limits?.subscriptions$
                            }));
                            break;
                        }
                        case 2: {
                            if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) {
                                throw new MaxLengthError('Decode error - map field "messages" had too many elements');
                            }
                            obj.messages.push(RPC.Message.codec().decode(reader, reader.uint32(), {
                                limits: opts.limits?.messages$
                            }));
                            break;
                        }
                        case 3: {
                            obj.control = ControlMessage.codec().decode(reader, reader.uint32(), {
                                limits: opts.limits?.control
                            });
                            break;
                        }
                        default: {
                            reader.skipType(tag & 7);
                            break;
                        }
                    }
                }
                return obj;
            });
        }
        return _codec;
    };
    RPC.encode = (obj) => {
        return encodeMessage(obj, RPC.codec());
    };
    RPC.decode = (buf, opts) => {
        return decodeMessage(buf, RPC.codec(), opts);
    };
})(RPC || (RPC = {}));
export var ControlMessage;
(function (ControlMessage) {
    let _codec;
    ControlMessage.codec = () => {
        if (_codec == null) {
            _codec = message((obj, w, opts = {}) => {
                if (opts.lengthDelimited !== false) {
                    w.fork();
                }
                if (obj.ihave != null) {
                    for (const value of obj.ihave) {
                        w.uint32(10);
                        ControlIHave.codec().encode(value, w);
                    }
                }
                if (obj.iwant != null) {
                    for (const value of obj.iwant) {
                        w.uint32(18);
                        ControlIWant.codec().encode(value, w);
                    }
                }
                if (obj.graft != null) {
                    for (const value of obj.graft) {
                        w.uint32(26);
                        ControlGraft.codec().encode(value, w);
                    }
                }
                if (obj.prune != null) {
                    for (const value of obj.prune) {
                        w.uint32(34);
                        ControlPrune.codec().encode(value, w);
                    }
                }
                if (opts.lengthDelimited !== false) {
                    w.ldelim();
                }
            }, (reader, length, opts = {}) => {
                const obj = {
                    ihave: [],
                    iwant: [],
                    graft: [],
                    prune: []
                };
                const end = length == null ? reader.len : reader.pos + length;
                while (reader.pos < end) {
                    const tag = reader.uint32();
                    switch (tag >>> 3) {
                        case 1: {
                            if (opts.limits?.ihave != null && obj.ihave.length === opts.limits.ihave) {
                                throw new MaxLengthError('Decode error - map field "ihave" had too many elements');
                            }
                            obj.ihave.push(ControlIHave.codec().decode(reader, reader.uint32(), {
                                limits: opts.limits?.ihave$
                            }));
                            break;
                        }
                        case 2: {
                            if (opts.limits?.iwant != null && obj.iwant.length === opts.limits.iwant) {
                                throw new MaxLengthError('Decode error - map field "iwant" had too many elements');
                            }
                            obj.iwant.push(ControlIWant.codec().decode(reader, reader.uint32(), {
                                limits: opts.limits?.iwant$
                            }));
                            break;
                        }
                        case 3: {
                            if (opts.limits?.graft != null && obj.graft.length === opts.limits.graft) {
                                throw new MaxLengthError('Decode error - map field "graft" had too many elements');
                            }
                            obj.graft.push(ControlGraft.codec().decode(reader, reader.uint32(), {
                                limits: opts.limits?.graft$
                            }));
                            break;
                        }
                        case 4: {
                            if (opts.limits?.prune != null && obj.prune.length === opts.limits.prune) {
                                throw new MaxLengthError('Decode error - map field "prune" had too many elements');
                            }
                            obj.prune.push(ControlPrune.codec().decode(reader, reader.uint32(), {
                                limits: opts.limits?.prune$
                            }));
                            break;
                        }
                        default: {
                            reader.skipType(tag & 7);
                            break;
                        }
                    }
                }
                return obj;
            });
        }
        return _codec;
    };
    ControlMessage.encode = (obj) => {
        return encodeMessage(obj, ControlMessage.codec());
    };
    ControlMessage.decode = (buf, opts) => {
        return decodeMessage(buf, ControlMessage.codec(), opts);
    };
})(ControlMessage || (ControlMessage = {}));
export var ControlIHave;
(function (ControlIHave) {
    let _codec;
    ControlIHave.codec = () => {
        if (_codec == null) {
            _codec = message((obj, w, opts = {}) => {
                if (opts.lengthDelimited !== false) {
                    w.fork();
                }
                if (obj.topic != null) {
                    w.uint32(10);
                    w.string(obj.topic);
                }
                if (obj.messageIDs != null) {
                    for (const value of obj.messageIDs) {
                        w.uint32(18);
                        w.bytes(value);
                    }
                }
                if (opts.lengthDelimited !== false) {
                    w.ldelim();
                }
            }, (reader, length, opts = {}) => {
                const obj = {
                    messageIDs: []
                };
                const end = length == null ? reader.len : reader.pos + length;
                while (reader.pos < end) {
                    const tag = reader.uint32();
                    switch (tag >>> 3) {
                        case 1: {
                            obj.topic = reader.string();
                            break;
                        }
                        case 2: {
                            if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) {
                                throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements');
                            }
                            obj.messageIDs.push(reader.bytes());
                            break;
                        }
                        default: {
                            reader.skipType(tag & 7);
                            break;
                        }
                    }
                }
                return obj;
            });
        }
        return _codec;
    };
    ControlIHave.encode = (obj) => {
        return encodeMessage(obj, ControlIHave.codec());
    };
    ControlIHave.decode = (buf, opts) => {
        return decodeMessage(buf, ControlIHave.codec(), opts);
    };
})(ControlIHave || (ControlIHave = {}));
export var ControlIWant;
(function (ControlIWant) {
    let _codec;
    ControlIWant.codec = () => {
        if (_codec == null) {
            _codec = message((obj, w, opts = {}) => {
                if (opts.lengthDelimited !== false) {
                    w.fork();
                }
                if (obj.messageIDs != null) {
                    for (const value of obj.messageIDs) {
                        w.uint32(10);
                        w.bytes(value);
                    }
                }
                if (opts.lengthDelimited !== false) {
                    w.ldelim();
                }
            }, (reader, length, opts = {}) => {
                const obj = {
                    messageIDs: []
                };
                const end = length == null ? reader.len : reader.pos + length;
                while (reader.pos < end) {
                    const tag = reader.uint32();
                    switch (tag >>> 3) {
                        case 1: {
                            if (opts.limits?.messageIDs != null && obj.messageIDs.length === opts.limits.messageIDs) {
                                throw new MaxLengthError('Decode error - map field "messageIDs" had too many elements');
                            }
                            obj.messageIDs.push(reader.bytes());
                            break;
                        }
                        default: {
                            reader.skipType(tag & 7);
                            break;
                        }
                    }
                }
                return obj;
            });
        }
        return _codec;
    };
    ControlIWant.encode = (obj) => {
        return encodeMessage(obj, ControlIWant.codec());
    };
    ControlIWant.decode = (buf, opts) => {
        return decodeMessage(buf, ControlIWant.codec(), opts);
    };
})(ControlIWant || (ControlIWant = {}));
export var ControlGraft;
(function (ControlGraft) {
    let _codec;
    ControlGraft.codec = () => {
        if (_codec == null) {
            _codec = message((obj, w, opts = {}) => {
                if (opts.lengthDelimited !== false) {
                    w.fork();
                }
                if (obj.topic != null) {
                    w.uint32(10);
                    w.string(obj.topic);
                }
                if (opts.lengthDelimited !== false) {
                    w.ldelim();
                }
            }, (reader, length, opts = {}) => {
                const obj = {};
                const end = length == null ? reader.len : reader.pos + length;
                while (reader.pos < end) {
                    const tag = reader.uint32();
                    switch (tag >>> 3) {
                        case 1: {
                            obj.topic = reader.string();
                            break;
                        }
                        default: {
                            reader.skipType(tag & 7);
                            break;
                        }
                    }
                }
                return obj;
            });
        }
        return _codec;
    };
    ControlGraft.encode = (obj) => {
        return encodeMessage(obj, ControlGraft.codec());
    };
    ControlGraft.decode = (buf, opts) => {
        return decodeMessage(buf, ControlGraft.codec(), opts);
    };
})(ControlGraft || (ControlGraft = {}));
export var ControlPrune;
(function (ControlPrune) {
    let _codec;
    ControlPrune.codec = () => {
        if (_codec == null) {
            _codec = message((obj, w, opts = {}) => {
                if (opts.lengthDelimited !== false) {
                    w.fork();
                }
                if (obj.topic != null) {
                    w.uint32(10);
                    w.string(obj.topic);
                }
                if (obj.peers != null) {
                    for (const value of obj.peers) {
                        w.uint32(18);
                        PeerInfo.codec().encode(value, w);
                    }
                }
                if (obj.backoff != null) {
                    w.uint32(24);
                    w.uint64(obj.backoff);
                }
                if (opts.lengthDelimited !== false) {
                    w.ldelim();
                }
            }, (reader, length, opts = {}) => {
                const obj = {
                    peers: []
                };
                const end = length == null ? reader.len : reader.pos + length;
                while (reader.pos < end) {
                    const tag = reader.uint32();
                    switch (tag >>> 3) {
                        case 1: {
                            obj.topic = reader.string();
                            break;
                        }
                        case 2: {
                            if (opts.limits?.peers != null && obj.peers.length === opts.limits.peers) {
                                throw new MaxLengthError('Decode error - map field "peers" had too many elements');
                            }
                            obj.peers.push(PeerInfo.codec().decode(reader, reader.uint32(), {
                                limits: opts.limits?.peers$
                            }));
                            break;
                        }
                        case 3: {
                            obj.backoff = reader.uint64();
                            break;
                        }
                        default: {
                            reader.skipType(tag & 7);
                            break;
                        }
                    }
                }
                return obj;
            });
        }
        return _codec;
    };
    ControlPrune.encode = (obj) => {
        return encodeMessage(obj, ControlPrune.codec());
    };
    ControlPrune.decode = (buf, opts) => {
        return decodeMessage(buf, ControlPrune.codec(), opts);
    };
})(ControlPrune || (ControlPrune = {}));
export var PeerInfo;
(function (PeerInfo) {
    let _codec;
    PeerInfo.codec = () => {
        if (_codec == null) {
            _codec = message((obj, w, opts = {}) => {
                if (opts.lengthDelimited !== false) {
                    w.fork();
                }
                if (obj.peerID != null) {
                    w.uint32(10);
                    w.bytes(obj.peerID);
                }
                if (obj.signedPeerRecord != null) {
                    w.uint32(18);
                    w.bytes(obj.signedPeerRecord);
                }
                if (opts.lengthDelimited !== false) {
                    w.ldelim();
                }
            }, (reader, length, opts = {}) => {
                const obj = {};
                const end = length == null ? reader.len : reader.pos + length;
                while (reader.pos < end) {
                    const tag = reader.uint32();
                    switch (tag >>> 3) {
                        case 1: {
                            obj.peerID = reader.bytes();
                            break;
                        }
                        case 2: {
                            obj.signedPeerRecord = reader.bytes();
                            break;
                        }
                        default: {
                            reader.skipType(tag & 7);
                            break;
                        }
                    }
                }
                return obj;
            });
        }
        return _codec;
    };
    PeerInfo.encode = (obj) => {
        return encodeMessage(obj, PeerInfo.codec());
    };
    PeerInfo.decode = (buf, opts) => {
        return decodeMessage(buf, PeerInfo.codec(), opts);
    };
})(PeerInfo || (PeerInfo = {}));
//# sourceMappingURL=rpc.js.map