Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How to convert this JavaScript code to C#? / Constants (Type) var TYPE_EUI64 = 'EUI-64'; var TYPE_RA28 = 'RA-28'; var TYPE_ADVA48 = 'ADVA-48'; var TYPE_RADIO_PAYLOAD
How to convert this JavaScript code to C#?
/ Constants (Type) | |
var TYPE_EUI64 = 'EUI-64'; | |
var TYPE_RA28 = 'RA-28'; | |
var TYPE_ADVA48 = 'ADVA-48'; | |
var TYPE_RADIO_PAYLOAD = 'RadioPayload'; | |
var TYPE_UNDEFINED = 'Undefined'; | |
// Constants | |
var REELYACTIVE_OUI36 = '001bc5094'; | |
/** | |
* Identifier Class | |
* Represents an identifier | |
* @param {string} type Type of identifier. | |
* @param {Object} value The value of the given identifier. | |
* @constructor | |
*/ | |
function Identifier(type, value) { | |
var isValue = (value != null); | |
// Constructor for EUI-64 | |
if((type == TYPE_EUI64) && isValue) { | |
this.type = TYPE_EUI64; | |
this.value = value; | |
} | |
// Constructor for RA-28 | |
else if((type == TYPE_RA28) && isValue) { | |
this.type = TYPE_RA28; | |
this.value = value.substr(value.length - 7, 7); | |
} | |
// Constructor for ADVA-48 | |
else if((type == TYPE_ADVA48) && isValue) { | |
this.type = TYPE_ADVA48; | |
this.value = value; | |
} | |
// Constructor for RadioPayload | |
else if((type = TYPE_RADIO_PAYLOAD) && isValue) { | |
this.type = TYPE_RADIO_PAYLOAD; | |
this.value = value.payload; | |
this.lengthBytes = value.payloadLengthBytes; | |
} | |
// Constructor for Undefined | |
else { | |
this.type = TYPE_UNDEFINED; | |
} | |
}; | |
/** | |
* Convert this identifier to a new one of the given type, if possible. | |
* @param {string} newType New identifier type. | |
*/ | |
Identifier.prototype.toType = function(newType) { | |
var isEUI64Target = (newType === TYPE_EUI64); | |
var isRA28Source = (this.type === TYPE_RA28); | |
if(isEUI64Target && isRA28Source) { | |
return new Identifier(TYPE_EUI64, REELYACTIVE_OUI36 + this.value); | |
} | |
return null; | |
} | |
module.exports = Identifier; | |
module.exports.EUI64 = TYPE_EUI64; | |
module.exports.RA28 = TYPE_RA28; | |
module.exports.ADVA48 = TYPE_ADVA48; | |
module.exports.RADIO_PAYLOAD = TYPE_RADIO_PAYLOAD; |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started