serialize: Support serialization of “simple” types

Provide object serialization and deserialization for simple Python objects. In this case, simple means numbers (int, float, numpy arrays), strings, bytes, booleans, and non-recursive tuples, lists, sets, and dictionaries. Recursive data-structures are not checked for and thus can cause an infinite loop. Arbitrary Python objects are not allowed.

Internally use pickle, with safeguards on what is written (so the author of the code is more likely to find the bug before a user of the software does), and on what is read. The reading is more restrictive because the C-version of the pickler will pickle objects, like arbtrary functions. The deserializer catches those mistakes, but later when the session is opened.

Version 1 of the protocol supports instances of the following types:

pickle_deserialize(stream)

Recover object from a binary stream

pickle_serialize(stream, obj)

Put object in to a binary stream