src/evtLink.js
function createSegment(typeKey, value) {
    // 1-byte unsigned integer
    if (typeKey <= 20) {
        return (new Buffer([ typeKey, value ]));
    }
    // 2-byte unsigned integer
    if (typeKey <= 40) {
        let content = new Buffer(3);
        content.writeUInt8(typeKey, 0);
        content.writeUInt16BE(value, 1);
        return (content);
    }
    // 4-byte unsigned integer
    else if (typeKey <= 90) {
        let content = new Buffer(5);
        content.writeUInt8(typeKey, 0);
        content.writeUInt32BE(value, 1);
        return (content);
    }
    // string
    else if (typeKey <= 155) {
        let content = Buffer.from(value);
        let header = new Buffer([ typeKey, content.length ]);
        return (Buffer.concat([ header, content ]));
    }
    // uuid
    else if (typeKey <= 165) {
        return (Buffer.concat([ new Buffer( [ typeKey ] ), value ]));
    }
    // byte string
    else if (typeKey <= 180) {
        let content = value;
        let header = new Buffer([ typeKey, content.length ]);
        return (Buffer.concat([ header, content ]));
    }
    else {
        throw new Error("typeKey not supported");
    }
}
function createSegment(typeKey, value) {
    // 1-byte unsigned integer
    if (typeKey <= 20) {
        return (new Buffer([ typeKey, value ]));
    }
    // 2-byte unsigned integer
    if (typeKey <= 40) {
        let content = new Buffer(3);
        content.writeUInt8(typeKey, 0);
        content.writeUInt16BE(value, 1);
        return (content);
    }
    // 4-byte unsigned integer
    else if (typeKey <= 90) {
        let content = new Buffer(5);
        content.writeUInt8(typeKey, 0);
        content.writeUInt32BE(value, 1);
        return (content);
    }
    // string
    else if (typeKey <= 155) {
        let content = Buffer.from(value);
        let header = new Buffer([ typeKey, content.length ]);
        return (Buffer.concat([ header, content ]));
    }
    // uuid
    else if (typeKey <= 165) {
        return (Buffer.concat([ new Buffer( [ typeKey ] ), value ]));
    }
    // byte string
    else if (typeKey <= 180) {
        let content = value;
        let header = new Buffer([ typeKey, content.length ]);
        return (Buffer.concat([ header, content ]));
    }
    else {
        throw new Error("typeKey not supported");
    }
}
function createSegment ( typeKey , value ) { // 1-byte unsigned integer if ( typeKey <= 20 ) { return ( new Buffer ( [ typeKey , value ] ) ) ; } // 2-byte unsigned integer if ( typeKey <= 40 ) { let content = new Buffer ( 3 ) ; content . writeUInt8 ( typeKey , 0 ) ; content . writeUInt16BE ( value , 1 ) ; return ( content ) ; } // 4-byte unsigned integer else if ( typeKey <= 90 ) { let content = new Buffer ( 5 ) ; content . writeUInt8 ( typeKey , 0 ) ; content . writeUInt32BE ( value , 1 ) ; return ( content ) ; } // string else if ( typeKey <= 155 ) { let content = Buffer . from ( value ) ; let header = new Buffer ( [ typeKey , content . length ] ) ; return ( Buffer . concat ( [ header , content ] ) ) ; } // uuid else if ( typeKey <= 165 ) { return ( Buffer . concat ( [ new Buffer ( [ typeKey ] ) , value ] ) ) ; } // byte string else if ( typeKey <= 180 ) { let content = value ; let header = new Buffer ( [ typeKey , content . length ] ) ; return ( Buffer . concat ( [ header , content ] ) ) ; } else { throw new Error ( "typeKey not supported" ) ; } }
create a buffer representing a segment.
Different typeKey has different data type, this is the detail:
0   - 20    1-byte unsigned integer
21  - 40    2-byte unsigned integer (BE)
41  - 90    4-byte unsigned integer (BE)
91  - 155   string
156 - 165   uuid
166 - 180   byte string
> 180      remained

@param {*} typeKey the typeKey, different key has different type and meanings (0 - 254)
@param {*} value the value, must has the right data type according to typeKey
create a buffer representing a segment . Different typeKey has different data type this is the detail : 0 - 20 1 - byte unsigned integer 21 - 40 2 - byte unsigned integer ( BE ) 41 - 90 4 - byte unsigned integer ( BE ) 91 - 155 string 156 - 165 uuid 166 - 180 byte string > 180 remained