import { TwirpServer, TwirpError, TwirpErrorCode, TwirpContentType, chainInterceptors, } from 'twirp-ts';
import { AboutWhereRequest, BasicSubredditRequest, DeleteSrImgRequest, BasicSearchRequest, SearchRedditNamesResponse, SearchSubredditsResponse, SiteAdminRequest, SubmitTextResponse, SubredditAutocompleteRequest, SubredditAutocompleteResponse, SubredditStylesheetRequest, SubscribeRequest, UploadSrImgRequest, UploadSrImgResponse, SubredditPostRequirementsResponse, SubredditAboutResponse, SubredditAboutEditRequest, SubredditAboutEditResponse, SubredditAboutRulesResponse, SubredditAboutTrafficResponse, StickyRequest, StickyResponse, BasicWhereRequest, SubredditsSearchRequest, SubredditsSearchResponse, UsersSearchRequest, UserSearchResponse, SubredditAddRemovalReasonRequest, SubredditAddRemovalReasonResponse, SubredditGetRemovalReasonsRequest, SubredditGetRemovalReasonsResponse, GetHighlightedPostsRequest, GetHighlightedPostsResponse, ReorderHighlightedPostsRequest, ReorderHighlightedPostsResponse, } from './subreddits_msg.js';
import { Listing, JsonStatus } from '../common/common_msg.js';
import { Empty } from '../../../../google/protobuf/empty.js';
import { StringValue } from '../../../../google/protobuf/wrappers.js';
export var SubredditsMethod;
(function (SubredditsMethod) {
    SubredditsMethod["AboutWhere"] = "AboutWhere";
    SubredditsMethod["DeleteSrBanner"] = "DeleteSrBanner";
    SubredditsMethod["DeleteSrHeader"] = "DeleteSrHeader";
    SubredditsMethod["DeleteSrIcon"] = "DeleteSrIcon";
    SubredditsMethod["DeleteSrImg"] = "DeleteSrImg";
    SubredditsMethod["SearchRedditNames"] = "SearchRedditNames";
    SubredditsMethod["SearchSubreddits"] = "SearchSubreddits";
    SubredditsMethod["SiteAdmin"] = "SiteAdmin";
    SubredditsMethod["SubmitText"] = "SubmitText";
    SubredditsMethod["SubredditAutocomplete"] = "SubredditAutocomplete";
    SubredditsMethod["SubredditStylesheet"] = "SubredditStylesheet";
    SubredditsMethod["Subscribe"] = "Subscribe";
    SubredditsMethod["UploadSrImg"] = "UploadSrImg";
    SubredditsMethod["SubredditPostRequirements"] = "SubredditPostRequirements";
    SubredditsMethod["SubredditAbout"] = "SubredditAbout";
    SubredditsMethod["SubredditAboutEdit"] = "SubredditAboutEdit";
    SubredditsMethod["SubredditAboutRules"] = "SubredditAboutRules";
    SubredditsMethod["SubredditAboutTraffic"] = "SubredditAboutTraffic";
    SubredditsMethod["Sidebar"] = "Sidebar";
    SubredditsMethod["Sticky"] = "Sticky";
    SubredditsMethod["SubredditsMineWhere"] = "SubredditsMineWhere";
    SubredditsMethod["SubredditsSearch"] = "SubredditsSearch";
    SubredditsMethod["SubredditsWhere"] = "SubredditsWhere";
    SubredditsMethod["UsersSearch"] = "UsersSearch";
    SubredditsMethod["UsersWhere"] = "UsersWhere";
    SubredditsMethod["SubredditAddRemovalReason"] = "SubredditAddRemovalReason";
    SubredditsMethod["SubredditGetRemovalReasons"] = "SubredditGetRemovalReasons";
    SubredditsMethod["GetHighlightedPosts"] = "GetHighlightedPosts";
    SubredditsMethod["ReorderHighlightedPosts"] = "ReorderHighlightedPosts";
})(SubredditsMethod || (SubredditsMethod = {}));
export const SubredditsMethodList = [
    SubredditsMethod.AboutWhere,
    SubredditsMethod.DeleteSrBanner,
    SubredditsMethod.DeleteSrHeader,
    SubredditsMethod.DeleteSrIcon,
    SubredditsMethod.DeleteSrImg,
    SubredditsMethod.SearchRedditNames,
    SubredditsMethod.SearchSubreddits,
    SubredditsMethod.SiteAdmin,
    SubredditsMethod.SubmitText,
    SubredditsMethod.SubredditAutocomplete,
    SubredditsMethod.SubredditStylesheet,
    SubredditsMethod.Subscribe,
    SubredditsMethod.UploadSrImg,
    SubredditsMethod.SubredditPostRequirements,
    SubredditsMethod.SubredditAbout,
    SubredditsMethod.SubredditAboutEdit,
    SubredditsMethod.SubredditAboutRules,
    SubredditsMethod.SubredditAboutTraffic,
    SubredditsMethod.Sidebar,
    SubredditsMethod.Sticky,
    SubredditsMethod.SubredditsMineWhere,
    SubredditsMethod.SubredditsSearch,
    SubredditsMethod.SubredditsWhere,
    SubredditsMethod.UsersSearch,
    SubredditsMethod.UsersWhere,
    SubredditsMethod.SubredditAddRemovalReason,
    SubredditsMethod.SubredditGetRemovalReasons,
    SubredditsMethod.GetHighlightedPosts,
    SubredditsMethod.ReorderHighlightedPosts,
];
export function createSubredditsServer(service) {
    return new TwirpServer({
        service,
        packageName: 'devvit.plugin.redditapi.subreddits',
        serviceName: 'Subreddits',
        methodList: SubredditsMethodList,
        matchRoute: matchSubredditsRoute,
    });
}
function matchSubredditsRoute(method, events) {
    switch (method) {
        case 'AboutWhere':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'AboutWhere' };
                await events.onMatch(ctx);
                return handleSubredditsAboutWhereRequest(ctx, service, data, interceptors);
            };
        case 'DeleteSrBanner':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'DeleteSrBanner' };
                await events.onMatch(ctx);
                return handleSubredditsDeleteSrBannerRequest(ctx, service, data, interceptors);
            };
        case 'DeleteSrHeader':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'DeleteSrHeader' };
                await events.onMatch(ctx);
                return handleSubredditsDeleteSrHeaderRequest(ctx, service, data, interceptors);
            };
        case 'DeleteSrIcon':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'DeleteSrIcon' };
                await events.onMatch(ctx);
                return handleSubredditsDeleteSrIconRequest(ctx, service, data, interceptors);
            };
        case 'DeleteSrImg':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'DeleteSrImg' };
                await events.onMatch(ctx);
                return handleSubredditsDeleteSrImgRequest(ctx, service, data, interceptors);
            };
        case 'SearchRedditNames':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SearchRedditNames' };
                await events.onMatch(ctx);
                return handleSubredditsSearchRedditNamesRequest(ctx, service, data, interceptors);
            };
        case 'SearchSubreddits':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SearchSubreddits' };
                await events.onMatch(ctx);
                return handleSubredditsSearchSubredditsRequest(ctx, service, data, interceptors);
            };
        case 'SiteAdmin':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SiteAdmin' };
                await events.onMatch(ctx);
                return handleSubredditsSiteAdminRequest(ctx, service, data, interceptors);
            };
        case 'SubmitText':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubmitText' };
                await events.onMatch(ctx);
                return handleSubredditsSubmitTextRequest(ctx, service, data, interceptors);
            };
        case 'SubredditAutocomplete':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditAutocomplete' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditAutocompleteRequest(ctx, service, data, interceptors);
            };
        case 'SubredditStylesheet':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditStylesheet' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditStylesheetRequest(ctx, service, data, interceptors);
            };
        case 'Subscribe':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'Subscribe' };
                await events.onMatch(ctx);
                return handleSubredditsSubscribeRequest(ctx, service, data, interceptors);
            };
        case 'UploadSrImg':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'UploadSrImg' };
                await events.onMatch(ctx);
                return handleSubredditsUploadSrImgRequest(ctx, service, data, interceptors);
            };
        case 'SubredditPostRequirements':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditPostRequirements' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditPostRequirementsRequest(ctx, service, data, interceptors);
            };
        case 'SubredditAbout':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditAbout' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditAboutRequest(ctx, service, data, interceptors);
            };
        case 'SubredditAboutEdit':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditAboutEdit' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditAboutEditRequest(ctx, service, data, interceptors);
            };
        case 'SubredditAboutRules':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditAboutRules' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditAboutRulesRequest(ctx, service, data, interceptors);
            };
        case 'SubredditAboutTraffic':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditAboutTraffic' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditAboutTrafficRequest(ctx, service, data, interceptors);
            };
        case 'Sidebar':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'Sidebar' };
                await events.onMatch(ctx);
                return handleSubredditsSidebarRequest(ctx, service, data, interceptors);
            };
        case 'Sticky':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'Sticky' };
                await events.onMatch(ctx);
                return handleSubredditsStickyRequest(ctx, service, data, interceptors);
            };
        case 'SubredditsMineWhere':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditsMineWhere' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditsMineWhereRequest(ctx, service, data, interceptors);
            };
        case 'SubredditsSearch':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditsSearch' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditsSearchRequest(ctx, service, data, interceptors);
            };
        case 'SubredditsWhere':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditsWhere' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditsWhereRequest(ctx, service, data, interceptors);
            };
        case 'UsersSearch':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'UsersSearch' };
                await events.onMatch(ctx);
                return handleSubredditsUsersSearchRequest(ctx, service, data, interceptors);
            };
        case 'UsersWhere':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'UsersWhere' };
                await events.onMatch(ctx);
                return handleSubredditsUsersWhereRequest(ctx, service, data, interceptors);
            };
        case 'SubredditAddRemovalReason':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditAddRemovalReason' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditAddRemovalReasonRequest(ctx, service, data, interceptors);
            };
        case 'SubredditGetRemovalReasons':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'SubredditGetRemovalReasons' };
                await events.onMatch(ctx);
                return handleSubredditsSubredditGetRemovalReasonsRequest(ctx, service, data, interceptors);
            };
        case 'GetHighlightedPosts':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'GetHighlightedPosts' };
                await events.onMatch(ctx);
                return handleSubredditsGetHighlightedPostsRequest(ctx, service, data, interceptors);
            };
        case 'ReorderHighlightedPosts':
            return async (ctx, service, data, interceptors) => {
                ctx = { ...ctx, methodName: 'ReorderHighlightedPosts' };
                await events.onMatch(ctx);
                return handleSubredditsReorderHighlightedPostsRequest(ctx, service, data, interceptors);
            };
        default:
            events.onNotFound();
            const msg = `no handler found`;
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsAboutWhereRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsAboutWhereJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsAboutWhereProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsDeleteSrBannerRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsDeleteSrBannerJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsDeleteSrBannerProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsDeleteSrHeaderRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsDeleteSrHeaderJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsDeleteSrHeaderProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsDeleteSrIconRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsDeleteSrIconJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsDeleteSrIconProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsDeleteSrImgRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsDeleteSrImgJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsDeleteSrImgProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSearchRedditNamesRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSearchRedditNamesJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSearchRedditNamesProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSearchSubredditsRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSearchSubredditsJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSearchSubredditsProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSiteAdminRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSiteAdminJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSiteAdminProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubmitTextRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubmitTextJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubmitTextProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditAutocompleteRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditAutocompleteJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditAutocompleteProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditStylesheetRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditStylesheetJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditStylesheetProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubscribeRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubscribeJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubscribeProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsUploadSrImgRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsUploadSrImgJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsUploadSrImgProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditPostRequirementsRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditPostRequirementsJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditPostRequirementsProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditAboutRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditAboutJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditAboutProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditAboutEditRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditAboutEditJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditAboutEditProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditAboutRulesRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditAboutRulesJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditAboutRulesProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditAboutTrafficRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditAboutTrafficJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditAboutTrafficProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSidebarRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSidebarJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSidebarProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsStickyRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsStickyJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsStickyProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditsMineWhereRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditsMineWhereJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditsMineWhereProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditsSearchRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditsSearchJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditsSearchProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditsWhereRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditsWhereJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditsWhereProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsUsersSearchRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsUsersSearchJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsUsersSearchProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsUsersWhereRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsUsersWhereJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsUsersWhereProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditAddRemovalReasonRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditAddRemovalReasonJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditAddRemovalReasonProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsSubredditGetRemovalReasonsRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsSubredditGetRemovalReasonsJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsSubredditGetRemovalReasonsProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsGetHighlightedPostsRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsGetHighlightedPostsJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsGetHighlightedPostsProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
function handleSubredditsReorderHighlightedPostsRequest(ctx, service, data, interceptors) {
    switch (ctx.contentType) {
        case TwirpContentType.JSON:
            return handleSubredditsReorderHighlightedPostsJSON(ctx, service, data, interceptors);
        case TwirpContentType.Protobuf:
            return handleSubredditsReorderHighlightedPostsProtobuf(ctx, service, data, interceptors);
        default:
            const msg = 'unexpected Content-Type';
            throw new TwirpError(TwirpErrorCode.BadRoute, msg);
    }
}
async function handleSubredditsAboutWhereJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = AboutWhereRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.AboutWhere(ctx, inputReq);
        });
    }
    else {
        response = await service.AboutWhere(ctx, request);
    }
    return JSON.stringify(Listing.toJSON(response));
}
async function handleSubredditsDeleteSrBannerJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.DeleteSrBanner(ctx, inputReq);
        });
    }
    else {
        response = await service.DeleteSrBanner(ctx, request);
    }
    return JSON.stringify(JsonStatus.toJSON(response));
}
async function handleSubredditsDeleteSrHeaderJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.DeleteSrHeader(ctx, inputReq);
        });
    }
    else {
        response = await service.DeleteSrHeader(ctx, request);
    }
    return JSON.stringify(JsonStatus.toJSON(response));
}
async function handleSubredditsDeleteSrIconJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.DeleteSrIcon(ctx, inputReq);
        });
    }
    else {
        response = await service.DeleteSrIcon(ctx, request);
    }
    return JSON.stringify(JsonStatus.toJSON(response));
}
async function handleSubredditsDeleteSrImgJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = DeleteSrImgRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.DeleteSrImg(ctx, inputReq);
        });
    }
    else {
        response = await service.DeleteSrImg(ctx, request);
    }
    return JSON.stringify(JsonStatus.toJSON(response));
}
async function handleSubredditsSearchRedditNamesJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSearchRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SearchRedditNames(ctx, inputReq);
        });
    }
    else {
        response = await service.SearchRedditNames(ctx, request);
    }
    return JSON.stringify(SearchRedditNamesResponse.toJSON(response));
}
async function handleSubredditsSearchSubredditsJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSearchRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SearchSubreddits(ctx, inputReq);
        });
    }
    else {
        response = await service.SearchSubreddits(ctx, request);
    }
    return JSON.stringify(SearchSubredditsResponse.toJSON(response));
}
async function handleSubredditsSiteAdminJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = SiteAdminRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SiteAdmin(ctx, inputReq);
        });
    }
    else {
        response = await service.SiteAdmin(ctx, request);
    }
    return JSON.stringify(JsonStatus.toJSON(response));
}
async function handleSubredditsSubmitTextJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubmitText(ctx, inputReq);
        });
    }
    else {
        response = await service.SubmitText(ctx, request);
    }
    return JSON.stringify(SubmitTextResponse.toJSON(response));
}
async function handleSubredditsSubredditAutocompleteJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = SubredditAutocompleteRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAutocomplete(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAutocomplete(ctx, request);
    }
    return JSON.stringify(SubredditAutocompleteResponse.toJSON(response));
}
async function handleSubredditsSubredditStylesheetJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = SubredditStylesheetRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditStylesheet(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditStylesheet(ctx, request);
    }
    return JSON.stringify(JsonStatus.toJSON(response));
}
async function handleSubredditsSubscribeJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = SubscribeRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.Subscribe(ctx, inputReq);
        });
    }
    else {
        response = await service.Subscribe(ctx, request);
    }
    return JSON.stringify(Empty.toJSON(response));
}
async function handleSubredditsUploadSrImgJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = UploadSrImgRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.UploadSrImg(ctx, inputReq);
        });
    }
    else {
        response = await service.UploadSrImg(ctx, request);
    }
    return JSON.stringify(UploadSrImgResponse.toJSON(response));
}
async function handleSubredditsSubredditPostRequirementsJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditPostRequirements(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditPostRequirements(ctx, request);
    }
    return JSON.stringify(SubredditPostRequirementsResponse.toJSON(response));
}
async function handleSubredditsSubredditAboutJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAbout(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAbout(ctx, request);
    }
    return JSON.stringify(SubredditAboutResponse.toJSON(response));
}
async function handleSubredditsSubredditAboutEditJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = SubredditAboutEditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAboutEdit(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAboutEdit(ctx, request);
    }
    return JSON.stringify(SubredditAboutEditResponse.toJSON(response));
}
async function handleSubredditsSubredditAboutRulesJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAboutRules(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAboutRules(ctx, request);
    }
    return JSON.stringify(SubredditAboutRulesResponse.toJSON(response));
}
async function handleSubredditsSubredditAboutTrafficJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAboutTraffic(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAboutTraffic(ctx, request);
    }
    return JSON.stringify(SubredditAboutTrafficResponse.toJSON(response));
}
async function handleSubredditsSidebarJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicSubredditRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.Sidebar(ctx, inputReq);
        });
    }
    else {
        response = await service.Sidebar(ctx, request);
    }
    return JSON.stringify(StringValue.toJSON(response));
}
async function handleSubredditsStickyJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = StickyRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.Sticky(ctx, inputReq);
        });
    }
    else {
        response = await service.Sticky(ctx, request);
    }
    return JSON.stringify(StickyResponse.toJSON(response));
}
async function handleSubredditsSubredditsMineWhereJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicWhereRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditsMineWhere(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditsMineWhere(ctx, request);
    }
    return JSON.stringify(Listing.toJSON(response));
}
async function handleSubredditsSubredditsSearchJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = SubredditsSearchRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditsSearch(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditsSearch(ctx, request);
    }
    return JSON.stringify(SubredditsSearchResponse.toJSON(response));
}
async function handleSubredditsSubredditsWhereJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicWhereRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditsWhere(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditsWhere(ctx, request);
    }
    return JSON.stringify(SubredditsSearchResponse.toJSON(response));
}
async function handleSubredditsUsersSearchJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = UsersSearchRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.UsersSearch(ctx, inputReq);
        });
    }
    else {
        response = await service.UsersSearch(ctx, request);
    }
    return JSON.stringify(UserSearchResponse.toJSON(response));
}
async function handleSubredditsUsersWhereJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = BasicWhereRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.UsersWhere(ctx, inputReq);
        });
    }
    else {
        response = await service.UsersWhere(ctx, request);
    }
    return JSON.stringify(SubredditsSearchResponse.toJSON(response));
}
async function handleSubredditsSubredditAddRemovalReasonJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = SubredditAddRemovalReasonRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAddRemovalReason(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAddRemovalReason(ctx, request);
    }
    return JSON.stringify(SubredditAddRemovalReasonResponse.toJSON(response));
}
async function handleSubredditsSubredditGetRemovalReasonsJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = SubredditGetRemovalReasonsRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditGetRemovalReasons(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditGetRemovalReasons(ctx, request);
    }
    return JSON.stringify(SubredditGetRemovalReasonsResponse.toJSON(response));
}
async function handleSubredditsGetHighlightedPostsJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = GetHighlightedPostsRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.GetHighlightedPosts(ctx, inputReq);
        });
    }
    else {
        response = await service.GetHighlightedPosts(ctx, request);
    }
    return JSON.stringify(GetHighlightedPostsResponse.toJSON(response));
}
async function handleSubredditsReorderHighlightedPostsJSON(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        const body = JSON.parse(data.toString() || '{}');
        request = ReorderHighlightedPostsRequest.fromJSON(body);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the json request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.ReorderHighlightedPosts(ctx, inputReq);
        });
    }
    else {
        response = await service.ReorderHighlightedPosts(ctx, request);
    }
    return JSON.stringify(ReorderHighlightedPostsResponse.toJSON(response));
}
async function handleSubredditsAboutWhereProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = AboutWhereRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.AboutWhere(ctx, inputReq);
        });
    }
    else {
        response = await service.AboutWhere(ctx, request);
    }
    return Buffer.from(Listing.encode(response).finish());
}
async function handleSubredditsDeleteSrBannerProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.DeleteSrBanner(ctx, inputReq);
        });
    }
    else {
        response = await service.DeleteSrBanner(ctx, request);
    }
    return Buffer.from(JsonStatus.encode(response).finish());
}
async function handleSubredditsDeleteSrHeaderProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.DeleteSrHeader(ctx, inputReq);
        });
    }
    else {
        response = await service.DeleteSrHeader(ctx, request);
    }
    return Buffer.from(JsonStatus.encode(response).finish());
}
async function handleSubredditsDeleteSrIconProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.DeleteSrIcon(ctx, inputReq);
        });
    }
    else {
        response = await service.DeleteSrIcon(ctx, request);
    }
    return Buffer.from(JsonStatus.encode(response).finish());
}
async function handleSubredditsDeleteSrImgProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = DeleteSrImgRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.DeleteSrImg(ctx, inputReq);
        });
    }
    else {
        response = await service.DeleteSrImg(ctx, request);
    }
    return Buffer.from(JsonStatus.encode(response).finish());
}
async function handleSubredditsSearchRedditNamesProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSearchRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SearchRedditNames(ctx, inputReq);
        });
    }
    else {
        response = await service.SearchRedditNames(ctx, request);
    }
    return Buffer.from(SearchRedditNamesResponse.encode(response).finish());
}
async function handleSubredditsSearchSubredditsProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSearchRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SearchSubreddits(ctx, inputReq);
        });
    }
    else {
        response = await service.SearchSubreddits(ctx, request);
    }
    return Buffer.from(SearchSubredditsResponse.encode(response).finish());
}
async function handleSubredditsSiteAdminProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = SiteAdminRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SiteAdmin(ctx, inputReq);
        });
    }
    else {
        response = await service.SiteAdmin(ctx, request);
    }
    return Buffer.from(JsonStatus.encode(response).finish());
}
async function handleSubredditsSubmitTextProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubmitText(ctx, inputReq);
        });
    }
    else {
        response = await service.SubmitText(ctx, request);
    }
    return Buffer.from(SubmitTextResponse.encode(response).finish());
}
async function handleSubredditsSubredditAutocompleteProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = SubredditAutocompleteRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAutocomplete(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAutocomplete(ctx, request);
    }
    return Buffer.from(SubredditAutocompleteResponse.encode(response).finish());
}
async function handleSubredditsSubredditStylesheetProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = SubredditStylesheetRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditStylesheet(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditStylesheet(ctx, request);
    }
    return Buffer.from(JsonStatus.encode(response).finish());
}
async function handleSubredditsSubscribeProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = SubscribeRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.Subscribe(ctx, inputReq);
        });
    }
    else {
        response = await service.Subscribe(ctx, request);
    }
    return Buffer.from(Empty.encode(response).finish());
}
async function handleSubredditsUploadSrImgProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = UploadSrImgRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.UploadSrImg(ctx, inputReq);
        });
    }
    else {
        response = await service.UploadSrImg(ctx, request);
    }
    return Buffer.from(UploadSrImgResponse.encode(response).finish());
}
async function handleSubredditsSubredditPostRequirementsProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditPostRequirements(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditPostRequirements(ctx, request);
    }
    return Buffer.from(SubredditPostRequirementsResponse.encode(response).finish());
}
async function handleSubredditsSubredditAboutProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAbout(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAbout(ctx, request);
    }
    return Buffer.from(SubredditAboutResponse.encode(response).finish());
}
async function handleSubredditsSubredditAboutEditProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = SubredditAboutEditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAboutEdit(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAboutEdit(ctx, request);
    }
    return Buffer.from(SubredditAboutEditResponse.encode(response).finish());
}
async function handleSubredditsSubredditAboutRulesProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAboutRules(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAboutRules(ctx, request);
    }
    return Buffer.from(SubredditAboutRulesResponse.encode(response).finish());
}
async function handleSubredditsSubredditAboutTrafficProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAboutTraffic(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAboutTraffic(ctx, request);
    }
    return Buffer.from(SubredditAboutTrafficResponse.encode(response).finish());
}
async function handleSubredditsSidebarProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicSubredditRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.Sidebar(ctx, inputReq);
        });
    }
    else {
        response = await service.Sidebar(ctx, request);
    }
    return Buffer.from(StringValue.encode(response).finish());
}
async function handleSubredditsStickyProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = StickyRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.Sticky(ctx, inputReq);
        });
    }
    else {
        response = await service.Sticky(ctx, request);
    }
    return Buffer.from(StickyResponse.encode(response).finish());
}
async function handleSubredditsSubredditsMineWhereProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicWhereRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditsMineWhere(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditsMineWhere(ctx, request);
    }
    return Buffer.from(Listing.encode(response).finish());
}
async function handleSubredditsSubredditsSearchProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = SubredditsSearchRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditsSearch(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditsSearch(ctx, request);
    }
    return Buffer.from(SubredditsSearchResponse.encode(response).finish());
}
async function handleSubredditsSubredditsWhereProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicWhereRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditsWhere(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditsWhere(ctx, request);
    }
    return Buffer.from(SubredditsSearchResponse.encode(response).finish());
}
async function handleSubredditsUsersSearchProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = UsersSearchRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.UsersSearch(ctx, inputReq);
        });
    }
    else {
        response = await service.UsersSearch(ctx, request);
    }
    return Buffer.from(UserSearchResponse.encode(response).finish());
}
async function handleSubredditsUsersWhereProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = BasicWhereRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.UsersWhere(ctx, inputReq);
        });
    }
    else {
        response = await service.UsersWhere(ctx, request);
    }
    return Buffer.from(SubredditsSearchResponse.encode(response).finish());
}
async function handleSubredditsSubredditAddRemovalReasonProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = SubredditAddRemovalReasonRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditAddRemovalReason(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditAddRemovalReason(ctx, request);
    }
    return Buffer.from(SubredditAddRemovalReasonResponse.encode(response).finish());
}
async function handleSubredditsSubredditGetRemovalReasonsProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = SubredditGetRemovalReasonsRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.SubredditGetRemovalReasons(ctx, inputReq);
        });
    }
    else {
        response = await service.SubredditGetRemovalReasons(ctx, request);
    }
    return Buffer.from(SubredditGetRemovalReasonsResponse.encode(response).finish());
}
async function handleSubredditsGetHighlightedPostsProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = GetHighlightedPostsRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.GetHighlightedPosts(ctx, inputReq);
        });
    }
    else {
        response = await service.GetHighlightedPosts(ctx, request);
    }
    return Buffer.from(GetHighlightedPostsResponse.encode(response).finish());
}
async function handleSubredditsReorderHighlightedPostsProtobuf(ctx, service, data, interceptors) {
    let request;
    let response;
    try {
        request = ReorderHighlightedPostsRequest.decode(data);
    }
    catch (e) {
        if (e instanceof Error) {
            const msg = 'the protobuf request could not be decoded';
            throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true);
        }
    }
    if (interceptors && interceptors.length > 0) {
        const interceptor = chainInterceptors(...interceptors);
        response = await interceptor(ctx, request, (ctx, inputReq) => {
            return service.ReorderHighlightedPosts(ctx, inputReq);
        });
    }
    else {
        response = await service.ReorderHighlightedPosts(ctx, request);
    }
    return Buffer.from(ReorderHighlightedPostsResponse.encode(response).finish());
}
