def generate_msg(role, msg_dict=None):
"""
See `IoT Protocol Specification`
:param msg_dict: The data dict.
:param role:
:return: Encrypted bytes
"""
logging.debug("Generating a message ...")
msg = {'proto': 'iddp',
'role': role,
'timestamp': datetime.datetime.utcnow().timestamp(),
'id': identity,
'data': msg_dict}
msg = simplejson.dumps(msg, separators=(',', ':')).encode()
return crypto.encrypt(gzip.compress(msg))[0]
评论列表
文章目录