//Copyright 2022, FOSS-VG Developers and Contributers // //This program is free software: you can redistribute it and/or modify it //under the terms of the GNU Affero General Public License as published //by the Free Software Foundation, version 3. // //This program is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied //warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //See the GNU Affero General Public License for more details. // //You should have received a copy of the GNU Affero General Public License //version 3 along with this program. //If not, see https://www.gnu.org/licenses/agpl-3.0.en.html #pragma once #include #include #include "error.hpp" #include "../../.endianness" #ifdef FOSSVG_ENDIAN_BIG_WORD #error "Honeywell-316-style endianness is not supported. If you feel like it should, feel free to participate in the project to maintain it." #endif #ifdef FOSSVG_ENDIAN_LITTLE_WORD #error "PDP-11-style endianness is not supported. If you feel like it should, feel free to participate in the project to maintain it." #endif #ifdef FOSSVG_ENDIAN_UNKNOWN #error "The endianness of your system could not be determined. Please set it manually. FOSS-VG is currently implemented using some endian-specific functions." #endif namespace JavaCompat { ErrorOr importJavaString(uint8_t data[], uint16_t size) { std::string stdString; uint16_t encodedSize = static_cast(data[0])<<8 | static_cast(data[1]); if(encodedSize != size){ return ErrorOr(true, ErrorCodes::MISMATCHEDSIZE); } for(uint16_t i=2; i(tiny_utf8::string(stdString)); } ErrorOr> exportJavaString(tiny_utf8::string data) { uint16_t* size = new uint16_t; uint8_t* sizeBytes = reinterpret_cast(size); std::vector output = std::vector(); std::string stdString = data.cpp_str(); if(stdString.size() > 0xFFFF){ return ErrorOr>(true, ErrorCodes::OVERRUN); } *size = (uint16_t) stdString.size(); //placeholder size bytes output.push_back(0x00); output.push_back(0x00); for(uint16_t i=0; i