All files / ua Guid.js

100% Statements 31/31
90.91% Branches 10/11
100% Functions 5/5
100% Lines 30/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44  56x 56x   56x 56x 56x 6x 6x 96x   6x       6x 6x 6x 6x   6x 6x 6x 6x     3x 3x 3x 3x 3x 3x     3x 3x 3x 3x 3x 3x     56x  
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Bucket_1 = __importDefault(require("./Bucket"));
const parse = (s) => {
    const out = [];
    for (let i = 0; i < s.length; i += 2) {
        out.push(parseInt(s.substr(i, 2), 16));
    }
    return out;
};
class Guid {
    constructor(s) {
        s = (s !== null && s !== void 0 ? s : '00000000-0000-0000-0000-000000000000');
        const h = parse(s.replace(/-/g, ''));
        const data = new Uint8Array(h);
        const dv = new DataView(data.buffer);
        // attention! big endian
        this.Data1 = dv.getUint32(0);
        this.Data2 = dv.getUint16(4);
        this.Data3 = dv.getUint16(6);
        this.Data4 = data.subarray(8, 16);
    }
    encode() {
        const bucket = new Bucket_1.default();
        bucket.writeUint32(this.Data1);
        bucket.writeUint16(this.Data2);
        bucket.writeUint16(this.Data3);
        bucket.write(this.Data4);
        return bucket.bytes;
    }
    decode(b, position) {
        const bucket = new Bucket_1.default(b, position);
        this.Data1 = bucket.readUint32();
        this.Data2 = bucket.readUint16();
        this.Data3 = bucket.readUint16();
        this.Data4 = bucket.readN(8);
        return bucket.position;
    }
}
exports.default = Guid;