1515
1616class FramedMessage :
1717 """
18- A complete message constructed from one or more Frames .
18+ A complete, two-part message .
1919 """
2020
2121 __slots__ = ("msg_id" , "header" , "payload" )
@@ -27,7 +27,6 @@ def __init__(self, msg_id=None, header=None, payload=None):
2727 self .header = header
2828 self .payload = payload
2929
30-
3130 def serialize (self ):
3231 h = json .dumps (self .header ).encode ("utf-8" )
3332 return b'' .join ([
@@ -39,6 +38,10 @@ def serialize(self):
3938
4039
4140class CommandMessage (FramedMessage ):
41+ """
42+ A complete, single part message, meant to encapsulate point to point
43+ commands or naive broadcasts.
44+ """
4245
4346 def serialize (self ):
4447 h = json .dumps (self .header ).encode ("utf-8" )
@@ -116,6 +119,12 @@ async def get(self):
116119
117120
118121class Frame :
122+ """
123+ A Frame represents the minimal metadata about a transmission.
124+
125+ Usually you should not create one directly, but rather use the
126+ FramedMessage or CommandMessage classes.
127+ """
119128
120129 class Types (IntEnum ):
121130 HEADER = 0
@@ -126,7 +135,6 @@ class Types(IntEnum):
126135
127136 __slots__ = ('type' , 'version' , 'length' , 'msg_id' , 'id' )
128137
129-
130138 def __init__ (self , type_ , version , length , msg_id , id_ ):
131139 self .type = type_
132140 self .version = version
@@ -164,10 +172,12 @@ def wrap(cls, data, type_=Types.PAYLOAD, msg_id=None):
164172
165173
166174def split_uuid (data ):
175+ "Splits a 128 bit int into two 64 bit words for binary encoding"
167176 return ((data >> 64 ) & MAX_INT64 , data & MAX_INT64 )
168177
169178
170179def join_uuid (hi , lo ):
180+ "Joins two 64 bit words into a 128bit int from binary encoding"
171181 return (hi << 64 ) | lo
172182
173183
0 commit comments