Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include<vector>
- #include<string>
- #include<sstream>
- #include <algorithm>
- #include "Company.h"
- byte* serializeToMemory(std::string const& input,
- size_t& bytesWritten) {
- std::istringstream iss(input);
- std::vector<Company> companies;
- Company parsedCompany;
- while (iss >> parsedCompany) {
- companies.push_back(parsedCompany);
- }
- std::vector<byte> bytes;
- bytes.push_back(companies.size());
- for (const auto& company : companies) {
- bytes.push_back(company.getId());
- for (char c : company.getName()) {
- bytes.push_back((byte) c);
- }
- bytes.push_back('\0');
- auto employees = company.getEmployees();
- bytes.push_back(employees.size());
- for (auto e : employees) {
- bytes.push_back((byte) e.first);
- bytes.push_back((byte) e.second);
- }
- }
- bytesWritten = bytes.size();
- byte* memory = new byte[bytes.size()];
- std::copy(std::begin(bytes), std::end(bytes), memory);
- return memory;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement