def handleMsg(topic,data): # Since protobuf messages are not self-defining, easiest way is to use another field to msg = loco_pb2.nb_event() msg.ParseFromString(data) msg_json = ale_pprint.msgToJSON(msg,topic=topic) print msg_json
def dumpMessage(topic,data): global countEvent global verbose msg = loco_pb2.nb_event() # Original code has the following. But don't think it's needed. # msg.Clear() msg.ParseFromString(data) msg_json = ale_pprint.msgToJSON(msg,level=1,topic=topic) # json_obj = protobuf_json.pb2json(msg) # print pprint.pprint(json_obj, depth = 4) print msg_json
def handleALEEvent(topic,data): global countEvent global config aleMsg = loco_pb2.nb_event() aleMsg.Clear() aleMsg.ParseFromString(data) #dummy print of topic and msg if verbose >= 2: print print '*** received an event pub ('+str(countEvent)+') ***' print topic msg_json = ale_pprint.msgToJSON(aleMsg,level=1,topic=topic) print msg_json return aleMsg