1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 
13 module hunt.proton.amqp.security.SaslCode;
14 
15 import hunt.proton.amqp.UnsignedByte;
16 import hunt.Enum;
17 import std.concurrency : initOnce;
18 import hunt.util.ObjectUtils;
19 class SaslCode : AbstractEnum!SaslCode
20 {
21     //__gshared SaslCode OK;
22     //__gshared SaslCode AUTH;
23     //__gshared SaslCode SYS;
24     //__gshared SaslCode SYS_PERM;
25     //__gshared SaslCode SYS_TEMP;
26 
27 
28     static SaslCode  OK() {
29         __gshared SaslCode  inst;
30         return initOnce!inst(new SaslCode("OK" , 0));
31     }
32 
33     static SaslCode  AUTH() {
34         __gshared SaslCode  inst;
35         return initOnce!inst(new SaslCode("AUTH" , 1));
36     }
37 
38     static SaslCode  SYS() {
39         __gshared SaslCode  inst;
40         return initOnce!inst(new SaslCode("SYS" , 2));
41     }
42 
43     static SaslCode  SYS_PERM() {
44         __gshared SaslCode  inst;
45         return initOnce!inst(new SaslCode("SYS_PERM" , 3));
46     }
47 
48     static SaslCode  SYS_TEMP() {
49         __gshared SaslCode  inst;
50         return initOnce!inst(new SaslCode("SYS_TEMP" , 4));
51     }
52 
53     mixin ValuesMemberTempate!(SaslCode);
54 
55     //enum {
56     //    OK = 0, AUTH, SYS, SYS_PERM, SYS_TEMP
57     //}
58 
59     this(string name ,int val)
60     {
61         super(name,val);
62     }
63 
64     //private int ordinal()
65     //{
66     //    return value;
67     //}
68     //
69     //
70     //shared static  this()
71     //{
72     //    OK = new SaslCode(0);
73     //    AUTH = new SaslCode(1);
74     //    SYS = new SaslCode(2);
75     //    SYS_PERM = new SaslCode(3);
76     //    SYS_TEMP = new SaslCode(4);
77     //}
78 
79     public UnsignedByte getValue()
80     {
81         return UnsignedByte.valueOf(cast(byte)(ordinal()));
82     }
83 
84     static SaslCode valueOf(UnsignedByte v)
85     {
86        // return SaslCode.values()[v.byteValue()];
87         switch(cast(int)v.byteValue())
88         {
89             case 0:
90                 return OK;
91             case 1:
92                 return AUTH;
93             case 2:
94                 return SYS;
95             case 3:
96                 return SYS_PERM;
97             case 4:
98                 return SYS_TEMP;
99             default:
100                 return null;
101         }
102     }
103 
104 }