2023-09-07 05:35:02 -04:00
|
|
|
#pragma once
|
2023-09-08 05:38:09 -04:00
|
|
|
|
2023-09-07 05:35:02 -04:00
|
|
|
#include "CoreMinimal.h"
|
2023-10-18 17:38:53 -04:00
|
|
|
#include "lpx-basebuffer.hpp"
|
2023-09-07 05:35:02 -04:00
|
|
|
|
2026-02-22 20:59:02 -05:00
|
|
|
class FlxStreamBufferConfig {
|
2023-09-07 05:35:02 -04:00
|
|
|
private:
|
2023-10-24 01:44:09 -04:00
|
|
|
bool err_eof_on_read_;
|
|
|
|
|
bool err_string_too_long_;
|
|
|
|
|
bool err_integer_truncated_;
|
2026-02-22 22:46:54 -05:00
|
|
|
public:
|
2026-02-22 20:59:02 -05:00
|
|
|
using string_type = std::string;
|
2023-10-24 01:44:09 -04:00
|
|
|
void *basebuffer_malloc(size_t size) { return malloc(size); }
|
|
|
|
|
void basebuffer_free(void *p) { free(p); }
|
|
|
|
|
void clear_error_flags() { err_eof_on_read_ = err_string_too_long_ = err_integer_truncated_ = false; }
|
|
|
|
|
void raise_eof_on_read() { err_eof_on_read_ = true; }
|
|
|
|
|
void raise_string_too_long() { err_string_too_long_ = true; }
|
|
|
|
|
void raise_integer_truncated() { err_integer_truncated_ = true; }
|
2024-09-05 01:33:37 -04:00
|
|
|
|
|
|
|
|
public:
|
2023-10-24 01:44:09 -04:00
|
|
|
bool get_err_eof_on_read() const { return err_eof_on_read_; }
|
|
|
|
|
bool get_err_string_too_long() const { return err_string_too_long_; }
|
|
|
|
|
bool get_err_integer_truncated() const { return err_integer_truncated_; }
|
|
|
|
|
bool any_error() const { return err_eof_on_read_ || err_string_too_long_ || err_integer_truncated_; }
|
|
|
|
|
};
|
2023-09-07 05:35:02 -04:00
|
|
|
|
2026-02-22 20:59:02 -05:00
|
|
|
class FlxStreamBuffer : public BaseBuffer<FlxStreamBufferConfig> {
|
2023-10-24 01:44:09 -04:00
|
|
|
public:
|
|
|
|
|
using BaseBuffer::BaseBuffer;
|
2024-08-31 16:42:07 -04:00
|
|
|
using BaseBuffer::write_string;
|
|
|
|
|
|
|
|
|
|
void write_string(const FString &str) {
|
|
|
|
|
FTCHARToUTF8 utf8str(str);
|
|
|
|
|
write_string(std::string_view(utf8str.Get(), utf8str.Length()));
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-05 16:08:34 -05:00
|
|
|
void write_fname(const FName &name) {
|
|
|
|
|
FTCHARToUTF8 utf8str(name.ToString());
|
|
|
|
|
write_string(std::string_view(utf8str.Get(), utf8str.Length()));
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-31 16:42:07 -04:00
|
|
|
void write_string(const char *s) {
|
|
|
|
|
write_string(std::string_view(s));
|
|
|
|
|
}
|
2023-10-24 01:44:09 -04:00
|
|
|
|
2023-10-31 13:33:00 -04:00
|
|
|
void write_fvector(const FVector &xyz) {
|
2023-10-24 01:44:09 -04:00
|
|
|
write_double(xyz.X);
|
|
|
|
|
write_double(xyz.Y);
|
|
|
|
|
write_double(xyz.Z);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 13:33:00 -04:00
|
|
|
FVector read_fvector() {
|
2023-10-24 01:44:09 -04:00
|
|
|
double x = read_double();
|
|
|
|
|
double y = read_double();
|
|
|
|
|
double z = read_double();
|
|
|
|
|
return FVector(x, y, z);
|
|
|
|
|
}
|
2025-02-05 16:08:34 -05:00
|
|
|
|
|
|
|
|
FString read_fstring() {
|
|
|
|
|
std::string_view s = read_string_view();
|
|
|
|
|
return FString(s.size(), (const UTF8CHAR *)s.data());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FName read_fname() {
|
|
|
|
|
std::string_view s = read_string_view();
|
|
|
|
|
return FName(s.size(), (const UTF8CHAR *)s.data(), FNAME_Add);
|
|
|
|
|
}
|
2023-09-07 05:35:02 -04:00
|
|
|
};
|