2017-11-25 175 views
0

我有接受传入分组作为在下面的C++结构的服务器:序列化Python类C型结构(具有位填充),用于发送在插座

struct data_point 
{ 
    uint32_t type   : 8; 
    uint32_t id    : 24; 
    uint32_t timestamp_sec; 
    uint32_t timestamp_msec : 10; 
    uint32_t status   : 4; 
    uint32_t value   : 18; 
}; 

我制造一个基于Python的客户端具有以下DataPoint类:

class DataPoint : 
    def __init__(self, type, id, sec, msec, status, value) : 
     self._type = type 
     self._id = id 
     self._sec = sec 
     self._msec = msec 
     self._status = status 
     self._value = value 

我如何序列化DataPoint为二进制格式,并送过来插座用于服务器正常接受吗?

+0

你为什么不使用JSON? – yumetodo

+0

@yumetodo减少流量的结构已被严格设计,我没有做到。 –

回答