made Char be a method to match async method

This commit is contained in:
Adam Hathcock
2026-04-28 08:39:54 +01:00
parent 896dfd6537
commit 18fade571e
5 changed files with 35 additions and 32 deletions

View File

@@ -281,13 +281,13 @@ internal class ModelPpm
internal bool DecodeInit(IRarUnpack unpackRead, int escChar)
{
var maxOrder = unpackRead.Char & 0xff;
var maxOrder = unpackRead.ReadChar() & 0xff;
var reset = ((maxOrder & 0x20) != 0);
var maxMb = 0;
if (reset)
{
maxMb = unpackRead.Char;
maxMb = unpackRead.ReadChar();
}
else
{
@@ -298,7 +298,7 @@ internal class ModelPpm
}
if ((maxOrder & 0x40) != 0)
{
escChar = unpackRead.Char;
escChar = unpackRead.ReadChar();
unpackRead.PpmEscChar = escChar;
}
Coder = new RangeCoder(unpackRead);

View File

@@ -62,7 +62,7 @@ internal class RangeCoder
_range = 0xFFFFffffL;
for (var i = 0; i < 4; i++)
{
_code = ((_code << 8) | Char) & UINT_MASK;
_code = ((_code << 8) | ReadChar()) & UINT_MASK;
}
}
@@ -91,20 +91,17 @@ internal class RangeCoder
}
}
private long Char
private long ReadChar()
{
get
if (_unpackRead != null)
{
if (_unpackRead != null)
{
return (_unpackRead.Char);
}
if (_stream != null)
{
return _stream.ReadByte();
}
return -1;
return (_unpackRead.ReadChar());
}
if (_stream != null)
{
return _stream.ReadByte();
}
return -1;
}
internal SubRange SubRange { get; private set; }
@@ -139,7 +136,7 @@ internal class RangeCoder
_range = (-_low & (BOT - 1)) & UINT_MASK;
c2 = false;
}
_code = ((_code << 8) | Char) & UINT_MASK;
_code = ((_code << 8) | ReadChar()) & UINT_MASK;
_range = (_range << 8) & UINT_MASK;
_low = (_low << 8) & UINT_MASK;
}

View File

@@ -22,6 +22,7 @@ internal interface IRarUnpack
bool Suspended { get; set; }
long DestSize { get; }
int Char { get; }
int ReadChar();
ValueTask<int> ReadCharAsync(CancellationToken cancellationToken);
int PpmEscChar { get; set; }
}

View File

@@ -55,16 +55,13 @@ internal sealed partial class Unpack : BitInput, IRarUnpack
set => suspended = value;
}
public int Char
public int ReadChar()
{
get
if (inAddr > MAX_SIZE - 30)
{
if (inAddr > MAX_SIZE - 30)
{
unpReadBuf();
}
return (InBuf[inAddr++] & 0xff);
unpReadBuf();
}
return (InBuf[inAddr++] & 0xff);
}
public int PpmEscChar { get; set; }

View File

@@ -154,17 +154,25 @@ internal partial class Unpack : IRarUnpack
public long DestSize => DestUnpSize;
public int Char
public int ReadChar()
{
get
// TODO: coderb: not sure where the "MAXSIZE-30" comes from, ported from V1 code
if (InAddr > MAX_SIZE - 30)
{
// TODO: coderb: not sure where the "MAXSIZE-30" comes from, ported from V1 code
if (InAddr > MAX_SIZE - 30)
{
UnpReadBuf();
}
return InBuf[InAddr++];
UnpReadBuf();
}
return InBuf[InAddr++];
}
public async ValueTask<int> ReadCharAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
// TODO: coderb: not sure where the "MAXSIZE-30" comes from, ported from V1 code
if (InAddr > MAX_SIZE - 30)
{
await UnpReadBufAsync(cancellationToken).ConfigureAwait(false);
}
return InBuf[InAddr++];
}
public int PpmEscChar