9 enum class Encoding : u8 {
17 static inline constexpr size_t GetCharacterSize(
const Encoding enc) {
19 case Encoding::CP1252: {
23 case Encoding::UTF16: {
24 return sizeof(char16_t);
26 case Encoding::UTF8: {
29 case Encoding::ShiftJIS: {
39 static inline constexpr bool IsValidEncoding(
const Encoding enc) {
40 return GetCharacterSize(enc) > 0;
59 static constexpr size_t OffsetSize =
sizeof(u32);
61 inline size_t GetAttributesSize() {
62 return this->entry_size - OffsetSize;
65 inline void SetAttributesSize(
const size_t size) {
66 this->entry_size = OffsetSize + size;
80 enum class MessageTokenType : u8 {
86 std::vector<u8> esc_data;
90 MessageTokenType type;
94 inline size_t GetByteLength(
const Encoding enc)
const {
96 case MessageTokenType::Escape: {
97 return GetCharacterSize(enc) + 1 + this->escape.esc_data.size();
99 case MessageTokenType::Text: {
100 return this->text.length() * GetCharacterSize(enc);
110 std::vector<MessageToken> msg;
111 std::vector<u8> attrs;
114 inline size_t GetByteLength(
const Encoding enc)
const {
115 size_t size = GetCharacterSize(enc);
116 for(
const auto &token: this->msg) {
117 size += token.GetByteLength(enc);
126 std::optional<MessageIdSection> msg_id;
127 std::vector<Message> messages;
132 inline bool HasMessageIds() {
133 return this->msg_id.has_value();
136 Result CreateFrom(
const Encoding enc,
const bool has_message_ids,
const size_t attr_size,
const std::vector<Message> &msgs,
const u32 file_id,
const ntr::fs::FileCompression comp = ntr::fs::FileCompression::None);
138 Result ValidateImpl(
const std::string &path, std::shared_ptr<fs::FileHandle> file_handle,
const fs::FileCompression comp)
override;
139 Result ReadImpl(
const std::string &path, std::shared_ptr<fs::FileHandle> file_handle,
const fs::FileCompression comp)
override;
140 Result WriteImpl(
const std::string &path, std::shared_ptr<fs::FileHandle> file_handle,
const fs::FileCompression comp)
override;