Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string DecodeMessageType(int code){
- switch(code){
- case 0: return "roomopen";
- case 1: return "roomclose";
- ///...etc
- }
- }
- int EncodeMessageType(string sCode){
- switch(sCode){
- case "roomopen": return 0;
- case "roomclose": return 1;
- ///...etc
- }
- }
- EncodeMessageType("roomopen"); //returns 0, as a 16bit int
- DecodeMessageType(0); //returns "roomopen" as string.
- //so before you send the data, Encode it to an int, and when you recieve it, before you read it decode it back to a string
- //you could even go one step further and register each message type and let it figure out the int value for it automatically, instead of having to add a new case in Decode/EncodeMessageType
- List<string> messageTypes = new List();
- void RegisterMessage(string sCode){
- messageTypes.add(sCode);
- }
- int EncodeMessageType(string sCode){
- return messageTypes.indexOf(sCode);
- }
- string DecodeMessageType(int code){
- return messageTypes[code);
- {
Advertisement
Add Comment
Please, Sign In to add comment