aboutsummaryrefslogtreecommitdiff
path: root/DvdLib/BigEndianBinaryReader.cs
blob: 7b581e3402b9fa01e8d6c92f7399e94733ab507e (plain)
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
using System;
using System.IO;

namespace DvdLib
{
    public class BigEndianBinaryReader : BinaryReader
    {
        public BigEndianBinaryReader(Stream input)
            : base(input)
        {
        }

        public override ushort ReadUInt16()
        {
            return BitConverter.ToUInt16(ReadAndReverseBytes(2), 0);
        }

        public override uint ReadUInt32()
        {
            return BitConverter.ToUInt32(ReadAndReverseBytes(4), 0);
        }

        private byte[] ReadAndReverseBytes(int count)
        {
            byte[] val = base.ReadBytes(count);
            Array.Reverse(val, 0, count);
            return val;
        }
    }
}