1 /*
2  * Collie - An asynchronous event-driven network framework using Dlang development
3  *
4  * Copyright (C) 2015-2017  Shanghai Putao Technology Co., Ltd 
5  *
6  * Developer: putao's Dlang team
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 module collie.codec.mqtt.mqttversion;
12 
13 import std.array;
14 
15 class MqttVersion
16 {
17 	this(string protocolname,byte protocolLevel)
18 	{
19 		_name = protocolname;
20 		_level = protocolLevel;
21 	}
22 
23 	string protocolName()
24 	{
25 		return _name;
26 	}
27 
28 	byte protocolLevel()
29 	{
30 		return _level;
31 	}
32 
33 	static MqttVersion fromProtocolNameAndLevel(string protocolname,byte protocolLevel)
34 	{
35 		foreach(MqttVersion v; _mqtt_versions)
36 		{
37 			if(v.protocolName() == protocolname && v.protocolLevel() == protocolLevel)
38 				return v;
39 		}
40 		throw new Exception("unknown protocol name");
41 	}
42 
43 
44 private :
45 	string _name;
46 	byte _level;
47 
48 }
49 
50 __gshared  MqttVersion[] _mqtt_versions= [new MqttVersion("MQIsdp",cast(byte)3), new MqttVersion("MQTT",cast(byte)4)];