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
#!/usr/bin/python import zmq import sys import schema_pb2 import struct import time # ZeroMQ Context context = zmq.Context() # Define the socket using the "Context" sock = context.socket(zmq.SUB) sock.setsockopt(zmq.SUBSCRIBE, '') # Define subscription and messages with prefix to accept. sock.connect("tcp://10.150.2.60:7779") print "Recopilando datos del servidor..." while True: print "waiting on msg" message = sock.recv_multipart() message2 = message[1] p = schema_pb2.nb_event() p.ParseFromString(message2) print "Decoded", p