PIP 5.6.1
Platform-Independent Primitives
Input/Output stream

PIBinaryStream is the binary serialization interface. For versioned, extensible formats with chunk ids see Chunk stream and versioned serialization. It is not used standalone; only as a mixin or via concrete classes such as PIByteArray and PIIOBinaryStream. Use it to save or load any data. Trivial types are read/written as memory blocks unless custom operators are defined; non-trivial types must have stream operators or the code will not compile. Containers are supported under the same rules. Enums are treated as int, bool as one byte. Write operators append to the stream; read operators consume from the beginning. Macros: BINARY_STREAM_FRIEND(T), BINARY_STREAM_WRITE(T), BINARY_STREAM_READ(T) (inside them s is the stream, v is the value).

Result:

For store/restore custom data blocks this is PIMemoryBlock class. Stream operators of this class simply store/restore data block to/from stream:

Result:

If a read runs out of data (e.g. end of array or file), the stream's wasReadError() returns true. Check it after reads to handle errors correctly.