"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeGetCachedAppDataReq = serializeGetCachedAppDataReq;
exports.deserializeGetCachedAppDataReq = deserializeGetCachedAppDataReq;
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const cGetCachedAppDataReqVersion = 1;
function serializeGetCachedAppDataReq(stream, request, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGetCachedAppDataReq);
    }
    stream.writeUInt8(cGetCachedAppDataReqVersion);
    stream.writeString(request.topic);
    stream.writeString(request.dataId);
}
function deserializeGetCachedAppDataReq(stream) {
    const version = stream.readUInt8();
    if (version > cGetCachedAppDataReqVersion) {
        throw new Error('Unsupported version in deserializeGetCachedAppDataReq');
    }
    const topic = stream.readString();
    const dataId = stream.readString();
    const req = { topic, dataId };
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.GetCachedAppDataReq, req);
    if (errors && errors.length > 0) {
        throw new Error(`AJV: validation error -> ${errors.join(', ')}`);
    }
    return req;
}
//# sourceMappingURL=GetCachedAppDataReq.js.map