THRIFT-5874 Introduce new type MESSAGE_SIZE_LIMIT in TTransportException
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/netstd/Thrift/Protocol/TJSONProtocol.cs b/lib/netstd/Thrift/Protocol/TJSONProtocol.cs
index ae37a80..170f294 100644
--- a/lib/netstd/Thrift/Protocol/TJSONProtocol.cs
+++ b/lib/netstd/Thrift/Protocol/TJSONProtocol.cs
@@ -468,6 +468,7 @@
}
// it's \uXXXX
+ Trans.CheckReadBytesAvailable(4);
await Trans.ReadAllAsync(_tempBuffer, 0, 4, cancellationToken);
var wch = (short) ((TJSONProtocolHelper.ToHexVal(_tempBuffer[0]) << 12) +
@@ -1018,6 +1019,7 @@
else
{
// find more easy way to avoid exception on reading primitive types
+ Proto.Trans.CheckReadBytesAvailable(1);
await Proto.Trans.ReadAllAsync(_data, 0, 1, cancellationToken);
}
return _data[0];
@@ -1034,6 +1036,7 @@
if (!_hasData)
{
// find more easy way to avoid exception on reading primitive types
+ Proto.Trans.CheckReadBytesAvailable(1);
await Proto.Trans.ReadAllAsync(_data, 0, 1, cancellationToken);
_hasData = true;
}
diff --git a/lib/netstd/Thrift/Transport/Client/THttpTransport.cs b/lib/netstd/Thrift/Transport/Client/THttpTransport.cs
index 4467681..439777e 100644
--- a/lib/netstd/Thrift/Transport/Client/THttpTransport.cs
+++ b/lib/netstd/Thrift/Transport/Client/THttpTransport.cs
@@ -27,6 +27,7 @@
#pragma warning disable IDE0079 // unneeded suppression -> all except net8
#pragma warning disable IDE0301 // simplify collection init -> net8 only
+#pragma warning disable IDE0305 // simplify collection init -> net8 only
namespace Thrift.Transport.Client
{
diff --git a/lib/netstd/Thrift/Transport/TEndpointTransport.cs b/lib/netstd/Thrift/Transport/TEndpointTransport.cs
index 27fb48d..c736e2f 100644
--- a/lib/netstd/Thrift/Transport/TEndpointTransport.cs
+++ b/lib/netstd/Thrift/Transport/TEndpointTransport.cs
@@ -56,7 +56,7 @@
// update only: message size can shrink, but not grow
Debug.Assert(KnownMessageSize <= MaxMessageSize);
if (newSize > KnownMessageSize)
- throw new TTransportException(TTransportException.ExceptionType.EndOfFile, "MaxMessageSize reached");
+ throw new TTransportException(TTransportException.ExceptionType.MessageSizeLimit, "MaxMessageSize reached");
KnownMessageSize = newSize;
RemainingMessageSize = newSize;
@@ -81,7 +81,7 @@
public override void CheckReadBytesAvailable(long numBytes)
{
if ((RemainingMessageSize < numBytes) || (numBytes < 0))
- throw new TTransportException(TTransportException.ExceptionType.EndOfFile, "MaxMessageSize reached");
+ throw new TTransportException(TTransportException.ExceptionType.MessageSizeLimit, "MaxMessageSize reached");
}
/// <summary>
@@ -97,7 +97,7 @@
else
{
RemainingMessageSize = 0;
- throw new TTransportException(TTransportException.ExceptionType.EndOfFile, "MaxMessageSize reached");
+ throw new TTransportException(TTransportException.ExceptionType.MessageSizeLimit, "MaxMessageSize reached");
}
}
}
diff --git a/lib/netstd/Thrift/Transport/TTransportException.cs b/lib/netstd/Thrift/Transport/TTransportException.cs
index 760a178..682b864 100644
--- a/lib/netstd/Thrift/Transport/TTransportException.cs
+++ b/lib/netstd/Thrift/Transport/TTransportException.cs
@@ -29,7 +29,8 @@
AlreadyOpen,
TimedOut,
EndOfFile,
- Interrupted
+ Interrupted,
+ MessageSizeLimit
}
public ExceptionType ExType { get; private set; }
@@ -57,4 +58,4 @@
public ExceptionType Type => ExType;
}
-}
\ No newline at end of file
+}