#pragma once
#include "serialize/binary.inl"
#include "serialize/text.inl"
#include "meta/result.inl"
namespace YAML
{
	using meta::result;
	enum class SerializeError : char
	{
		TEXT_EMPTY,
		TYPE_ERROR,
	};
	inline string Text_Serialize(const Any& any) {
		return Dump(TextArchive::Serialize(any));
	}
	template<typename T>
	inline result<T, SerializeError> Text_Unserialize(const string& text) {
		if (text.empty()) {
			return SerializeError::TEXT_EMPTY;
		}
		char data[sizeof(T)];
		Any any(&data, &TypeInfo<T>::StaticClass);
		if (!TextArchive::Unserialize(Load(text), any)) {
			return SerializeError::TYPE_ERROR;
		}
		return *any.CastTo<T*>();
	}
	inline bool Text_Unserialize(const string& text, Any any) {
		return TextArchive::Unserialize(Load(text), any);
	}
}