-
Notifications
You must be signed in to change notification settings - Fork 0
/
protobuf.py
47 lines (39 loc) · 901 Bytes
/
protobuf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import chat_pb2
'''
create a protocol buffer user object
Input: string username
channel to join
output: protocol buffer object
'''
def newUser(nick, channel):
usr = chat_pb2.join()
usr.nick = nick
usr.channel = channel
return usr
'''
create a protocol buffer message object
Input: string message
output: protocol buffer object
'''
def newMsg(txt):
msg = chat_pb2.message()
msg.text = txt
return msg
'''
get protocol buffer message object from serialized message
Input: string serialized protobuf message object
output: protocol buffer message object
'''
def getMsg(serialized):
msg = chat_pb2.message()
msg.ParseFromString(serialized)
return msg
'''
get protocol buffer user object from serialized user
Input: string serialized protobuf user object
output: protocol buffer user object
'''
def getUsr(serialized):
usr = chat_pb2.join()
usr.ParseFromString(serialized)
return usr