MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / fragment_message

Function fragment_message

include/Helpers/Networking/ByteStream.cpp:37–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37std::vector<std::shared_ptr<std::stringstream>> fragment_message(std::string_view uncompressedView, size_t stride) {
38 if(uncompressedView.length() <= stride)
39 return {};
40
41 std::vector<char> compressedData(ZSTD_compressBound(uncompressedView.size()));
42 size_t trueCompressedSize = ZSTD_compress(compressedData.data(), compressedData.size(), uncompressedView.data(), uncompressedView.size(), ZSTD_CLEVEL_DEFAULT);
43
44 std::string_view v(compressedData.data(), trueCompressedSize);
45
46 uint64_t nextByte = 0;
47 std::vector<std::shared_ptr<std::stringstream>> toRet;
48
49 toRet.emplace_back(std::make_shared<std::stringstream>());
50
51 size_t messFirstStride = std::min<size_t>(stride, v.size());
52
53 {
54 cereal::PortableBinaryOutputArchive m(*toRet.back());
55 m((MessageCommandType)0, (uint64_t)v.length(), cereal::binary_data(v.data() + nextByte, messFirstStride));
56 }
57
58 if(messFirstStride == v.size())
59 return toRet;
60
61 nextByte += stride;
62 for(;;) {
63 if((v.length() - nextByte) <= stride) {
64 toRet.emplace_back(std::make_shared<std::stringstream>());
65 {
66 cereal::PortableBinaryOutputArchive m(*toRet.back());
67 m((MessageCommandType)0, cereal::binary_data(v.data() + nextByte, v.length() - nextByte));
68 }
69 break;
70 }
71 toRet.emplace_back(std::make_shared<std::stringstream>());
72 {
73 cereal::PortableBinaryOutputArchive m(*toRet.back());
74 m((MessageCommandType)0, cereal::binary_data(v.data() + nextByte, stride));
75 }
76 nextByte += stride;
77 }
78 return toRet;
79}
80
81void uncompress_and_run_func(PartialFragmentMessage& spfm, std::function<void(cereal::PortableBinaryInputArchive& completeArchive)> runAfterDecoded) {
82 std::vector<char> uncompressedData(ZSTD_getFrameContentSize(spfm.partialFragmentMessage.data(), spfm.partialFragmentMessage.size()));

Calls 4

binary_dataFunction · 0.85
lengthMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected