| 718 | size_t remaining = sessionMemory.stateScratch.sizeInBytes() - stateScratchUsed; |
| 719 | for (size_t idx = 0; idx < sources.sizeInElements(); ++idx) |
| 720 | { |
| 721 | if (remaining < sources[idx].sizeInBytes()) |
| 722 | return Result::Error(HttpClientResultCategory, HttpClientError::SessionStateStorageTooSmall); |
| 723 | remaining -= sources[idx].sizeInBytes(); |
| 724 | } |
| 725 | |
| 726 | size_t destinationOffset = stateScratchUsed; |
| 727 | for (size_t idx = 0; idx < sources.sizeInElements(); ++idx) |
| 728 | { |
| 729 | const StringSpan source = sources[idx]; |
| 730 | if (source.isEmpty()) |
| 731 | { |
| 732 | destinations[idx] = StringSpan(source.getEncoding()); |
| 733 | continue; |
| 734 | } |
| 735 | |
| 736 | char* const destinationBytes = sessionMemory.stateScratch.data() + destinationOffset; |
| 737 | ::memcpy(destinationBytes, source.bytesWithoutTerminator(), source.sizeInBytes()); |
| 738 | destinations[idx] = StringSpan({destinationBytes, source.sizeInBytes()}, false, source.getEncoding()); |
| 739 | destinationOffset += source.sizeInBytes(); |
| 740 | } |
| 741 | stateScratchUsed = destinationOffset; |
| 742 | return Result(true); |
| 743 | } |