Skip to content

Commit 22123ef

Browse files
author
Wasin Waeosri
committed
change log: support single fragment now
1 parent ab1477e commit 22123ef

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

mrn_prototype.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import websocket
1818
import threading
1919
from threading import Thread, Event
20+
import base64
21+
import zlib
2022

2123
# Global Default Variables
2224
hostname = '172.20.33.30'
@@ -75,10 +77,24 @@ def processUpdate(ws, message_json):
7577
frag_num = fields_data["FRAG_NUM"]
7678
guid = fields_data["GUID"]
7779
mrn_src = fields_data["MRN_SRC"]
78-
tot_size = fields_data["TOT_SIZE"]
79-
80-
# if frag_num > 1: # We are now processing more than one part of an envelope - retrieve the current details
81-
# i = 0
80+
tot_size = int(fields_data["TOT_SIZE"])
81+
try:
82+
fragment_decoded = base64.b64decode(fragment)
83+
print("GUID = %s" % guid)
84+
print("TOT_SIZE = %d" % tot_size)
85+
print("fragment length = %d" % len(fragment_decoded))
86+
# if frag_num > 1: # We are now processing more than one part of an envelope - retrieve the current details
87+
88+
if tot_size == len(fragment_decoded): # Completed News
89+
decompressed_data = zlib.decompress(
90+
fragment_decoded, zlib.MAX_WBITS | 32)
91+
print("News = %s" % decompressed_data)
92+
else:
93+
print("Multiple Fragments!!")
94+
except zlib.error as error:
95+
print(error)
96+
except:
97+
print("Error!!!")
8298

8399

84100
def processStatus(ws, message_json):

0 commit comments

Comments
 (0)