"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeSendCachedAppDataReq = exports.serializeSendCachedAppDataReq = void 0;
const CachedAppData_1 = require("./CachedAppData");
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const cSendCachedAppDataReqVersion = 1;
function serializeSendCachedAppDataReq(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cSendCachedAppDataReq);
    }
    stream.writeUInt8(cSendCachedAppDataReqVersion);
    stream.writeString(obj.topic);
    stream.writeString(obj.txId);
    stream.writeString(obj.executionShardKey);
    (0, CachedAppData_1.serializeCachedAppData)(stream, obj.cachedAppData);
}
exports.serializeSendCachedAppDataReq = serializeSendCachedAppDataReq;
function deserializeSendCachedAppDataReq(stream) {
    const version = stream.readUInt8();
    if (version > cSendCachedAppDataReqVersion) {
        throw new Error('SendCachedAppDataReq version mismatch');
    }
    const data = {
        topic: stream.readString(),
        txId: stream.readString(),
        executionShardKey: stream.readString(),
        cachedAppData: (0, CachedAppData_1.deserializeCachedAppData)(stream),
    };
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.SendCachedAppDataReq, data);
    if (errors && errors.length > 0) {
        throw new Error('AJV: SendCachedAppDataReq validation failed');
    }
    return data;
}
exports.deserializeSendCachedAppDataReq = deserializeSendCachedAppDataReq;
//# sourceMappingURL=SendCachedAppDataReq.js.map