leverage lazy bytestring for 'Serialise' CBOR-in-CBOR.
Description
The main use case for this type lies within the StateQuery protocol, where it can be particularly useful to obtain a plain CBOR response. This is particularly useful for large query results such as DebugNewEpochState (multiple GB on mainnet). The network library makes a great effort at trying to serialise and deserialise bytes lazily throughout; and these efforts are unfortunately destroyed by this implementation that would here evaluate the entire ByteString when decoding and encoding. So on a machine that would have both a server and client using this library, we would pay twice the cost of fully evaluating in memory the entire response, instead of leverage lazy IO as, I believe, is originally intended.
Note that 'decode' and 'encode' here rely on the default implementation for lazy ByteString in Codec.Serialise, which do the right thing: encode lazy bytestrings as indefinite sequences of byte chunks; effectively preserving the laziness in both directions.
Checklist
Quality
- [x] Commit sequence makes sense and have useful messages, see ref.
- [ ] New tests are added and existing tests are updated.
- [x] Self-reviewed the PR.
Maintenance
- [ ] Linked an issue or added the PR to the current sprint of
ouroboros-networkproject. - [ ] Added labels.
- [ ] Updated changelog files.
- [ ] The documentation has been properly updated, see ref.