public static object ReadJsonBuffered(
            this NetworkStream stream,
            Type type,
            int?maxBytes   = null,
            int bufferSize = 0xFFF, Encoding encoding = null)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            return(PapercutIPCommSerializer.FromJson(type, stream.ReadStringBuffered(maxBytes, bufferSize, encoding)));
        }
Exemple #2
0
        public static async Task <object> ReadJsonBufferedAsync(
            this NetworkStream stream,
            Type type,
            int?maxBytes   = null,
            int bufferSize = 0xFFF, Encoding encoding = null, CancellationToken token = default)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var readStringBufferedAsync = await stream.ReadStringBufferedAsync(maxBytes, bufferSize, encoding, token : token);

            return(PapercutIPCommSerializer.FromJson(type, readStringBufferedAsync));
        }
        public static object ReadJsonBuffered(this NetworkStream stream, Type type, int payloadSize, Encoding encoding = null)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            encoding = encoding ?? Encoding.UTF8;

            using (var memoryStream = new MemoryStream())
            {
                stream.CopyBufferedTo(memoryStream, payloadSize);

                return(PapercutIPCommSerializer.FromJson(type, encoding.GetString(memoryStream.ToArray())));
            }
        }
Exemple #4
0
        public static async Task <object> ReadJsonBufferedAsync(this NetworkStream stream, Type type, int payloadSize, Encoding encoding = null, CancellationToken token = default)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            encoding = encoding ?? Encoding.UTF8;

            using (var memoryStream = new MemoryStream())
            {
                await stream.CopyBufferedToAsync(memoryStream, payloadSize, token : token);

                return(PapercutIPCommSerializer.FromJson(type, encoding.GetString(memoryStream.ToArray())));
            }
        }