Initial Commit
This commit is contained in:
commit
6088fc29ed
978 changed files with 353647 additions and 0 deletions
46
include/Helpers/Networking/ByteStream.cpp
Normal file
46
include/Helpers/Networking/ByteStream.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "ByteStream.hpp"
|
||||
#include <cereal/archives/portable_binary.hpp>
|
||||
#include <cereal/types/string.hpp>
|
||||
#include "NetLibrary.hpp"
|
||||
|
||||
ByteMemBuf::ByteMemBuf(char* p, size_t l) {
|
||||
setg(p, p, p + l);
|
||||
|
||||
}
|
||||
|
||||
ByteMemStream::ByteMemStream(char* p, size_t l):
|
||||
std::istream(&buffer),
|
||||
buffer(p, l)
|
||||
{
|
||||
rdbuf(&buffer);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<std::stringstream>> fragment_message(std::string_view v, uint64_t stride) {
|
||||
if(v.length() <= stride)
|
||||
return {};
|
||||
uint64_t nextByte = 0;
|
||||
std::vector<std::shared_ptr<std::stringstream>> toRet;
|
||||
toRet.emplace_back(std::make_shared<std::stringstream>());
|
||||
{
|
||||
cereal::PortableBinaryOutputArchive m(*toRet.back());
|
||||
m((MessageCommandType)0, (uint64_t)v.length(), cereal::binary_data(v.data() + nextByte, stride));
|
||||
}
|
||||
nextByte += stride;
|
||||
for(;;) {
|
||||
if((v.length() - nextByte) <= stride) {
|
||||
toRet.emplace_back(std::make_shared<std::stringstream>());
|
||||
{
|
||||
cereal::PortableBinaryOutputArchive m(*toRet.back());
|
||||
m((MessageCommandType)0, cereal::binary_data(v.data() + nextByte, (uint64_t)(v.length() - nextByte)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
toRet.emplace_back(std::make_shared<std::stringstream>());
|
||||
{
|
||||
cereal::PortableBinaryOutputArchive m(*toRet.back());
|
||||
m((MessageCommandType)0, cereal::binary_data(v.data() + nextByte, stride));
|
||||
}
|
||||
nextByte += stride;
|
||||
}
|
||||
return toRet;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue