World structure update + new blocks

This commit is contained in:
MihailRis
2023-11-24 02:20:13 +03:00
parent cc556bc19b
commit 275e4af9fd
9 changed files with 70 additions and 4 deletions
+18
View File
@@ -27,6 +27,15 @@ void BinaryWriter::put(const string& s) {
put((const ubyte*)s.data(), len);
}
void BinaryWriter::putShortStr(const string& s) {
size_t len = s.length();
if (len > 255) {
throw std::domain_error("length > 255");
}
put(len);
put((const ubyte*)s.data(), len);
}
void BinaryWriter::put(const ubyte* arr, size_t size) {
buffer.reserve(buffer.size() + size);
for (size_t i = 0; i < size; i++) {
@@ -144,6 +153,15 @@ string BinaryReader::getString() {
return string((const char*)(data+pos-length), length);
}
string BinaryReader::getShortString() {
ubyte length = get();
if (pos+length > size) {
throw std::underflow_error("unexpected end");
}
pos += length;
return string((const char*)(data+pos-length), length);
}
bool BinaryReader::hasNext() const {
return pos < size;
}