1+ .. _internalapi :
2+
13Internal API
24============
35
@@ -46,7 +48,6 @@ They **might** implement the following:
4648 and thus might not provide message filtering:
4749
4850
49-
5051Concrete instances are usually created by :class: `can.Bus ` which takes the users
5152configuration into account.
5253
@@ -66,19 +67,53 @@ methods:
6667
6768
6869
70+ About the IO module
71+ -------------------
72+
73+ Handling of the different file formats is implemented in :mod: `can.io `.
74+ Each file/IO type is within a separate module and ideally implements both a *Reader * and a *Writer *.
75+ The reader usually extends :class: `can.io.generic.BaseIOHandler `, while
76+ the writer often additionally extends :class: `can.Listener `,
77+ to be able to be passed directly to a :class: `can.Notifier `.
78+
79+
80+
81+ Adding support for new file formats
82+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83+
84+ This assumes that you want to add a new file format, called *canstore *.
85+ Ideally add both reading and writing support for the new file format, although this is not strictly required.
86+
87+ 1. Create a new module: *can/io/canstore.py *
88+ (*or * simply copy some existing one like *can/io/csv.py *)
89+ 2. Implement a reader ``CanstoreReader `` (which often extends :class: `can.io.generic.BaseIOHandler `, but does not have to).
90+ Besides from a constructor, only ``__iter__(self) `` needs to be implemented.
91+ 3. Implement a writer ``CanstoreWriter `` (which often extends :class: `can.io.generic.BaseIOHandler ` and :class: `can.Listener `, but does not have to).
92+ Besides from a constructor, only ``on_message_received(self, msg) `` needs to be implemented.
93+ 4. Document the two new classes (and possibly additional helpers) with docstrings and comments.
94+ Please mention features and limitations of the implementation.
95+ 5. Add a short section to the bottom of *doc/listeners.rst *.
96+ 6. Add tests where appropriate, for example by simply adding a test case called
97+ `class TestCanstoreFileFormat(ReaderWriterTest) ` to *test/logformats_test.py *.
98+ That should already handle all of the general testing.
99+ Just follow the way the other tests in there do it.
100+ 7. Add imports to *can/__init__py * and *can/io/__init__py * so that the
101+ new classes can be simply imported as *from can import CanstoreReader, CanstoreWriter *.
102+
103+
104+
69105IO Utilities
70- ------------
106+ ~~~~~~~~~~~~
71107
72108
73109.. automodule :: can.io.generic
74110 :members:
75111
76112
77113
78- Other Util
79- ----------
114+ Other Utilities
115+ ---------------
80116
81117
82118.. automodule :: can.util
83119 :members:
84-
0 commit comments