import * as _m0 from "../../../node_modules/protobufjs/minimal";
import { Struct, Value } from "../google/protobuf/struct";
import Long from "../../../node_modules/long/index";
import { map } from "../../../node_modules/rxjs/dist/types/index";
export const protobufPackage = "hermes";
export var RpcFrameType;
(function (RpcFrameType) {
    RpcFrameType[RpcFrameType["UnspecifiedRFT"] = 0] = "UnspecifiedRFT";
    RpcFrameType[RpcFrameType["Request"] = 1] = "Request";
    RpcFrameType[RpcFrameType["SuccessResponse"] = 2] = "SuccessResponse";
    RpcFrameType[RpcFrameType["ErrorResponse"] = 3] = "ErrorResponse";
    RpcFrameType[RpcFrameType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(RpcFrameType || (RpcFrameType = {}));
export function rpcFrameTypeFromJSON(object) {
    switch (object) {
        case 0:
        case "UnspecifiedRFT":
            return RpcFrameType.UnspecifiedRFT;
        case 1:
        case "Request":
            return RpcFrameType.Request;
        case 2:
        case "SuccessResponse":
            return RpcFrameType.SuccessResponse;
        case 3:
        case "ErrorResponse":
            return RpcFrameType.ErrorResponse;
        case -1:
        case "UNRECOGNIZED":
        default:
            return RpcFrameType.UNRECOGNIZED;
    }
}
export function rpcFrameTypeToJSON(object) {
    switch (object) {
        case RpcFrameType.UnspecifiedRFT:
            return "UnspecifiedRFT";
        case RpcFrameType.Request:
            return "Request";
        case RpcFrameType.SuccessResponse:
            return "SuccessResponse";
        case RpcFrameType.ErrorResponse:
            return "ErrorResponse";
        case RpcFrameType.UNRECOGNIZED:
        default:
            return "UNRECOGNIZED";
    }
}
export var ContentType;
(function (ContentType) {
    ContentType[ContentType["UnspecifiedCT"] = 0] = "UnspecifiedCT";
    ContentType[ContentType["Protobuf"] = 1] = "Protobuf";
    ContentType[ContentType["Json"] = 2] = "Json";
    ContentType[ContentType["Binary"] = 3] = "Binary";
    ContentType[ContentType["Text"] = 4] = "Text";
    ContentType[ContentType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(ContentType || (ContentType = {}));
export function contentTypeFromJSON(object) {
    switch (object) {
        case 0:
        case "UnspecifiedCT":
            return ContentType.UnspecifiedCT;
        case 1:
        case "Protobuf":
            return ContentType.Protobuf;
        case 2:
        case "Json":
            return ContentType.Json;
        case 3:
        case "Binary":
            return ContentType.Binary;
        case 4:
        case "Text":
            return ContentType.Text;
        case -1:
        case "UNRECOGNIZED":
        default:
            return ContentType.UNRECOGNIZED;
    }
}
export function contentTypeToJSON(object) {
    switch (object) {
        case ContentType.UnspecifiedCT:
            return "UnspecifiedCT";
        case ContentType.Protobuf:
            return "Protobuf";
        case ContentType.Json:
            return "Json";
        case ContentType.Binary:
            return "Binary";
        case ContentType.Text:
            return "Text";
        case ContentType.UNRECOGNIZED:
        default:
            return "UNRECOGNIZED";
    }
}
function createBaseMessageFromClient() {
    return {
        sendMessageRequest: undefined,
        firstMessage: undefined,
        ping: undefined,
        pong: undefined,
        notification: undefined,
        subscribeRequest: undefined,
    };
}
export const MessageFromClient = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.sendMessageRequest !== undefined) {
            SendMessageRequest.encode(message.sendMessageRequest, writer.uint32(10).fork()).ldelim();
        }
        if (message.firstMessage !== undefined) {
            FirstMessage.encode(message.firstMessage, writer.uint32(18).fork()).ldelim();
        }
        if (message.ping !== undefined) {
            Ping.encode(message.ping, writer.uint32(26).fork()).ldelim();
        }
        if (message.pong !== undefined) {
            Pong.encode(message.pong, writer.uint32(34).fork()).ldelim();
        }
        if (message.notification !== undefined) {
            Notification.encode(message.notification, writer.uint32(42).fork()).ldelim();
        }
        if (message.subscribeRequest !== undefined) {
            SubscribeRequest.encode(message.subscribeRequest, writer.uint32(50).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseMessageFromClient();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.sendMessageRequest = SendMessageRequest.decode(reader, reader.uint32());
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.firstMessage = FirstMessage.decode(reader, reader.uint32());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.ping = Ping.decode(reader, reader.uint32());
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.pong = Pong.decode(reader, reader.uint32());
                    continue;
                case 5:
                    if (tag !== 42) {
                        break;
                    }
                    message.notification = Notification.decode(reader, reader.uint32());
                    continue;
                case 6:
                    if (tag !== 50) {
                        break;
                    }
                    message.subscribeRequest = SubscribeRequest.decode(reader, reader.uint32());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            sendMessageRequest: isSet(object.sendMessageRequest)
                ? SendMessageRequest.fromJSON(object.sendMessageRequest)
                : undefined,
            firstMessage: isSet(object.firstMessage) ? FirstMessage.fromJSON(object.firstMessage) : undefined,
            ping: isSet(object.ping) ? Ping.fromJSON(object.ping) : undefined,
            pong: isSet(object.pong) ? Pong.fromJSON(object.pong) : undefined,
            notification: isSet(object.notification) ? Notification.fromJSON(object.notification) : undefined,
            subscribeRequest: isSet(object.subscribeRequest) ? SubscribeRequest.fromJSON(object.subscribeRequest) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.sendMessageRequest !== undefined) {
            obj.sendMessageRequest = SendMessageRequest.toJSON(message.sendMessageRequest);
        }
        if (message.firstMessage !== undefined) {
            obj.firstMessage = FirstMessage.toJSON(message.firstMessage);
        }
        if (message.ping !== undefined) {
            obj.ping = Ping.toJSON(message.ping);
        }
        if (message.pong !== undefined) {
            obj.pong = Pong.toJSON(message.pong);
        }
        if (message.notification !== undefined) {
            obj.notification = Notification.toJSON(message.notification);
        }
        if (message.subscribeRequest !== undefined) {
            obj.subscribeRequest = SubscribeRequest.toJSON(message.subscribeRequest);
        }
        return obj;
    },
    create(base) {
        return MessageFromClient.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        const message = createBaseMessageFromClient();
        message.sendMessageRequest = (object.sendMessageRequest !== undefined && object.sendMessageRequest !== null)
            ? SendMessageRequest.fromPartial(object.sendMessageRequest)
            : undefined;
        message.firstMessage = (object.firstMessage !== undefined && object.firstMessage !== null)
            ? FirstMessage.fromPartial(object.firstMessage)
            : undefined;
        message.ping = (object.ping !== undefined && object.ping !== null) ? Ping.fromPartial(object.ping) : undefined;
        message.pong = (object.pong !== undefined && object.pong !== null) ? Pong.fromPartial(object.pong) : undefined;
        message.notification = (object.notification !== undefined && object.notification !== null)
            ? Notification.fromPartial(object.notification)
            : undefined;
        message.subscribeRequest = (object.subscribeRequest !== undefined && object.subscribeRequest !== null)
            ? SubscribeRequest.fromPartial(object.subscribeRequest)
            : undefined;
        return message;
    },
};
function createBaseNotification() {
    return { message: "" };
}
export const Notification = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.message !== undefined && message.message !== "") {
            writer.uint32(10).string(message.message);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseNotification();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.message = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return { message: isSet(object.message) ? globalThis.String(object.message) : "" };
    },
    toJSON(message) {
        const obj = {};
        if (message.message !== undefined && message.message !== "") {
            obj.message = message.message;
        }
        return obj;
    },
    create(base) {
        return Notification.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a;
        const message = createBaseNotification();
        message.message = (_a = object.message) !== null && _a !== void 0 ? _a : "";
        return message;
    },
};
function createBaseMessageToClient() {
    return {
        messageEnvelope: undefined,
        sendMessageResponse: undefined,
        ping: undefined,
        pong: undefined,
        notification: undefined,
        subscribeResponse: undefined,
    };
}
export const MessageToClient = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.messageEnvelope !== undefined) {
            MessageEnvelope.encode(message.messageEnvelope, writer.uint32(10).fork()).ldelim();
        }
        if (message.sendMessageResponse !== undefined) {
            SendMessageResponse.encode(message.sendMessageResponse, writer.uint32(18).fork()).ldelim();
        }
        if (message.ping !== undefined) {
            Ping.encode(message.ping, writer.uint32(26).fork()).ldelim();
        }
        if (message.pong !== undefined) {
            Pong.encode(message.pong, writer.uint32(34).fork()).ldelim();
        }
        if (message.notification !== undefined) {
            Notification.encode(message.notification, writer.uint32(42).fork()).ldelim();
        }
        if (message.subscribeResponse !== undefined) {
            SubscribeResponse.encode(message.subscribeResponse, writer.uint32(50).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseMessageToClient();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.messageEnvelope = MessageEnvelope.decode(reader, reader.uint32());
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.sendMessageResponse = SendMessageResponse.decode(reader, reader.uint32());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.ping = Ping.decode(reader, reader.uint32());
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.pong = Pong.decode(reader, reader.uint32());
                    continue;
                case 5:
                    if (tag !== 42) {
                        break;
                    }
                    message.notification = Notification.decode(reader, reader.uint32());
                    continue;
                case 6:
                    if (tag !== 50) {
                        break;
                    }
                    message.subscribeResponse = SubscribeResponse.decode(reader, reader.uint32());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            messageEnvelope: isSet(object.messageEnvelope) ? MessageEnvelope.fromJSON(object.messageEnvelope) : undefined,
            sendMessageResponse: isSet(object.sendMessageResponse)
                ? SendMessageResponse.fromJSON(object.sendMessageResponse)
                : undefined,
            ping: isSet(object.ping) ? Ping.fromJSON(object.ping) : undefined,
            pong: isSet(object.pong) ? Pong.fromJSON(object.pong) : undefined,
            notification: isSet(object.notification) ? Notification.fromJSON(object.notification) : undefined,
            subscribeResponse: isSet(object.subscribeResponse)
                ? SubscribeResponse.fromJSON(object.subscribeResponse)
                : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.messageEnvelope !== undefined) {
            obj.messageEnvelope = MessageEnvelope.toJSON(message.messageEnvelope);
        }
        if (message.sendMessageResponse !== undefined) {
            obj.sendMessageResponse = SendMessageResponse.toJSON(message.sendMessageResponse);
        }
        if (message.ping !== undefined) {
            obj.ping = Ping.toJSON(message.ping);
        }
        if (message.pong !== undefined) {
            obj.pong = Pong.toJSON(message.pong);
        }
        if (message.notification !== undefined) {
            obj.notification = Notification.toJSON(message.notification);
        }
        if (message.subscribeResponse !== undefined) {
            obj.subscribeResponse = SubscribeResponse.toJSON(message.subscribeResponse);
        }
        return obj;
    },
    create(base) {
        return MessageToClient.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        const message = createBaseMessageToClient();
        message.messageEnvelope = (object.messageEnvelope !== undefined && object.messageEnvelope !== null)
            ? MessageEnvelope.fromPartial(object.messageEnvelope)
            : undefined;
        message.sendMessageResponse = (object.sendMessageResponse !== undefined && object.sendMessageResponse !== null)
            ? SendMessageResponse.fromPartial(object.sendMessageResponse)
            : undefined;
        message.ping = (object.ping !== undefined && object.ping !== null) ? Ping.fromPartial(object.ping) : undefined;
        message.pong = (object.pong !== undefined && object.pong !== null) ? Pong.fromPartial(object.pong) : undefined;
        message.notification = (object.notification !== undefined && object.notification !== null)
            ? Notification.fromPartial(object.notification)
            : undefined;
        message.subscribeResponse = (object.subscribeResponse !== undefined && object.subscribeResponse !== null)
            ? SubscribeResponse.fromPartial(object.subscribeResponse)
            : undefined;
        return message;
    },
};
function createBasePing() {
    return { payload: new Uint8Array(0) };
}
export const Ping = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.payload !== undefined && message.payload.length !== 0) {
            writer.uint32(10).bytes(message.payload);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBasePing();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.payload = reader.bytes();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return { payload: isSet(object.payload) ? bytesFromBase64(object.payload) : new Uint8Array(0) };
    },
    toJSON(message) {
        const obj = {};
        if (message.payload !== undefined && message.payload.length !== 0) {
            obj.payload = base64FromBytes(message.payload);
        }
        return obj;
    },
    create(base) {
        return Ping.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a;
        const message = createBasePing();
        message.payload = (_a = object.payload) !== null && _a !== void 0 ? _a : new Uint8Array(0);
        return message;
    },
};
function createBasePong() {
    return { payload: new Uint8Array(0) };
}
export const Pong = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.payload !== undefined && message.payload.length !== 0) {
            writer.uint32(10).bytes(message.payload);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBasePong();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.payload = reader.bytes();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return { payload: isSet(object.payload) ? bytesFromBase64(object.payload) : new Uint8Array(0) };
    },
    toJSON(message) {
        const obj = {};
        if (message.payload !== undefined && message.payload.length !== 0) {
            obj.payload = base64FromBytes(message.payload);
        }
        return obj;
    },
    create(base) {
        return Pong.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a;
        const message = createBasePong();
        message.payload = (_a = object.payload) !== null && _a !== void 0 ? _a : new Uint8Array(0);
        return message;
    },
};
function createBaseMessageHeader() {
    return { sender: "", contentType: 0, rpcHeader: undefined, senderSequence: 0, extraHeaders: [] };
}
export const MessageHeader = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.sender !== undefined && message.sender !== "") {
            writer.uint32(10).string(message.sender);
        }
        if (message.contentType !== undefined && message.contentType !== 0) {
            writer.uint32(16).int32(message.contentType);
        }
        if (message.rpcHeader !== undefined) {
            RpcHeader.encode(message.rpcHeader, writer.uint32(26).fork()).ldelim();
        }
        if (message.senderSequence !== undefined && message.senderSequence !== 0) {
            writer.uint32(32).int64(message.senderSequence);
        }
        if (message.extraHeaders !== undefined && message.extraHeaders.length !== 0) {
            for (const v of message.extraHeaders) {
                KeyValPair.encode(v, writer.uint32(1602).fork()).ldelim();
            }
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseMessageHeader();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.sender = reader.string();
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.contentType = reader.int32();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.rpcHeader = RpcHeader.decode(reader, reader.uint32());
                    continue;
                case 4:
                    if (tag !== 32) {
                        break;
                    }
                    message.senderSequence = longToNumber(reader.int64());
                    continue;
                case 200:
                    if (tag !== 1602) {
                        break;
                    }
                    message.extraHeaders.push(KeyValPair.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            sender: isSet(object.sender) ? globalThis.String(object.sender) : "",
            contentType: isSet(object.contentType) ? contentTypeFromJSON(object.contentType) : 0,
            rpcHeader: isSet(object.rpcHeader) ? RpcHeader.fromJSON(object.rpcHeader) : undefined,
            senderSequence: isSet(object.senderSequence) ? globalThis.Number(object.senderSequence) : 0,
            extraHeaders: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.extraHeaders)
                ? object.extraHeaders.map((e) => KeyValPair.fromJSON(e))
                : [],
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if (message.sender !== undefined && message.sender !== "") {
            obj.sender = message.sender;
        }
        if (message.contentType !== undefined && message.contentType !== 0) {
            obj.contentType = contentTypeToJSON(message.contentType);
        }
        if (message.rpcHeader !== undefined) {
            obj.rpcHeader = RpcHeader.toJSON(message.rpcHeader);
        }
        if (message.senderSequence !== undefined && message.senderSequence !== 0) {
            obj.senderSequence = Math.round(message.senderSequence);
        }
        if ((_a = message.extraHeaders) === null || _a === void 0 ? void 0 : _a.length) {
            obj.extraHeaders = message.extraHeaders.map((e) => KeyValPair.toJSON(e));
        }
        return obj;
    },
    create(base) {
        return MessageHeader.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = createBaseMessageHeader();
        message.sender = (_a = object.sender) !== null && _a !== void 0 ? _a : "";
        message.contentType = (_b = object.contentType) !== null && _b !== void 0 ? _b : 0;
        message.rpcHeader = (object.rpcHeader !== undefined && object.rpcHeader !== null)
            ? RpcHeader.fromPartial(object.rpcHeader)
            : undefined;
        message.senderSequence = (_c = object.senderSequence) !== null && _c !== void 0 ? _c : 0;
        message.extraHeaders = ((_d = object.extraHeaders) === null || _d === void 0 ? void 0 : _d.map((e) => KeyValPair.fromPartial(e))) || [];
        return message;
    },
};
function createBaseSenderEnvelope() {
    return { created: 0 };
}
export const SenderEnvelope = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.created !== undefined && message.created !== 0) {
            writer.uint32(8).int64(message.created);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSenderEnvelope();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 8) {
                        break;
                    }
                    message.created = longToNumber(reader.int64());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return { created: isSet(object.created) ? globalThis.Number(object.created) : 0 };
    },
    toJSON(message) {
        const obj = {};
        if (message.created !== undefined && message.created !== 0) {
            obj.created = Math.round(message.created);
        }
        return obj;
    },
    create(base) {
        return SenderEnvelope.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a;
        const message = createBaseSenderEnvelope();
        message.created = (_a = object.created) !== null && _a !== void 0 ? _a : 0;
        return message;
    },
};
function createBaseServerEnvelope() {
    return { sequence: 0, created: 0, channel: "", subscriptionId: "" };
}
export const ServerEnvelope = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.sequence !== undefined && message.sequence !== 0) {
            writer.uint32(8).uint64(message.sequence);
        }
        if (message.created !== undefined && message.created !== 0) {
            writer.uint32(16).int64(message.created);
        }
        if (message.channel !== undefined && message.channel !== "") {
            writer.uint32(26).string(message.channel);
        }
        if (message.subscriptionId !== undefined && message.subscriptionId !== "") {
            writer.uint32(34).string(message.subscriptionId);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseServerEnvelope();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 8) {
                        break;
                    }
                    message.sequence = longToNumber(reader.uint64());
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.created = longToNumber(reader.int64());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.channel = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.subscriptionId = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            sequence: isSet(object.sequence) ? globalThis.Number(object.sequence) : 0,
            created: isSet(object.created) ? globalThis.Number(object.created) : 0,
            channel: isSet(object.channel) ? globalThis.String(object.channel) : "",
            subscriptionId: isSet(object.subscriptionId) ? globalThis.String(object.subscriptionId) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.sequence !== undefined && message.sequence !== 0) {
            obj.sequence = Math.round(message.sequence);
        }
        if (message.created !== undefined && message.created !== 0) {
            obj.created = Math.round(message.created);
        }
        if (message.channel !== undefined && message.channel !== "") {
            obj.channel = message.channel;
        }
        if (message.subscriptionId !== undefined && message.subscriptionId !== "") {
            obj.subscriptionId = message.subscriptionId;
        }
        return obj;
    },
    create(base) {
        return ServerEnvelope.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = createBaseServerEnvelope();
        message.sequence = (_a = object.sequence) !== null && _a !== void 0 ? _a : 0;
        message.created = (_b = object.created) !== null && _b !== void 0 ? _b : 0;
        message.channel = (_c = object.channel) !== null && _c !== void 0 ? _c : "";
        message.subscriptionId = (_d = object.subscriptionId) !== null && _d !== void 0 ? _d : "";
        return message;
    },
};
function createBaseKeyValPair() {
    return { key: "", val: "" };
}
export const KeyValPair = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.key !== undefined && message.key !== "") {
            writer.uint32(10).string(message.key);
        }
        if (message.val !== undefined && message.val !== "") {
            writer.uint32(18).string(message.val);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseKeyValPair();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.key = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.val = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            key: isSet(object.key) ? globalThis.String(object.key) : "",
            val: isSet(object.val) ? globalThis.String(object.val) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.key !== undefined && message.key !== "") {
            obj.key = message.key;
        }
        if (message.val !== undefined && message.val !== "") {
            obj.val = message.val;
        }
        return obj;
    },
    create(base) {
        return KeyValPair.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b;
        const message = createBaseKeyValPair();
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : "";
        message.val = (_b = object.val) !== null && _b !== void 0 ? _b : "";
        return message;
    },
};
function createBaseRpcHeader() {
    return { correlationId: "", endPoint: "", frameType: 0, errorInfo: undefined };
}
export const RpcHeader = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.correlationId !== undefined && message.correlationId !== "") {
            writer.uint32(18).string(message.correlationId);
        }
        if (message.endPoint !== undefined && message.endPoint !== "") {
            writer.uint32(26).string(message.endPoint);
        }
        if (message.frameType !== undefined && message.frameType !== 0) {
            writer.uint32(32).int32(message.frameType);
        }
        if (message.errorInfo !== undefined) {
            RpcErrorInfo.encode(message.errorInfo, writer.uint32(42).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseRpcHeader();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.correlationId = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.endPoint = reader.string();
                    continue;
                case 4:
                    if (tag !== 32) {
                        break;
                    }
                    message.frameType = reader.int32();
                    continue;
                case 5:
                    if (tag !== 42) {
                        break;
                    }
                    message.errorInfo = RpcErrorInfo.decode(reader, reader.uint32());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            correlationId: isSet(object.correlationId) ? globalThis.String(object.correlationId) : "",
            endPoint: isSet(object.endPoint) ? globalThis.String(object.endPoint) : "",
            frameType: isSet(object.frameType) ? rpcFrameTypeFromJSON(object.frameType) : 0,
            errorInfo: isSet(object.errorInfo) ? RpcErrorInfo.fromJSON(object.errorInfo) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.correlationId !== undefined && message.correlationId !== "") {
            obj.correlationId = message.correlationId;
        }
        if (message.endPoint !== undefined && message.endPoint !== "") {
            obj.endPoint = message.endPoint;
        }
        if (message.frameType !== undefined && message.frameType !== 0) {
            obj.frameType = rpcFrameTypeToJSON(message.frameType);
        }
        if (message.errorInfo !== undefined) {
            obj.errorInfo = RpcErrorInfo.toJSON(message.errorInfo);
        }
        return obj;
    },
    create(base) {
        return RpcHeader.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = createBaseRpcHeader();
        message.correlationId = (_a = object.correlationId) !== null && _a !== void 0 ? _a : "";
        message.endPoint = (_b = object.endPoint) !== null && _b !== void 0 ? _b : "";
        message.frameType = (_c = object.frameType) !== null && _c !== void 0 ? _c : 0;
        message.errorInfo = (object.errorInfo !== undefined && object.errorInfo !== null)
            ? RpcErrorInfo.fromPartial(object.errorInfo)
            : undefined;
        return message;
    },
};
function createBaseRpcErrorInfo() {
    return { errorCode: 0, message: "", stackTrace: "" };
}
export const RpcErrorInfo = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.errorCode !== undefined && message.errorCode !== 0) {
            writer.uint32(8).uint32(message.errorCode);
        }
        if (message.message !== undefined && message.message !== "") {
            writer.uint32(18).string(message.message);
        }
        if (message.stackTrace !== undefined && message.stackTrace !== "") {
            writer.uint32(26).string(message.stackTrace);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseRpcErrorInfo();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 8) {
                        break;
                    }
                    message.errorCode = reader.uint32();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.message = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.stackTrace = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            errorCode: isSet(object.errorCode) ? globalThis.Number(object.errorCode) : 0,
            message: isSet(object.message) ? globalThis.String(object.message) : "",
            stackTrace: isSet(object.stackTrace) ? globalThis.String(object.stackTrace) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.errorCode !== undefined && message.errorCode !== 0) {
            obj.errorCode = Math.round(message.errorCode);
        }
        if (message.message !== undefined && message.message !== "") {
            obj.message = message.message;
        }
        if (message.stackTrace !== undefined && message.stackTrace !== "") {
            obj.stackTrace = message.stackTrace;
        }
        return obj;
    },
    create(base) {
        return RpcErrorInfo.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = createBaseRpcErrorInfo();
        message.errorCode = (_a = object.errorCode) !== null && _a !== void 0 ? _a : 0;
        message.message = (_b = object.message) !== null && _b !== void 0 ? _b : "";
        message.stackTrace = (_c = object.stackTrace) !== null && _c !== void 0 ? _c : "";
        return message;
    },
};
function createBaseMessage() {
    return { header: undefined, senderEnvelope: undefined, serverEnvelope: undefined, data: new Uint8Array(0) };
}
export const Message = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.header !== undefined) {
            MessageHeader.encode(message.header, writer.uint32(10).fork()).ldelim();
        }
        if (message.senderEnvelope !== undefined) {
            SenderEnvelope.encode(message.senderEnvelope, writer.uint32(18).fork()).ldelim();
        }
        if (message.serverEnvelope !== undefined) {
            ServerEnvelope.encode(message.serverEnvelope, writer.uint32(26).fork()).ldelim();
        }
        if (message.data !== undefined && message.data.length !== 0) {
            writer.uint32(34).bytes(message.data);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseMessage();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.header = MessageHeader.decode(reader, reader.uint32());
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.senderEnvelope = SenderEnvelope.decode(reader, reader.uint32());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.serverEnvelope = ServerEnvelope.decode(reader, reader.uint32());
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.data = reader.bytes();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            header: isSet(object.header) ? MessageHeader.fromJSON(object.header) : undefined,
            senderEnvelope: isSet(object.senderEnvelope) ? SenderEnvelope.fromJSON(object.senderEnvelope) : undefined,
            serverEnvelope: isSet(object.serverEnvelope) ? ServerEnvelope.fromJSON(object.serverEnvelope) : undefined,
            data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0),
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.header !== undefined) {
            obj.header = MessageHeader.toJSON(message.header);
        }
        if (message.senderEnvelope !== undefined) {
            obj.senderEnvelope = SenderEnvelope.toJSON(message.senderEnvelope);
        }
        if (message.serverEnvelope !== undefined) {
            obj.serverEnvelope = ServerEnvelope.toJSON(message.serverEnvelope);
        }
        if (message.data !== undefined && message.data.length !== 0) {
            obj.data = base64FromBytes(message.data);
        }
        return obj;
    },
    create(base) {
        return Message.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a;
        const message = createBaseMessage();
        message.header = (object.header !== undefined && object.header !== null)
            ? MessageHeader.fromPartial(object.header)
            : undefined;
        message.senderEnvelope = (object.senderEnvelope !== undefined && object.senderEnvelope !== null)
            ? SenderEnvelope.fromPartial(object.senderEnvelope)
            : undefined;
        message.serverEnvelope = (object.serverEnvelope !== undefined && object.serverEnvelope !== null)
            ? ServerEnvelope.fromPartial(object.serverEnvelope)
            : undefined;
        message.data = (_a = object.data) !== null && _a !== void 0 ? _a : new Uint8Array(0);
        return message;
    },
};
function createBaseMessageEnvelope() {
    return { messageBytes: new Uint8Array(0), serverEnvelope: undefined };
}
export const MessageEnvelope = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.messageBytes !== undefined && message.messageBytes.length !== 0) {
            writer.uint32(10).bytes(message.messageBytes);
        }
        if (message.serverEnvelope !== undefined) {
            ServerEnvelope.encode(message.serverEnvelope, writer.uint32(18).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseMessageEnvelope();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.messageBytes = reader.bytes();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.serverEnvelope = ServerEnvelope.decode(reader, reader.uint32());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            messageBytes: isSet(object.messageBytes) ? bytesFromBase64(object.messageBytes) : new Uint8Array(0),
            serverEnvelope: isSet(object.serverEnvelope) ? ServerEnvelope.fromJSON(object.serverEnvelope) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.messageBytes !== undefined && message.messageBytes.length !== 0) {
            obj.messageBytes = base64FromBytes(message.messageBytes);
        }
        if (message.serverEnvelope !== undefined) {
            obj.serverEnvelope = ServerEnvelope.toJSON(message.serverEnvelope);
        }
        return obj;
    },
    create(base) {
        return MessageEnvelope.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a;
        const message = createBaseMessageEnvelope();
        message.messageBytes = (_a = object.messageBytes) !== null && _a !== void 0 ? _a : new Uint8Array(0);
        message.serverEnvelope = (object.serverEnvelope !== undefined && object.serverEnvelope !== null)
            ? ServerEnvelope.fromPartial(object.serverEnvelope)
            : undefined;
        return message;
    },
};
function createBaseSendMessageRequest() {
    return { to: [], message: undefined, channel: "", idempotentId: "" };
}
export const SendMessageRequest = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.to !== undefined && message.to.length !== 0) {
            for (const v of message.to) {
                writer.uint32(10).string(v);
            }
        }
        if (message.message !== undefined) {
            Message.encode(message.message, writer.uint32(18).fork()).ldelim();
        }
        if (message.channel !== undefined && message.channel !== "") {
            writer.uint32(26).string(message.channel);
        }
        if (message.idempotentId !== undefined && message.idempotentId !== "") {
            writer.uint32(34).string(message.idempotentId);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSendMessageRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.to.push(reader.string());
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.message = Message.decode(reader, reader.uint32());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.channel = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.idempotentId = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            to: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.to) ? object.to.map((e) => globalThis.String(e)) : [],
            message: isSet(object.message) ? Message.fromJSON(object.message) : undefined,
            channel: isSet(object.channel) ? globalThis.String(object.channel) : "",
            idempotentId: isSet(object.idempotentId) ? globalThis.String(object.idempotentId) : "",
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if ((_a = message.to) === null || _a === void 0 ? void 0 : _a.length) {
            obj.to = message.to;
        }
        if (message.message !== undefined) {
            obj.message = Message.toJSON(message.message);
        }
        if (message.channel !== undefined && message.channel !== "") {
            obj.channel = message.channel;
        }
        if (message.idempotentId !== undefined && message.idempotentId !== "") {
            obj.idempotentId = message.idempotentId;
        }
        return obj;
    },
    create(base) {
        return SendMessageRequest.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = createBaseSendMessageRequest();
        message.to = ((_a = object.to) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
        message.message = (object.message !== undefined && object.message !== null)
            ? Message.fromPartial(object.message)
            : undefined;
        message.channel = (_b = object.channel) !== null && _b !== void 0 ? _b : "";
        message.idempotentId = (_c = object.idempotentId) !== null && _c !== void 0 ? _c : "";
        return message;
    },
};
function createBaseSendMessageResponse() {
    return { errors: [], duplicates: [], idempotentId: "", correlationId: "" };
}
export const SendMessageResponse = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.errors !== undefined && message.errors.length !== 0) {
            for (const v of message.errors) {
                SendMessageError.encode(v, writer.uint32(10).fork()).ldelim();
            }
        }
        if (message.duplicates !== undefined && message.duplicates.length !== 0) {
            for (const v of message.duplicates) {
                writer.uint32(18).string(v);
            }
        }
        if (message.idempotentId !== undefined && message.idempotentId !== "") {
            writer.uint32(26).string(message.idempotentId);
        }
        if (message.correlationId !== undefined && message.correlationId !== "") {
            writer.uint32(34).string(message.correlationId);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSendMessageResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.errors.push(SendMessageError.decode(reader, reader.uint32()));
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.duplicates.push(reader.string());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.idempotentId = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.correlationId = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            errors: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.errors)
                ? object.errors.map((e) => SendMessageError.fromJSON(e))
                : [],
            duplicates: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.duplicates)
                ? object.duplicates.map((e) => globalThis.String(e))
                : [],
            idempotentId: isSet(object.idempotentId) ? globalThis.String(object.idempotentId) : "",
            correlationId: isSet(object.correlationId) ? globalThis.String(object.correlationId) : "",
        };
    },
    toJSON(message) {
        var _a, _b;
        const obj = {};
        if ((_a = message.errors) === null || _a === void 0 ? void 0 : _a.length) {
            obj.errors = message.errors.map((e) => SendMessageError.toJSON(e));
        }
        if ((_b = message.duplicates) === null || _b === void 0 ? void 0 : _b.length) {
            obj.duplicates = message.duplicates;
        }
        if (message.idempotentId !== undefined && message.idempotentId !== "") {
            obj.idempotentId = message.idempotentId;
        }
        if (message.correlationId !== undefined && message.correlationId !== "") {
            obj.correlationId = message.correlationId;
        }
        return obj;
    },
    create(base) {
        return SendMessageResponse.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = createBaseSendMessageResponse();
        message.errors = ((_a = object.errors) === null || _a === void 0 ? void 0 : _a.map((e) => SendMessageError.fromPartial(e))) || [];
        message.duplicates = ((_b = object.duplicates) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
        message.idempotentId = (_c = object.idempotentId) !== null && _c !== void 0 ? _c : "";
        message.correlationId = (_d = object.correlationId) !== null && _d !== void 0 ? _d : "";
        return message;
    },
};
function createBaseSendReceipt() {
    return { request: undefined, response: undefined, serverEnvelope: undefined };
}
export const SendReceipt = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.request !== undefined) {
            SendMessageRequest.encode(message.request, writer.uint32(10).fork()).ldelim();
        }
        if (message.response !== undefined) {
            SendMessageResponse.encode(message.response, writer.uint32(18).fork()).ldelim();
        }
        if (message.serverEnvelope !== undefined) {
            ServerEnvelope.encode(message.serverEnvelope, writer.uint32(26).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSendReceipt();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.request = SendMessageRequest.decode(reader, reader.uint32());
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.response = SendMessageResponse.decode(reader, reader.uint32());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.serverEnvelope = ServerEnvelope.decode(reader, reader.uint32());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            request: isSet(object.request) ? SendMessageRequest.fromJSON(object.request) : undefined,
            response: isSet(object.response) ? SendMessageResponse.fromJSON(object.response) : undefined,
            serverEnvelope: isSet(object.serverEnvelope) ? ServerEnvelope.fromJSON(object.serverEnvelope) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.request !== undefined) {
            obj.request = SendMessageRequest.toJSON(message.request);
        }
        if (message.response !== undefined) {
            obj.response = SendMessageResponse.toJSON(message.response);
        }
        if (message.serverEnvelope !== undefined) {
            obj.serverEnvelope = ServerEnvelope.toJSON(message.serverEnvelope);
        }
        return obj;
    },
    create(base) {
        return SendReceipt.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        const message = createBaseSendReceipt();
        message.request = (object.request !== undefined && object.request !== null)
            ? SendMessageRequest.fromPartial(object.request)
            : undefined;
        message.response = (object.response !== undefined && object.response !== null)
            ? SendMessageResponse.fromPartial(object.response)
            : undefined;
        message.serverEnvelope = (object.serverEnvelope !== undefined && object.serverEnvelope !== null)
            ? ServerEnvelope.fromPartial(object.serverEnvelope)
            : undefined;
        return message;
    },
};
function createBaseSendMessageError() {
    return { message: "", to: "" };
}
export const SendMessageError = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.message !== undefined && message.message !== "") {
            writer.uint32(10).string(message.message);
        }
        if (message.to !== undefined && message.to !== "") {
            writer.uint32(18).string(message.to);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSendMessageError();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.message = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.to = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            message: isSet(object.message) ? globalThis.String(object.message) : "",
            to: isSet(object.to) ? globalThis.String(object.to) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.message !== undefined && message.message !== "") {
            obj.message = message.message;
        }
        if (message.to !== undefined && message.to !== "") {
            obj.to = message.to;
        }
        return obj;
    },
    create(base) {
        return SendMessageError.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b;
        const message = createBaseSendMessageError();
        message.message = (_a = object.message) !== null && _a !== void 0 ? _a : "";
        message.to = (_b = object.to) !== null && _b !== void 0 ? _b : "";
        return message;
    },
};
function createBaseFirstMessage() {
    return { senderInfo: undefined, mailboxTimeoutInMs: 0, subscriptions: [] };
}
export const FirstMessage = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.senderInfo !== undefined) {
            SenderInfo.encode(message.senderInfo, writer.uint32(10).fork()).ldelim();
        }
        if (message.mailboxTimeoutInMs !== undefined && message.mailboxTimeoutInMs !== 0) {
            writer.uint32(16).uint32(message.mailboxTimeoutInMs);
        }
        if (message.subscriptions !== undefined && message.subscriptions.length !== 0) {
            for (const v of message.subscriptions) {
                Subscription.encode(v, writer.uint32(26).fork()).ldelim();
            }
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseFirstMessage();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.senderInfo = SenderInfo.decode(reader, reader.uint32());
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.mailboxTimeoutInMs = reader.uint32();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.subscriptions.push(Subscription.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            senderInfo: isSet(object.senderInfo) ? SenderInfo.fromJSON(object.senderInfo) : undefined,
            mailboxTimeoutInMs: isSet(object.mailboxTimeoutInMs) ? globalThis.Number(object.mailboxTimeoutInMs) : 0,
            subscriptions: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.subscriptions)
                ? object.subscriptions.map((e) => Subscription.fromJSON(e))
                : [],
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if (message.senderInfo !== undefined) {
            obj.senderInfo = SenderInfo.toJSON(message.senderInfo);
        }
        if (message.mailboxTimeoutInMs !== undefined && message.mailboxTimeoutInMs !== 0) {
            obj.mailboxTimeoutInMs = Math.round(message.mailboxTimeoutInMs);
        }
        if ((_a = message.subscriptions) === null || _a === void 0 ? void 0 : _a.length) {
            obj.subscriptions = message.subscriptions.map((e) => Subscription.toJSON(e));
        }
        return obj;
    },
    create(base) {
        return FirstMessage.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b;
        const message = createBaseFirstMessage();
        message.senderInfo = (object.senderInfo !== undefined && object.senderInfo !== null)
            ? SenderInfo.fromPartial(object.senderInfo)
            : undefined;
        message.mailboxTimeoutInMs = (_a = object.mailboxTimeoutInMs) !== null && _a !== void 0 ? _a : 0;
        message.subscriptions = ((_b = object.subscriptions) === null || _b === void 0 ? void 0 : _b.map((e) => Subscription.fromPartial(e))) || [];
        return message;
    },
};
function createBaseSenderInfo() {
    return { readerKey: "", address: "" };
}
export const SenderInfo = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.readerKey !== undefined && message.readerKey !== "") {
            writer.uint32(10).string(message.readerKey);
        }
        if (message.address !== undefined && message.address !== "") {
            writer.uint32(18).string(message.address);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSenderInfo();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.readerKey = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.address = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            readerKey: isSet(object.readerKey) ? globalThis.String(object.readerKey) : "",
            address: isSet(object.address) ? globalThis.String(object.address) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.readerKey !== undefined && message.readerKey !== "") {
            obj.readerKey = message.readerKey;
        }
        if (message.address !== undefined && message.address !== "") {
            obj.address = message.address;
        }
        return obj;
    },
    create(base) {
        return SenderInfo.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b;
        const message = createBaseSenderInfo();
        message.readerKey = (_a = object.readerKey) !== null && _a !== void 0 ? _a : "";
        message.address = (_b = object.address) !== null && _b !== void 0 ? _b : "";
        return message;
    },
};
function createBaseSubscribeRequest() {
    return { subscriptions: [] };
}
export const SubscribeRequest = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.subscriptions !== undefined && message.subscriptions.length !== 0) {
            for (const v of message.subscriptions) {
                Subscription.encode(v, writer.uint32(10).fork()).ldelim();
            }
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSubscribeRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.subscriptions.push(Subscription.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            subscriptions: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.subscriptions)
                ? object.subscriptions.map((e) => Subscription.fromJSON(e))
                : [],
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if ((_a = message.subscriptions) === null || _a === void 0 ? void 0 : _a.length) {
            obj.subscriptions = message.subscriptions.map((e) => Subscription.toJSON(e));
        }
        return obj;
    },
    create(base) {
        return SubscribeRequest.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a;
        const message = createBaseSubscribeRequest();
        message.subscriptions = ((_a = object.subscriptions) === null || _a === void 0 ? void 0 : _a.map((e) => Subscription.fromPartial(e))) || [];
        return message;
    },
};
function createBaseSubscribeResponse() {
    return { succeeded: [], errors: [] };
}
export const SubscribeResponse = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.succeeded !== undefined && message.succeeded.length !== 0) {
            for (const v of message.succeeded) {
                writer.uint32(10).string(v);
            }
        }
        if (message.errors !== undefined && message.errors.length !== 0) {
            for (const v of message.errors) {
                SubscribeError.encode(v, writer.uint32(18).fork()).ldelim();
            }
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSubscribeResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.succeeded.push(reader.string());
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.errors.push(SubscribeError.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            succeeded: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.succeeded)
                ? object.succeeded.map((e) => globalThis.String(e))
                : [],
            errors: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.errors) ? object.errors.map((e) => SubscribeError.fromJSON(e)) : [],
        };
    },
    toJSON(message) {
        var _a, _b;
        const obj = {};
        if ((_a = message.succeeded) === null || _a === void 0 ? void 0 : _a.length) {
            obj.succeeded = message.succeeded;
        }
        if ((_b = message.errors) === null || _b === void 0 ? void 0 : _b.length) {
            obj.errors = message.errors.map((e) => SubscribeError.toJSON(e));
        }
        return obj;
    },
    create(base) {
        return SubscribeResponse.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b;
        const message = createBaseSubscribeResponse();
        message.succeeded = ((_a = object.succeeded) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
        message.errors = ((_b = object.errors) === null || _b === void 0 ? void 0 : _b.map((e) => SubscribeError.fromPartial(e))) || [];
        return message;
    },
};
function createBaseSubscribeError() {
    return { state: "", message: "" };
}
export const SubscribeError = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.state !== undefined && message.state !== "") {
            writer.uint32(18).string(message.state);
        }
        if (message.message !== undefined && message.message !== "") {
            writer.uint32(26).string(message.message);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSubscribeError();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.state = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.message = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            state: isSet(object.state) ? globalThis.String(object.state) : "",
            message: isSet(object.message) ? globalThis.String(object.message) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.state !== undefined && message.state !== "") {
            obj.state = message.state;
        }
        if (message.message !== undefined && message.message !== "") {
            obj.message = message.message;
        }
        return obj;
    },
    create(base) {
        return SubscribeError.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b;
        const message = createBaseSubscribeError();
        message.state = (_a = object.state) !== null && _a !== void 0 ? _a : "";
        message.message = (_b = object.message) !== null && _b !== void 0 ? _b : "";
        return message;
    },
};
function createBaseSubscription() {
    return { mailbox: undefined, nefario: undefined, changeDataCapture: undefined, unsubscribe: undefined };
}
export const Subscription = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.mailbox !== undefined) {
            MailboxSubscription.encode(message.mailbox, writer.uint32(10).fork()).ldelim();
        }
        if (message.nefario !== undefined) {
            NefarioSubscription.encode(message.nefario, writer.uint32(18).fork()).ldelim();
        }
        if (message.changeDataCapture !== undefined) {
            ChangeDataCaptureSubscription.encode(message.changeDataCapture, writer.uint32(26).fork()).ldelim();
        }
        if (message.unsubscribe !== undefined) {
            Unsubscribe.encode(message.unsubscribe, writer.uint32(34).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSubscription();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.mailbox = MailboxSubscription.decode(reader, reader.uint32());
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.nefario = NefarioSubscription.decode(reader, reader.uint32());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.changeDataCapture = ChangeDataCaptureSubscription.decode(reader, reader.uint32());
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.unsubscribe = Unsubscribe.decode(reader, reader.uint32());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            mailbox: isSet(object.mailbox) ? MailboxSubscription.fromJSON(object.mailbox) : undefined,
            nefario: isSet(object.nefario) ? NefarioSubscription.fromJSON(object.nefario) : undefined,
            changeDataCapture: isSet(object.changeDataCapture)
                ? ChangeDataCaptureSubscription.fromJSON(object.changeDataCapture)
                : undefined,
            unsubscribe: isSet(object.unsubscribe) ? Unsubscribe.fromJSON(object.unsubscribe) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.mailbox !== undefined) {
            obj.mailbox = MailboxSubscription.toJSON(message.mailbox);
        }
        if (message.nefario !== undefined) {
            obj.nefario = NefarioSubscription.toJSON(message.nefario);
        }
        if (message.changeDataCapture !== undefined) {
            obj.changeDataCapture = ChangeDataCaptureSubscription.toJSON(message.changeDataCapture);
        }
        if (message.unsubscribe !== undefined) {
            obj.unsubscribe = Unsubscribe.toJSON(message.unsubscribe);
        }
        return obj;
    },
    create(base) {
        return Subscription.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        const message = createBaseSubscription();
        message.mailbox = (object.mailbox !== undefined && object.mailbox !== null)
            ? MailboxSubscription.fromPartial(object.mailbox)
            : undefined;
        message.nefario = (object.nefario !== undefined && object.nefario !== null)
            ? NefarioSubscription.fromPartial(object.nefario)
            : undefined;
        message.changeDataCapture = (object.changeDataCapture !== undefined && object.changeDataCapture !== null)
            ? ChangeDataCaptureSubscription.fromPartial(object.changeDataCapture)
            : undefined;
        message.unsubscribe = (object.unsubscribe !== undefined && object.unsubscribe !== null)
            ? Unsubscribe.fromPartial(object.unsubscribe)
            : undefined;
        return message;
    },
};
function createBaseMailboxSubscription() {
    return { id: "", state: "", readerKey: "", channel: "", startSeq: "" };
}
export const MailboxSubscription = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.id !== undefined && message.id !== "") {
            writer.uint32(10).string(message.id);
        }
        if (message.state !== undefined && message.state !== "") {
            writer.uint32(18).string(message.state);
        }
        if (message.readerKey !== undefined && message.readerKey !== "") {
            writer.uint32(26).string(message.readerKey);
        }
        if (message.channel !== undefined && message.channel !== "") {
            writer.uint32(34).string(message.channel);
        }
        if (message.startSeq !== undefined && message.startSeq !== "") {
            writer.uint32(42).string(message.startSeq);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseMailboxSubscription();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.state = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.readerKey = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.channel = reader.string();
                    continue;
                case 5:
                    if (tag !== 42) {
                        break;
                    }
                    message.startSeq = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : "",
            state: isSet(object.state) ? globalThis.String(object.state) : "",
            readerKey: isSet(object.readerKey) ? globalThis.String(object.readerKey) : "",
            channel: isSet(object.channel) ? globalThis.String(object.channel) : "",
            startSeq: isSet(object.startSeq) ? globalThis.String(object.startSeq) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== undefined && message.id !== "") {
            obj.id = message.id;
        }
        if (message.state !== undefined && message.state !== "") {
            obj.state = message.state;
        }
        if (message.readerKey !== undefined && message.readerKey !== "") {
            obj.readerKey = message.readerKey;
        }
        if (message.channel !== undefined && message.channel !== "") {
            obj.channel = message.channel;
        }
        if (message.startSeq !== undefined && message.startSeq !== "") {
            obj.startSeq = message.startSeq;
        }
        return obj;
    },
    create(base) {
        return MailboxSubscription.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e;
        const message = createBaseMailboxSubscription();
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : "";
        message.state = (_b = object.state) !== null && _b !== void 0 ? _b : "";
        message.readerKey = (_c = object.readerKey) !== null && _c !== void 0 ? _c : "";
        message.channel = (_d = object.channel) !== null && _d !== void 0 ? _d : "";
        message.startSeq = (_e = object.startSeq) !== null && _e !== void 0 ? _e : "";
        return message;
    },
};
function createBaseChangeDataCaptureSubscription() {
    return { id: "", state: "", matchers: [], startSeq: "" };
}
export const ChangeDataCaptureSubscription = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.id !== undefined && message.id !== "") {
            writer.uint32(10).string(message.id);
        }
        if (message.state !== undefined && message.state !== "") {
            writer.uint32(18).string(message.state);
        }
        if (message.matchers !== undefined && message.matchers.length !== 0) {
            for (const v of message.matchers) {
                RecordMatcher.encode(v, writer.uint32(26).fork()).ldelim();
            }
        }
        if (message.startSeq !== undefined && message.startSeq !== "") {
            writer.uint32(34).string(message.startSeq);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseChangeDataCaptureSubscription();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.state = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.matchers.push(RecordMatcher.decode(reader, reader.uint32()));
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.startSeq = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : "",
            state: isSet(object.state) ? globalThis.String(object.state) : "",
            matchers: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.matchers)
                ? object.matchers.map((e) => RecordMatcher.fromJSON(e))
                : [],
            startSeq: isSet(object.startSeq) ? globalThis.String(object.startSeq) : "",
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if (message.id !== undefined && message.id !== "") {
            obj.id = message.id;
        }
        if (message.state !== undefined && message.state !== "") {
            obj.state = message.state;
        }
        if ((_a = message.matchers) === null || _a === void 0 ? void 0 : _a.length) {
            obj.matchers = message.matchers.map((e) => RecordMatcher.toJSON(e));
        }
        if (message.startSeq !== undefined && message.startSeq !== "") {
            obj.startSeq = message.startSeq;
        }
        return obj;
    },
    create(base) {
        return ChangeDataCaptureSubscription.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = createBaseChangeDataCaptureSubscription();
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : "";
        message.state = (_b = object.state) !== null && _b !== void 0 ? _b : "";
        message.matchers = ((_c = object.matchers) === null || _c === void 0 ? void 0 : _c.map((e) => RecordMatcher.fromPartial(e))) || [];
        message.startSeq = (_d = object.startSeq) !== null && _d !== void 0 ? _d : "";
        return message;
    },
};
function createBaseRecordMatcher() {
    return { database: "", table: "", primaryKeys: [] };
}
export const RecordMatcher = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.database !== undefined && message.database !== "") {
            writer.uint32(10).string(message.database);
        }
        if (message.table !== undefined && message.table !== "") {
            writer.uint32(18).string(message.table);
        }
        if (message.primaryKeys !== undefined && message.primaryKeys.length !== 0) {
            for (const v of message.primaryKeys) {
                Value.encode(Value.wrap(v), writer.uint32(26).fork()).ldelim();
            }
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseRecordMatcher();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.database = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.table = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.primaryKeys.push(Value.unwrap(Value.decode(reader, reader.uint32())));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            database: isSet(object.database) ? globalThis.String(object.database) : "",
            table: isSet(object.table) ? globalThis.String(object.table) : "",
            primaryKeys: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.primaryKeys) ? [...object.primaryKeys] : [],
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if (message.database !== undefined && message.database !== "") {
            obj.database = message.database;
        }
        if (message.table !== undefined && message.table !== "") {
            obj.table = message.table;
        }
        if ((_a = message.primaryKeys) === null || _a === void 0 ? void 0 : _a.length) {
            obj.primaryKeys = message.primaryKeys;
        }
        return obj;
    },
    create(base) {
        return RecordMatcher.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = createBaseRecordMatcher();
        message.database = (_a = object.database) !== null && _a !== void 0 ? _a : "";
        message.table = (_b = object.table) !== null && _b !== void 0 ? _b : "";
        message.primaryKeys = ((_c = object.primaryKeys) === null || _c === void 0 ? void 0 : _c.map((e) => e)) || [];
        return message;
    },
};
function createBaseNefarioSubscription() {
    return { id: "", state: "", processUid: "", channel: "", startSeq: "" };
}
export const NefarioSubscription = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.id !== undefined && message.id !== "") {
            writer.uint32(10).string(message.id);
        }
        if (message.state !== undefined && message.state !== "") {
            writer.uint32(18).string(message.state);
        }
        if (message.processUid !== undefined && message.processUid !== "") {
            writer.uint32(26).string(message.processUid);
        }
        if (message.channel !== undefined && message.channel !== "") {
            writer.uint32(34).string(message.channel);
        }
        if (message.startSeq !== undefined && message.startSeq !== "") {
            writer.uint32(42).string(message.startSeq);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseNefarioSubscription();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.state = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.processUid = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.channel = reader.string();
                    continue;
                case 5:
                    if (tag !== 42) {
                        break;
                    }
                    message.startSeq = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : "",
            state: isSet(object.state) ? globalThis.String(object.state) : "",
            processUid: isSet(object.processUid) ? globalThis.String(object.processUid) : "",
            channel: isSet(object.channel) ? globalThis.String(object.channel) : "",
            startSeq: isSet(object.startSeq) ? globalThis.String(object.startSeq) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== undefined && message.id !== "") {
            obj.id = message.id;
        }
        if (message.state !== undefined && message.state !== "") {
            obj.state = message.state;
        }
        if (message.processUid !== undefined && message.processUid !== "") {
            obj.processUid = message.processUid;
        }
        if (message.channel !== undefined && message.channel !== "") {
            obj.channel = message.channel;
        }
        if (message.startSeq !== undefined && message.startSeq !== "") {
            obj.startSeq = message.startSeq;
        }
        return obj;
    },
    create(base) {
        return NefarioSubscription.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e;
        const message = createBaseNefarioSubscription();
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : "";
        message.state = (_b = object.state) !== null && _b !== void 0 ? _b : "";
        message.processUid = (_c = object.processUid) !== null && _c !== void 0 ? _c : "";
        message.channel = (_d = object.channel) !== null && _d !== void 0 ? _d : "";
        message.startSeq = (_e = object.startSeq) !== null && _e !== void 0 ? _e : "";
        return message;
    },
};
function createBaseUnsubscribe() {
    return { id: "" };
}
export const Unsubscribe = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.id !== undefined && message.id !== "") {
            writer.uint32(10).string(message.id);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseUnsubscribe();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== undefined && message.id !== "") {
            obj.id = message.id;
        }
        return obj;
    },
    create(base) {
        return Unsubscribe.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a;
        const message = createBaseUnsubscribe();
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : "";
        return message;
    },
};
function createBaseCreateMailboxRequest() {
    return {
        channels: [],
        privateMetadata: undefined,
        publicMetadata: undefined,
        purgeTimeoutInMillis: 0,
        closeTimeoutInMillis: 0,
        extraData: undefined,
    };
}
export const CreateMailboxRequest = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.channels !== undefined && message.channels.length !== 0) {
            for (const v of message.channels) {
                writer.uint32(10).string(v);
            }
        }
        if (message.privateMetadata !== undefined) {
            Struct.encode(Struct.wrap(message.privateMetadata), writer.uint32(18).fork()).ldelim();
        }
        if (message.publicMetadata !== undefined) {
            Struct.encode(Struct.wrap(message.publicMetadata), writer.uint32(26).fork()).ldelim();
        }
        if (message.purgeTimeoutInMillis !== undefined && message.purgeTimeoutInMillis !== 0) {
            writer.uint32(32).int64(message.purgeTimeoutInMillis);
        }
        if (message.closeTimeoutInMillis !== undefined && message.closeTimeoutInMillis !== 0) {
            writer.uint32(40).int64(message.closeTimeoutInMillis);
        }
        if (message.extraData !== undefined) {
            Struct.encode(Struct.wrap(message.extraData), writer.uint32(50).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseCreateMailboxRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.channels.push(reader.string());
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.privateMetadata = Struct.unwrap(Struct.decode(reader, reader.uint32()));
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.publicMetadata = Struct.unwrap(Struct.decode(reader, reader.uint32()));
                    continue;
                case 4:
                    if (tag !== 32) {
                        break;
                    }
                    message.purgeTimeoutInMillis = longToNumber(reader.int64());
                    continue;
                case 5:
                    if (tag !== 40) {
                        break;
                    }
                    message.closeTimeoutInMillis = longToNumber(reader.int64());
                    continue;
                case 6:
                    if (tag !== 50) {
                        break;
                    }
                    message.extraData = Struct.unwrap(Struct.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            channels: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.channels) ? object.channels.map((e) => globalThis.String(e)) : [],
            privateMetadata: isObject(object.privateMetadata) ? object.privateMetadata : undefined,
            publicMetadata: isObject(object.publicMetadata) ? object.publicMetadata : undefined,
            purgeTimeoutInMillis: isSet(object.purgeTimeoutInMillis) ? globalThis.Number(object.purgeTimeoutInMillis) : 0,
            closeTimeoutInMillis: isSet(object.closeTimeoutInMillis) ? globalThis.Number(object.closeTimeoutInMillis) : 0,
            extraData: isObject(object.extraData) ? object.extraData : undefined,
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if ((_a = message.channels) === null || _a === void 0 ? void 0 : _a.length) {
            obj.channels = message.channels;
        }
        if (message.privateMetadata !== undefined) {
            obj.privateMetadata = message.privateMetadata;
        }
        if (message.publicMetadata !== undefined) {
            obj.publicMetadata = message.publicMetadata;
        }
        if (message.purgeTimeoutInMillis !== undefined && message.purgeTimeoutInMillis !== 0) {
            obj.purgeTimeoutInMillis = Math.round(message.purgeTimeoutInMillis);
        }
        if (message.closeTimeoutInMillis !== undefined && message.closeTimeoutInMillis !== 0) {
            obj.closeTimeoutInMillis = Math.round(message.closeTimeoutInMillis);
        }
        if (message.extraData !== undefined) {
            obj.extraData = message.extraData;
        }
        return obj;
    },
    create(base) {
        return CreateMailboxRequest.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f;
        const message = createBaseCreateMailboxRequest();
        message.channels = ((_a = object.channels) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
        message.privateMetadata = (_b = object.privateMetadata) !== null && _b !== void 0 ? _b : undefined;
        message.publicMetadata = (_c = object.publicMetadata) !== null && _c !== void 0 ? _c : undefined;
        message.purgeTimeoutInMillis = (_d = object.purgeTimeoutInMillis) !== null && _d !== void 0 ? _d : 0;
        message.closeTimeoutInMillis = (_e = object.closeTimeoutInMillis) !== null && _e !== void 0 ? _e : 0;
        message.extraData = (_f = object.extraData) !== null && _f !== void 0 ? _f : undefined;
        return message;
    },
};
function createBaseCreateMailboxResponse() {
    return { adminKey: "", address: "", readerKey: "", channels: [] };
}
export const CreateMailboxResponse = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.adminKey !== undefined && message.adminKey !== "") {
            writer.uint32(10).string(message.adminKey);
        }
        if (message.address !== undefined && message.address !== "") {
            writer.uint32(18).string(message.address);
        }
        if (message.readerKey !== undefined && message.readerKey !== "") {
            writer.uint32(26).string(message.readerKey);
        }
        if (message.channels !== undefined && message.channels.length !== 0) {
            for (const v of message.channels) {
                writer.uint32(34).string(v);
            }
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseCreateMailboxResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.adminKey = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.address = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.readerKey = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.channels.push(reader.string());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            adminKey: isSet(object.adminKey) ? globalThis.String(object.adminKey) : "",
            address: isSet(object.address) ? globalThis.String(object.address) : "",
            readerKey: isSet(object.readerKey) ? globalThis.String(object.readerKey) : "",
            channels: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.channels) ? object.channels.map((e) => globalThis.String(e)) : [],
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if (message.adminKey !== undefined && message.adminKey !== "") {
            obj.adminKey = message.adminKey;
        }
        if (message.address !== undefined && message.address !== "") {
            obj.address = message.address;
        }
        if (message.readerKey !== undefined && message.readerKey !== "") {
            obj.readerKey = message.readerKey;
        }
        if ((_a = message.channels) === null || _a === void 0 ? void 0 : _a.length) {
            obj.channels = message.channels;
        }
        return obj;
    },
    create(base) {
        return CreateMailboxResponse.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b, _c, _d;
        const message = createBaseCreateMailboxResponse();
        message.adminKey = (_a = object.adminKey) !== null && _a !== void 0 ? _a : "";
        message.address = (_b = object.address) !== null && _b !== void 0 ? _b : "";
        message.readerKey = (_c = object.readerKey) !== null && _c !== void 0 ? _c : "";
        message.channels = ((_d = object.channels) === null || _d === void 0 ? void 0 : _d.map((e) => e)) || [];
        return message;
    },
};
function createBaseAddChannelRequest() {
    return { adminKey: "", channels: [] };
}
export const AddChannelRequest = {
    encode(message, writer = _m0.Writer.create()) {
        if (message.adminKey !== undefined && message.adminKey !== "") {
            writer.uint32(10).string(message.adminKey);
        }
        if (message.channels !== undefined && message.channels.length !== 0) {
            for (const v of message.channels) {
                writer.uint32(18).string(v);
            }
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseAddChannelRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.adminKey = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.channels.push(reader.string());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            adminKey: isSet(object.adminKey) ? globalThis.String(object.adminKey) : "",
            channels: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.channels) ? object.channels.map((e) => globalThis.String(e)) : [],
        };
    },
    toJSON(message) {
        var _a;
        const obj = {};
        if (message.adminKey !== undefined && message.adminKey !== "") {
            obj.adminKey = message.adminKey;
        }
        if ((_a = message.channels) === null || _a === void 0 ? void 0 : _a.length) {
            obj.channels = message.channels;
        }
        return obj;
    },
    create(base) {
        return AddChannelRequest.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(object) {
        var _a, _b;
        const message = createBaseAddChannelRequest();
        message.adminKey = (_a = object.adminKey) !== null && _a !== void 0 ? _a : "";
        message.channels = ((_b = object.channels) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
        return message;
    },
};
function createBaseAddChannelResponse() {
    return {};
}
export const AddChannelResponse = {
    encode(_, writer = _m0.Writer.create()) {
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseAddChannelResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(_) {
        return {};
    },
    toJSON(_) {
        const obj = {};
        return obj;
    },
    create(base) {
        return AddChannelResponse.fromPartial(base !== null && base !== void 0 ? base : {});
    },
    fromPartial(_) {
        const message = createBaseAddChannelResponse();
        return message;
    },
};
export const HermesServiceServiceName = "hermes.HermesService";
export class HermesServiceClientImpl {
    constructor(rpc, opts) {
        this.service = (opts === null || opts === void 0 ? void 0 : opts.service) || HermesServiceServiceName;
        this.rpc = rpc;
        this.SendReceive = this.SendReceive.bind(this);
        this.CreateMailbox = this.CreateMailbox.bind(this);
        this.AddChannel = this.AddChannel.bind(this);
    }
    SendReceive(request) {
        const data = request.pipe(map((request) => MessageFromClient.encode(request).finish()));
        const result = this.rpc.bidirectionalStreamingRequest(this.service, "SendReceive", data);
        return result.pipe(map((data) => MessageToClient.decode(_m0.Reader.create(data))));
    }
    CreateMailbox(request) {
        const data = CreateMailboxRequest.encode(request).finish();
        const promise = this.rpc.request(this.service, "CreateMailbox", data);
        return promise.then((data) => CreateMailboxResponse.decode(_m0.Reader.create(data)));
    }
    AddChannel(request) {
        const data = AddChannelRequest.encode(request).finish();
        const promise = this.rpc.request(this.service, "AddChannel", data);
        return promise.then((data) => AddChannelResponse.decode(_m0.Reader.create(data)));
    }
}
function bytesFromBase64(b64) {
    if (globalThis.Buffer) {
        return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
    }
    else {
        const bin = globalThis.atob(b64);
        const arr = new Uint8Array(bin.length);
        for (let i = 0; i < bin.length; ++i) {
            arr[i] = bin.charCodeAt(i);
        }
        return arr;
    }
}
function base64FromBytes(arr) {
    if (globalThis.Buffer) {
        return globalThis.Buffer.from(arr).toString("base64");
    }
    else {
        const bin = [];
        arr.forEach((byte) => {
            bin.push(globalThis.String.fromCharCode(byte));
        });
        return globalThis.btoa(bin.join(""));
    }
}
function longToNumber(long) {
    if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
        throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
    }
    return long.toNumber();
}
if (_m0.util.Long !== Long) {
    _m0.util.Long = Long;
    _m0.configure();
}
function isObject(value) {
    return typeof value === "object" && value !== null;
}
function isSet(value) {
    return value !== null && value !== undefined;
}
