@@ -443,28 +443,19 @@ def publish(self, topic, msg, retain=False, qos=0):
443443 else :
444444 raise MMQTTException ("Invalid message data type." )
445445 if len (msg ) > MQTT_MSG_MAX_SZ :
446- raise MMQTTException ("Message size larger than %db ." % MQTT_MSG_MAX_SZ )
446+ raise MMQTTException ("Message size larger than %d bytes ." % MQTT_MSG_MAX_SZ )
447447 self ._check_qos (qos )
448448
449449 pub_hdr_fixed = bytearray (b"\x30 " )
450-
451450 pub_hdr_fixed [0 ] |= qos << 1 | retain
452- pub_hdr_fixed .append (len (msg ))
451+ pub_hdr_fixed .append (2 + len (msg ) + len ( topic ))
453452
454453 pub_hdr_var = bytearray ()
455454 pub_hdr_var .extend (b"\x00 \x17 " )
456455
457-
458- print (len (topic ))
459- print (len (msg ))
460456 remaining_length = 7 + len (msg )
461-
462457 if qos > 0 :
463458 remaining_length += 2 + len (qos )
464-
465- assert remaining_length < 2097152 # TODO: need a more descriptive error thrown here!
466-
467- """
468459 # Remaining length calculation
469460 large_rel_length = False
470461 if remaining_length > 0x7f :
@@ -480,17 +471,13 @@ def publish(self, topic, msg, retain=False, qos=0):
480471 if large_rel_length :
481472 pub_hdr_fixed .append (0x00 )
482473 else :
483- pub_hdr_fixed.append(remaining_length )
474+ pub_hdr_fixed .append (2 )
484475 pub_hdr_fixed .append (0x00 )
485476 print (pub_hdr_fixed )
486- """
487-
488-
489477
490478
491479 self ._sock .send (pub_hdr_fixed )
492480 self ._sock .send (pub_hdr_var )
493- # UP TO HERE!!
494481 self ._send_str (topic )
495482# self._sock.send(msg)
496483
0 commit comments