Returns a view over a serialized string with the string as a contiguous array of bytes. This may use 'storage' for a temporary copy.
| 595 | // contiguous array of bytes. This may use 'storage' for a temporary |
| 596 | // copy. |
| 597 | StringView readStringView(ByteInputStream& stream, std::string& storage) { |
| 598 | int32_t size = stream.read<int32_t>(); |
| 599 | auto view = stream.nextView(size); |
| 600 | if (view.size() == size) { |
| 601 | // The string is all in one piece, no copy. |
| 602 | return StringView(view.data(), view.size()); |
| 603 | } |
| 604 | storage.resize(size); |
| 605 | memcpy(storage.data(), view.data(), view.size()); |
| 606 | stream.readBytes(storage.data() + view.size(), size - view.size()); |
| 607 | return StringView(storage); |
| 608 | } |
| 609 | |
| 610 | // Comparison of two serializations. |
| 611 | std::optional<int32_t> compareSwitch( |