Be.IO
Be.IO copied to clipboard
ReadBoolean() always returns false
Hi James,
first of all - Great work! This library was just what I needed, when I needed it :smiley:
Unfortunately something isn't quite working right with the ReadBoolean()
method, inherited from BinaryReader
as it always reads in a value of false
:frowning_face:
I wrote a small example to prove I wasn't messing anything up from the outside:
byte[] mem = {
3, 2, // -> u16_1
1, // -> x1
0, // -> x2
1, // -> x3
2, 3, // -> u16_2
};
using (var stream = new MemoryStream(mem))
using (var reader = new BeBinaryReader(stream))
{
ushort u16_1 = reader.ReadUInt16(); // = 770 ✔️
bool x1 = reader.ReadBoolean(); // = false ❌
bool x2 = reader.ReadBoolean(); // = false ✔️
bool x3 = reader.ReadBoolean(); // = false ❌
ushort u16_2 = reader.ReadUInt16(); // = 515 ✔️
}
(... and apparently there's also a bug in GitHub's C# syntax highlighting :see_no_evil:)
The unexpected behavior here is that x1
and x3
should be true
since there's a byte non-zero value (1
) at the appropriate offsets in the byte array.
When I use the standard little-endian BinaryReader
though, the booleans are read correctly:
using (var reader = new BinaryReader(stream))
{
ushort u16_1 = reader.ReadUInt16(); // 515
bool x1 = reader.ReadBoolean(); // true
bool x2 = reader.ReadBoolean(); // false
bool x3 = reader.ReadBoolean(); // true
ushort u16_2 = reader.ReadUInt16(); // 770
}
I'll send a pull request if I found a solution for this problem. Cheers!