@@ -139,6 +139,12 @@ def __sub_interval(self, itvl):
139139 self .intervals = new
140140
141141 def __contains__ (self , other ):
142+ """Test if other is contained within self.
143+ First we compare sid they must be equals.
144+
145+ Then we search if intervals from other are contained within
146+ self intervals.
147+ """
142148 if other .sid != self .sid :
143149 return False
144150
@@ -204,6 +210,31 @@ def encoded_length(self):
204210 len (self .intervals ))
205211
206212 def encode (self ):
213+ """Encode a Gtid in binary
214+ Bytes are in **little endian**.
215+
216+ Format:
217+
218+ - sid will be uncoded as hex-binary without the dashes as a [u8; 16]
219+ - size of the interval list as a u64
220+ - all the interval as a pair: (start: u64, end: u64).
221+
222+ ## Diagram
223+
224+ ```txt
225+ Alligned on u64 bit.
226+ +-+-+-+-+-+-+-+-+-+-+
227+ | sid [16;u8] |
228+ | |
229+ +-+-+-+-+-+-+-+-+-+-+
230+ | intervals_len u64 |
231+ +-+-+-+-+-+-+-+-+-+-+
232+ |start u64 <-+
233+ - - - - - - - - - - - + Repeated
234+ |stop u64 <-+ interval_len times
235+ - - - - - - - - - - -
236+ ```
237+ """
207238 buffer = b''
208239 # sid
209240 buffer += binascii .unhexlify (self .sid .replace ('-' , '' ))
@@ -220,6 +251,10 @@ def encode(self):
220251
221252 @classmethod
222253 def decode (cls , payload ):
254+ """Decode from binary a Gtid
255+
256+ :param BytesIO payload to decode
257+ """
223258 assert isinstance (payload , BytesIO ), \
224259 'payload is expected to be a BytesIO'
225260 sid = b''
@@ -368,13 +403,33 @@ def encoded_length(self):
368403 sum (x .encoded_length for x in self .gtids ))
369404
370405 def encoded (self ):
406+ """Encode a GtidSet in binary
407+ Bytes are in **little endian**.
408+
409+ - `n_sid`: u64 is the number of Gtid to read
410+ - `Gtid`: `n_sid` * `Gtid_encoded_size` times.
411+ See`Gtid.encode` documentation for details.
412+
413+ ```txt
414+ Alligned on u64 bit.
415+ +-+-+-+-+-+-+-+-+-+-+
416+ | n_gtid u64 |
417+ +-+-+-+-+-+-+-+-+-+-+
418+ | Gtid | - Repeated n_gtid times
419+ - - - - - - - - - - -
420+ ```
421+ """
371422 return b'' + (struct .pack ('<Q' , len (self .gtids )) +
372423 b'' .join (x .encode () for x in self .gtids ))
373424
374425 encode = encoded
375426
376427 @classmethod
377428 def decode (cls , payload ):
429+ """Decode a GtidSet from binary.
430+
431+ :param BytesIO payload to decode
432+ """
378433 assert isinstance (payload , BytesIO ), \
379434 'payload is expected to be a BytesIO'
380435 (n_sid ,) = struct .unpack ('<Q' , payload .read (8 ))
0 commit comments