THRIFT-5027 Implement remaining read bytes checks
Client: netstd
Patch: Jens Geyer

This closes #1946
diff --git a/lib/netstd/Thrift/Protocol/TProtocol.cs b/lib/netstd/Thrift/Protocol/TProtocol.cs
index dca3f9e..5275c9c 100644
--- a/lib/netstd/Thrift/Protocol/TProtocol.cs
+++ b/lib/netstd/Thrift/Protocol/TProtocol.cs
@@ -77,6 +77,27 @@
             _isDisposed = true;
         }
 
+
+        protected void CheckReadBytesAvailable(TSet set)
+        {
+            Transport.CheckReadBytesAvailable(set.Count * GetMinSerializedSize(set.ElementType));
+        }
+
+        protected void CheckReadBytesAvailable(TList list)
+        {
+            Transport.CheckReadBytesAvailable(list.Count * GetMinSerializedSize(list.ElementType));
+        }
+
+        protected void CheckReadBytesAvailable(TMap map)
+        {
+            var elmSize = GetMinSerializedSize(map.KeyType) + GetMinSerializedSize(map.ValueType);
+            Transport.CheckReadBytesAvailable(map.Count * elmSize);
+        }
+
+        // Returns the minimum amount of bytes needed to store the smallest possible instance of TType.
+        public abstract int GetMinSerializedSize(TType type);
+
+
         public virtual async Task WriteMessageBeginAsync(TMessage message)
         {
             await WriteMessageBeginAsync(message, CancellationToken.None);