@@ -43,14 +43,6 @@ def pub(self, topic: str, metadata: str):
4343 except zmq .ZMQError as e :
4444 print (f"[ERROR] Publish error: { e } " )
4545
46- def pub_struct (self , topic : str , data : bytes ):
47- try :
48- with self .lock :
49- self .publisher .send_string (+ topic , zmq .SNDMORE )
50- self .publisher .send (data , zmq .DONTWAIT )
51- except zmq .ZMQError as e :
52- print (f"[ERROR] Publish struct error: { e } " )
53-
5446 def sub (self , topic : str , callback ):
5547 def run ():
5648 try :
@@ -62,30 +54,11 @@ def run():
6254 data_msg = subscriber .recv_string ()
6355 if topic_msg != topic :
6456 continue
65- callback (data_msg )
57+ callback (data_msg . encode (), len ( data_msg ) )
6658 except zmq .ZMQError as e :
6759 print (f"[ERROR] Exception in Sub thread for topic [{ topic } ]: { e } " )
6860
6961 thread = threading .Thread (target = run , daemon = True )
7062 thread .start ()
7163 self .sub_threads .append (thread )
7264
73- def sub_struct (self , topic : str , callback ):
74- def run ():
75- try :
76- context = zmq .Context ()
77- subscriber = context .socket (zmq .SUB )
78- subscriber .connect (self .endpoint )
79- subscriber .setsockopt_string (zmq .SUBSCRIBE , topic )
80- while True :
81- topic_msg = subscriber .recv_string ()
82- data_msg = subscriber .recv ()
83- if topic_msg != topic :
84- continue
85- callback (data_msg )
86- except zmq .ZMQError as e :
87- print (f"[ERROR] Exception in SubStruct for topic [{ topic } ]: { e } " )
88-
89- thread = threading .Thread (target = run , daemon = True )
90- thread .start ()
91- self .sub_threads .append (thread )
0 commit comments