Skip to content

Commit 7caacc2

Browse files
committed
serialization function added
1 parent daeda55 commit 7caacc2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/ugenpy/message.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def create_message(self):
5959
f = open(self.addr, 'r')
6060
md5string=''
6161
msgfile=f.read()
62+
f.close()
6263
data=msgfile.split('\n')
6364
md5string=data[0]
6465

@@ -135,6 +136,53 @@ def serialize(self, buff):
135136
buff.write(struct.pack('{}',self.{}))""".format(def_types.get(data[i].split(' ')[0]), data[i].split(' ')[1]))
136137

137138
script.write("""
139+
except Exception as e:
140+
print(e)
141+
142+
def deserialize(self, str):
143+
try:
144+
end = 0""")
145+
146+
for i in range(0,len(data)-1):
147+
temp=data[i].split(' ')[1]
148+
temppack=data[i].split(' ')[0]
149+
150+
if 'string' in temppack:
151+
script.write("""
152+
start = end
153+
end += 4
154+
(length,) = struct.unpack('<I', str[start:end])
155+
start = end
156+
end += length
157+
self.{} = str[start:end].decode('utf-8')""".format(temp))
158+
159+
elif ('bool' or 'byte' or 'char' or '8') in temppack:
160+
script.write("""
161+
start = end
162+
end += 1
163+
(self.{},) = struct.unpack('{}', str[start:end])""".format(temp, def_types.get(temppack)))
164+
165+
elif '16' in temppack:
166+
script.write("""
167+
start = end
168+
end += 2
169+
(self.{},) = struct.unpack('{}', str[start:end])""".format(temp, def_types.get(temppack)))
170+
171+
elif '32' in temppack:
172+
script.write("""
173+
start = end
174+
end += 4
175+
(self.{},) = struct.unpack('{}', str[start:end])""".format(temp, def_types.get(temppack)))
176+
177+
elif '64' in temppack:
178+
script.write("""
179+
start = end
180+
end += 8
181+
(self.{},) = struct.unpack('{}', str[start:end])""".format(temp, def_types.get(temppack)))
182+
183+
script.write("""
184+
return self
138185
except Exception as e:
139186
print(e)""")
187+
140188
script.close()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy