var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { ConverterError } from '../error';
var Ipv4StringConverter = /** @class */ (function () {
    function Ipv4StringConverter() {
    }
    Ipv4StringConverter.prototype.decode = function (body) {
        var e_1, _a;
        if (body == null || body.length != 4) {
            throw ConverterError.unexpectedBufferSize(4, body);
        }
        var result = '';
        var values = Array.from(body);
        try {
            for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
                var part = values_1_1.value;
                result += part.toString() + '.';
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        return result.substr(0, result.length - 1);
    };
    Ipv4StringConverter.prototype.encode = function (ip) {
        var parts = ip.split('.');
        if (parts.length != 4) {
            throw new Error('Invalid ip format. Should be x.x.x.x');
        }
        var result = new Uint8Array(4);
        parts.map(function (value, index) {
            result[index] = parseInt(value) & 0xff;
        });
        return result;
    };
    Ipv4StringConverter.instance = function () {
        if (!Ipv4StringConverter._instance) {
            Ipv4StringConverter._instance = new Ipv4StringConverter();
        }
        return Ipv4StringConverter._instance;
    };
    Ipv4StringConverter._instance = undefined;
    return Ipv4StringConverter;
}());
export { Ipv4StringConverter };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaXB2NC1zdHJpbmctZGVjb2Rlci5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0Bpb3RpemUvdGFwL2NsaWVudC9pbXBsLyIsInNvdXJjZXMiOlsibGliL2NvbnZlcnRlci9ib2R5L2lwdjQtc3RyaW5nLWRlY29k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