"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var request_1 = require("../../impl/request");
var tap_stream_1 = require("../frame/tap-stream");
var IotizeLWM2MCommandConverter = /** @class */ (function () {
    function IotizeLWM2MCommandConverter() {
    }
    IotizeLWM2MCommandConverter.instance = function () {
        return new IotizeLWM2MCommandConverter();
    };
    IotizeLWM2MCommandConverter.prototype.decode = function (frame) {
        var tapRequest = tap_stream_1.TapStreamReader.fromArray(frame).readTapRequest();
        var header = new request_1.Header(tapRequest.header.path);
        return request_1.ApiRequest.create(tapRequest.header.methodType, header.getPath(), tapRequest.payload);
    };
    IotizeLWM2MCommandConverter.prototype.encode = function (command) {
        var header = command.getHeader();
        var tapRequest = {
            header: {
                path: header.path,
                methodType: command.getMethod()
            },
            payload: command.getData()
        };
        var stream = new tap_stream_1.TapStreamWriter().writeTapRequestHeader(tapRequest.header);
        if (header.resourceInstance !== undefined) {
            stream.writeU2(header.resourceInstance);
        }
        return stream
            .writeBytes(tapRequest.payload)
            .toBytes;
    };
    IotizeLWM2MCommandConverter.HEADER_LENGTH = 7;
    return IotizeLWM2MCommandConverter;
}());
exports.IotizeLWM2MCommandConverter = IotizeLWM2MCommandConverter;
