Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAX serialization protocol #231

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions PolyEngine/Core/Src/pe/core/io/IProtocolSAX.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <Defines.hpp>
#include <core/utils/Result.hpp>
#include <core/storage/String.hpp>

namespace pe::core::io {

enum class ErrorSAX {
INTERNAL,
_COUNT
};

using ResultSAX = utils::Result<void, ErrorSAX>;

class IProtocolSAX : public BaseObject<>
{
virtual ResultSAX key(std::string_view name) = 0;
virtual ResultSAX metakey(std::string_view name) = 0;

virtual ResultSAX null() = 0;

virtual ResultSAX boolean(bool value) = 0;

virtual ResultSAX number(int32_t value) = 0;
virtual ResultSAX number(uint32_t value) = 0;
virtual ResultSAX number(int64_t value) = 0;
virtual ResultSAX number(uint64_t value) = 0;
virtual ResultSAX number(float value) = 0;
virtual ResultSAX number(double value) = 0;

virtual ResultSAX text(std::string_view text) = 0;
virtual ResultSAX text(storage::String&& text) = 0;

virtual ResultSAX binaryStream(const uint8_t* bytes, size_t size) = 0;

virtual ResultSAX startObject() = 0;
virtual ResultSAX endObject() = 0;

virtual ResultSAX startArray() = 0;
virtual ResultSAX endArray() = 0;
};

class IEventHandlerSAX : IProtocolSAX
{
virtual uint8_t* binaryStreamBufferRequest(size_t size) { return nullptr; }
virtual void binaryStreamBufferFilled(const ResultSAX& status) {}
};

class IReaderSAX
{
virtual ResultSAX read(IEventHandlerSAX& handler);
};

class IWriterSAX : IProtocolSAX
{
virtual ResultSAX write();
};

} // namespace pe::core::io
5 changes: 4 additions & 1 deletion PolyEngine/Engine/Src/pe/engine/EnginePCH.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@
#include <pe/core/storage/Queue.hpp>
#include <pe/core/storage/PriorityQueue.hpp>

// IO
#include <pe/core/io/IProtocolSAX.hpp>

// Other
#include <pe/core/math/Color.hpp>
#include <pe/core/utils/FileIO.hpp>
#include <pe/core/utils/Logger.hpp>
#include <pe/core/UniqueID.hpp>
#include <pe/core/utils/EnumUtils.hpp>
#include <pe/core/utils/OutputStream.hpp>
#include <pe/core/utils/OutputStream.hpp>
#include <pe/core/utils/Result.hpp>

// OpenAL
#include <AL/al.h>
Expand Down