2
This module implements a simple tuple transmission protocol. It's kept simple
3
to be implementable in other languages as well.
5
The protocol can only transmit lists of strings, which it splits up into chunks.
6
A chunk consists of a LENGTH byte, the actual PAYLOAD, and a STATUS byte.
8
A single string is split up into several chunks if it exceeds the maximum length
9
which can be specified by the LENGTH byte (255), otherwise a string is one
12
The STATUS byte after every chunk tells if the chunk is
14
- continued in the next chunk (CONT)
15
- the last chunk of a string (NEXT)
16
- the last chunk in the transmission (END)
18
In order to handle empty lists without getting too complicated, all lists are
19
extended by an arbitrary first element which just gets ignored.
24
["Hello", "World!"] is transmitted as:
26
01 00 01 05 48 65 6C 6C 6F 01 06 57 6F 72 6C 64 21 02
28
(1) ? NEXT (5) H e l l o NEXT (6) W o r l d ! END
32
class XDRError(RuntimeError):
36
_SEND_ERROR = "--SEND ERROR--"
46
args = ["\0"] + list(args)
50
chunks = [ a[i:i + 0xff] for i in range(0, len(a), 0xff) ]
55
if (chunks): s.send(_CONT)
57
if (args): s.send(_NEXT)
73
length = ord(s.recv(1))
77
if (length): chunk += s.recv(length)
80
if (flag == _CONT): continue
85
if (flag == _END): break