Returns a view over a serialized string with the string as a contiguous array of bytes. This may use 'storage' for a temporary copy.
| 896 | // contiguous array of bytes. This may use 'storage' for a temporary |
| 897 | // copy. |
| 898 | StringView readStringView(ByteInputStream& stream, std::string& storage) { |
| 899 | int32_t size = stream.read<int32_t>(); |
| 900 | auto view = stream.nextView(size); |
| 901 | if (view.size() == size) { |
| 902 | // The string is all in one piece, no copy. |
| 903 | return StringView(view.data(), view.size()); |
| 904 | } |
| 905 | storage.resize(size); |
| 906 | memcpy(storage.data(), view.data(), view.size()); |
| 907 | stream.readBytes(storage.data() + view.size(), size - view.size()); |
| 908 | return StringView(storage); |
| 909 | } |
| 910 | |
| 911 | // Comparison of two serializations. |
| 912 | std::optional<int32_t> compareSwitch( |