Repository navigation
Expand file tree
/
Copy pathEndianAwareBinaryReader.cs
More file actions
94 lines (73 loc) · 2.44 KB
/
Copy pathEndianAwareBinaryReader.cs
File metadata and controls
94 lines (73 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.IO;
using System.Text;
namespace LibCpp2IL
{
public class EndianAwareBinaryReader : BinaryReader
{
protected bool shouldReverseArrays = !BitConverter.IsLittleEndian; //Default to LE mode, so on LE systems, don't invert.
public bool IsBigEndian = false;
public EndianAwareBinaryReader(Stream input) : base(input)
{
}
public EndianAwareBinaryReader(Stream input, Encoding encoding) : base(input, encoding)
{
}
public EndianAwareBinaryReader(Stream input, Encoding encoding, bool leaveOpen) : base(input, encoding, leaveOpen)
{
}
protected void SetBigEndian()
{
shouldReverseArrays = BitConverter.IsLittleEndian; //Set to BE mode, so on LE systems we invert.
IsBigEndian = true;
}
public sealed override short ReadInt16()
{
if (!shouldReverseArrays)
return base.ReadInt16();
return this.ReadInt16WithReversedBits();
}
public sealed override int ReadInt32()
{
if (!shouldReverseArrays)
return base.ReadInt32();
return this.ReadInt32WithReversedBits();
}
public sealed override long ReadInt64()
{
if (!shouldReverseArrays)
return base.ReadInt64();
return this.ReadInt64WithReversedBits();
}
public sealed override ushort ReadUInt16()
{
if (!shouldReverseArrays)
return base.ReadUInt16();
return this.ReadUInt16WithReversedBits();
}
public sealed override uint ReadUInt32()
{
if (!shouldReverseArrays)
return base.ReadUInt32();
return this.ReadUInt32WithReversedBits();
}
public sealed override ulong ReadUInt64()
{
if (!shouldReverseArrays)
return base.ReadUInt64();
return this.ReadUInt64WithReversedBits();
}
public sealed override float ReadSingle()
{
if (!shouldReverseArrays)
return base.ReadSingle();
return this.ReadSingleWithReversedBits();
}
public sealed override double ReadDouble()
{
if (!shouldReverseArrays)
return base.ReadDouble();
return this.ReadDoubleWithReversedBits();
}
}
}