开发者

unsigned char to enum

I am working on a network program and I have this code in my thread pool

unsigned char type = pdata[0];
Packet *packet = m_packetFactory->createInstance(type);

CreateInstance take an enum type to crate a packet based on the enum variable;

Client is using java and serialize the first byte like this

 final byte LOGIN_REQUEST = 1;
 .
 .
 bBuffer.put(LOGIN_REQUEST);

How do I get this in enum type so I can pass that into creat开发者_如何学运维eInstance method..Thanks in advance..


If you are sure the data is valid, simply cast it to the enum type:

enum MyEnum{
  EXAMPLE_1 = 0,
  ...
};

char type = 0;
MyEnum etype = static_cast<MyEnum>(type);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜