using System;
using System.Buffers.Binary;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
namespace BililiveRecorder.Flv.Parser
{
///
public class BigEndianBinaryReader : BinaryReader
{
///
public BigEndianBinaryReader(Stream input) : base(input)
{
}
///
public BigEndianBinaryReader(Stream input, Encoding encoding) : base(input, encoding)
{
}
///
public BigEndianBinaryReader(Stream input, Encoding encoding, bool leaveOpen) : base(input, encoding, leaveOpen)
{
}
///
public override Stream BaseStream => base.BaseStream;
///
public override void Close() => base.Close();
///
public override bool Equals(object? obj) => base.Equals(obj);
///
public override int GetHashCode() => base.GetHashCode();
///
public override int PeekChar() => base.PeekChar();
///
public override int Read() => base.Read();
///
public override int Read(byte[] buffer, int index, int count) => base.Read(buffer, index, count);
///
public override int Read(char[] buffer, int index, int count) => base.Read(buffer, index, count);
///
public override bool ReadBoolean() => base.ReadBoolean();
///
public override byte ReadByte() => base.ReadByte();
///
public override byte[] ReadBytes(int count) => base.ReadBytes(count);
///
public override char ReadChar() => base.ReadChar();
///
public override char[] ReadChars(int count) => base.ReadChars(count);
///
public override decimal ReadDecimal() => BitConverter.IsLittleEndian ? throw new NotSupportedException("not supported") : base.ReadDecimal();
///
public override double ReadDouble() => BitConverter.IsLittleEndian
? BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64BigEndian(base.ReadBytes(sizeof(double))))
: base.ReadDouble();
///
public override short ReadInt16() => BitConverter.IsLittleEndian ? BinaryPrimitives.ReadInt16BigEndian(base.ReadBytes(sizeof(short))) : base.ReadInt16();
///
public override int ReadInt32() => BitConverter.IsLittleEndian ? BinaryPrimitives.ReadInt32BigEndian(base.ReadBytes(sizeof(int))) : base.ReadInt32();
///
public override long ReadInt64() => BitConverter.IsLittleEndian ? BinaryPrimitives.ReadInt64BigEndian(base.ReadBytes(sizeof(long))) : base.ReadInt64();
///
public override sbyte ReadSByte() => base.ReadSByte();
///
public override float ReadSingle() => BitConverter.IsLittleEndian
? Int32BitsToSingle(BinaryPrimitives.ReadInt32BigEndian(base.ReadBytes(sizeof(float))))
: base.ReadSingle();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe float Int32BitsToSingle(int value) => *(float*)&value;
///
public override string ReadString() => base.ReadString();
///
public override ushort ReadUInt16() => BitConverter.IsLittleEndian ? BinaryPrimitives.ReadUInt16BigEndian(base.ReadBytes(sizeof(ushort))) : base.ReadUInt16();
///
public override uint ReadUInt32() => BitConverter.IsLittleEndian ? BinaryPrimitives.ReadUInt32BigEndian(base.ReadBytes(sizeof(uint))) : base.ReadUInt32();
///
public override ulong ReadUInt64() => BitConverter.IsLittleEndian ? BinaryPrimitives.ReadUInt64BigEndian(base.ReadBytes(sizeof(ulong))) : base.ReadUInt64();
///
public override string? ToString() => base.ToString();
///
protected override void Dispose(bool disposing) => base.Dispose(disposing);
///
protected override void FillBuffer(int numBytes) => base.FillBuffer(numBytes);
}
}