![]() |
PIP 5.6.1
Platform-Independent Primitives
|
PIChunkStream is a binary stream where data is stored as chunks: each chunk has an integer id and a value. Reading is id-based, so you can add or reorder fields over time and stay backward compatible: old readers ignore unknown ids, new readers can skip optional ids.
Two format versions exist (PIChunkStream::Version_1 and Version_2); the writer chooses the version, the reader detects it automatically. By default new data is written in Version_2.
Use chunk streams when:
pip_cmg emits operators that read/write via PIChunkStream and field ids (see code_model for PIMETA id and simple-stream / no-stream).For fixed, non-extensible layouts, plain PIBinaryStream operators (see Input/Output stream) are enough.
Build a PIChunkStream from a PIByteArray (read or read-write). Write with cs << cs.chunk(id, value) or add(id, value); read with read() to get the next id, then get(value). Call data() to get the byte buffer for storing or sending. Example (conceptually as in code_model output):
Generated operators for structs use the same pattern; see Code generation.