Debian Codegraph @

docs/framing.rst

raw
1 .. currentmodule:: aiorpcx
2
3 Framing
4 =======
5
6 Message :dfn:`framing` is the method by which RPC messages are wrapped
7 in a byte stream so that message boundaries can be determined.
8
9 :mod:`aiorpcx` provides an abstract base class for framers, and a
10 single implementation: :class:`NewlineFramer`. A framer must know how
11 to take outgoing messages and frame them, and also how to break an
12 incoming byte stream into message frames in order to extract the RPC
13 messages from it.
14
15 .. class:: FramerBase
16
17 Derive from this class to implement your own message framing
18 methodology.
19
20 .. method:: frame(messages)
21
22 Frame each message and return the concatenated result.
23
24 :param message: an iterable; each message should be of type
25 :class:`bytes` or :class:`bytearray`
26 :return: the concatenated bytestream
27 :rtype: bytes
28
29 .. method:: messages(data)
30
31 :param data: incoming data of type :class:`bytes` or
32 :class:`bytearray`
33 :raises MemoryError: if the internal data buffer overflows
34
35 .. note:: since this may raise an exception, the caller should
36 process messages as they are yielded. Converting the
37 messages to a list will lose earlier ones if an
38 exception is raised later.
39
40
41 .. class:: NewlineFramer(max_size=1000000)
42
43 A framer where messages are delimited by an ASCII newline character in
44 a text stream. The internal buffer for partial messages will hold up
45 to *max_size* bytes.