lib/packet.js
function _initialiseFromFields(userFields) {
        if (util.isDefined(userFields.MType)) {
            var MTypeNo;
            if (util.isNumber(userFields.MType)) {
                MTypeNo = userFields.MType;
            } else if (util.isString(userFields.MType)) {
                var mhdr_idx = constants.MTYPE_DESCRIPTIONS.indexOf(userFields.MType);
                if (mhdr_idx >= 0) {
                    MTypeNo = mhdr_idx;
                } else {
                    throw new Error("MType is unknown");
                }
            } else {
                throw new Error("MType is required in a suitable format");
            }

            if(MTypeNo == constants.MTYPE_JOIN_REQUEST) {
                _initialiseJoinRequestPacketFromFields(userFields);
            } else if(MTypeNo == constants.MTYPE_JOIN_ACCEPT) {
                _initialiseJoinAcceptPacketFromFields(userFields);
            } else {
                _initialiseDataPacketFromFields(userFields);
            }
        } else {
            if (_isPlausibleDataPacket(userFields) === true) {
                _initialiseDataPacketFromFields(userFields);
            } else if (_isPlausibleJoinRequestPacket(userFields) === true) {
                _initialiseJoinRequestPacketFromFields(userFields);
            } else if (_isPlausibleJoinAcceptPacket(userFields) === true) {
                _initialiseJoinAcceptPacketFromFields(userFields);
            } else {
                throw new Error("No plausible packet");
            }
        }
    }
function _initialiseFromFields(userFields) {
        if (util.isDefined(userFields.MType)) {
            var MTypeNo;
            if (util.isNumber(userFields.MType)) {
                MTypeNo = userFields.MType;
            } else if (util.isString(userFields.MType)) {
                var mhdr_idx = constants.MTYPE_DESCRIPTIONS.indexOf(userFields.MType);
                if (mhdr_idx >= 0) {
                    MTypeNo = mhdr_idx;
                } else {
                    throw new Error("MType is unknown");
                }
            } else {
                throw new Error("MType is required in a suitable format");
            }

            if(MTypeNo == constants.MTYPE_JOIN_REQUEST) {
                _initialiseJoinRequestPacketFromFields(userFields);
            } else if(MTypeNo == constants.MTYPE_JOIN_ACCEPT) {
                _initialiseJoinAcceptPacketFromFields(userFields);
            } else {
                _initialiseDataPacketFromFields(userFields);
            }
        } else {
            if (_isPlausibleDataPacket(userFields) === true) {
                _initialiseDataPacketFromFields(userFields);
            } else if (_isPlausibleJoinRequestPacket(userFields) === true) {
                _initialiseJoinRequestPacketFromFields(userFields);
            } else if (_isPlausibleJoinAcceptPacket(userFields) === true) {
                _initialiseJoinAcceptPacketFromFields(userFields);
            } else {
                throw new Error("No plausible packet");
            }
        }
    }
function _initialiseFromFields ( userFields ) { if ( util . isDefined ( userFields . MType ) ) { var MTypeNo ; if ( util . isNumber ( userFields . MType ) ) { MTypeNo = userFields . MType ; } else if ( util . isString ( userFields . MType ) ) { var mhdr_idx = constants . MTYPE_DESCRIPTIONS . indexOf ( userFields . MType ) ; if ( mhdr_idx >= 0 ) { MTypeNo = mhdr_idx ; } else { throw new Error ( "MType is unknown" ) ; } } else { throw new Error ( "MType is required in a suitable format" ) ; } if ( MTypeNo == constants . MTYPE_JOIN_REQUEST ) { _initialiseJoinRequestPacketFromFields ( userFields ) ; } else if ( MTypeNo == constants . MTYPE_JOIN_ACCEPT ) { _initialiseJoinAcceptPacketFromFields ( userFields ) ; } else { _initialiseDataPacketFromFields ( userFields ) ; } } else { if ( _isPlausibleDataPacket ( userFields ) === true ) { _initialiseDataPacketFromFields ( userFields ) ; } else if ( _isPlausibleJoinRequestPacket ( userFields ) === true ) { _initialiseJoinRequestPacketFromFields ( userFields ) ; } else if ( _isPlausibleJoinAcceptPacket ( userFields ) === true ) { _initialiseJoinAcceptPacketFromFields ( userFields ) ; } else { throw new Error ( "No plausible packet" ) ; } } }
populate anew from whatever the client gives us with defaults for the rest
populate anew from whatever the client gives us with defaults for the rest