diff --git a/includes/csharp/io/binary.hpp b/includes/csharp/io/binary.hpp index 784c247..9c2f9d9 100644 --- a/includes/csharp/io/binary.hpp +++ b/includes/csharp/io/binary.hpp @@ -135,7 +135,7 @@ namespace csharp { std::shared_ptr _stream; bool _leaveOpen; bool _disposed{false}; - bool _2BytesPerChar{ false }; + bool _2BytesPerChar{ true }; std::vector _auxBuffer; }; diff --git a/samples/01_blank/xna.cpp b/samples/01_blank/xna.cpp index 7e45c24..5ffee7f 100644 --- a/samples/01_blank/xna.cpp +++ b/samples/01_blank/xna.cpp @@ -13,6 +13,9 @@ namespace xna { Game1() : Game() { Content()->RootDirectory("Content"); + short inteiro = 0xC3 | 0xA7; + char charpa = inteiro; + auto stream = std::make_shared("D:/file.bin", csharp::FileMode::Open); auto reader = csharp::BinaryReader(stream); auto bo = reader.ReadBoolean(); //reader.ReadChar() diff --git a/sources/csharp/io/binary.cpp b/sources/csharp/io/binary.cpp index f6ea899..c769ace 100644 --- a/sources/csharp/io/binary.cpp +++ b/sources/csharp/io/binary.cpp @@ -32,15 +32,13 @@ namespace csharp { { posSav = _stream->Position(); } - - auto charBytes = std::vector(MaxCharBytesSize); + char singleChar = '\0'; while (charsRead == 0) { numBytes = _2BytesPerChar ? 2 : 1; - auto r = _stream->ReadByte(); - charBytes[0] = static_cast(r); + auto r = _stream->ReadByte(); if (r == -1) { @@ -48,13 +46,12 @@ namespace csharp { } if (numBytes == 2) { - r = _stream->ReadByte(); - charBytes[1] = static_cast(r); + r |= _stream->ReadByte(); if (r == -1) { numBytes = 1; - } + } } if (numBytes == 0) @@ -62,8 +59,8 @@ namespace csharp { return -1; } - const auto chars = reinterpret_cast(charBytes.data()); - const auto decoder = std::string(chars); + const char chars = r; + const auto decoder = std::string(&chars); charsRead = decoder.size(); singleChar = decoder[0]; }