2017-11-25 176 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減少流量的結構已被嚴格設計,我沒有做到。 –

回答