Skip to content

Commit

Permalink
Expose origin BoM and TextEncoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Dec 7, 2023
1 parent 40246bc commit 7c703ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/MessageStudio/Formats/BinaryText/ImmutableMsbt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using MessageStudio.Formats.BinaryText.Structures;
using MessageStudio.IO;
using System.Runtime.CompilerServices;
using System.Text;

namespace MessageStudio.Formats.BinaryText;

public readonly ref struct ImmutableMsbt
{
public readonly MsbtHeader Header;
public readonly AttributeSectionReader AttributeSectionReader;
public readonly LabelSectionReader LabelSectionReader;
public readonly TextSectionReader TextSectionReader;
Expand Down Expand Up @@ -46,5 +46,15 @@ public ImmutableMsbt(ref SpanReader reader)

reader.Align(0x10);
}

Header = header;

// Fix the BoM for consumers
unsafe {
fixed (Endian* ptr = &Header.ByteOrderMark) {
Span<byte> range = new(ptr, sizeof(Endian));
range.Reverse();
}
}
}
}
9 changes: 8 additions & 1 deletion src/MessageStudio/Formats/BinaryText/Msbt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class Msbt : Dictionary<string, MsbtEntry>
internal const uint LBL1_MAGIC = 0x314C424C;
internal const uint TXT2_MAGIC = 0x32545854;

public Endian Endian { get; set; } = Endian.Little;
public TextEncoding Encoding { get; set; } = TextEncoding.Unicode;

/// <summary>
/// Create a new <see cref="Msbt"/> object from a data buffer
/// </summary>
Expand All @@ -32,7 +35,11 @@ public static Msbt FromBinary(Span<byte> buffer)
/// <returns></returns>
public static Msbt FromImmutable(ref ImmutableMsbt msbt)
{
Msbt managed = [];
Msbt managed = new() {
Encoding = msbt.Header.Encoding,
Endian = msbt.Header.ByteOrderMark
};

foreach (var label in msbt.LabelSectionReader) {
int index = label.Index;
string? key = label.GetManaged();
Expand Down

0 comments on commit 7c703ee

Please sign in to comment.