System.IO.Stream.ReadUInt32Compact()

Here are the examples of the csharp api System.IO.Stream.ReadUInt32Compact() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

19 Source : StreamHelpers.cs
with MIT License
from reaqtive

public static string ReadString(this Stream stream)
        {
            var len = (int)stream.ReadUInt32Compact();

            if (len > 0U)
            {
                byte[] buffer;
                if (len - 1 <= MAX_POOLED_STRING_BYTES)
                {
                    buffer = s_stringPool.Get();
                }
                else
                {
                    buffer = new byte[len - 1];
                }

                try
                {
                    var n = stream.Read(buffer, 0, len - 1);
                    if (n < len - 1)
                    {
                        throw new EndOfStreamException("Expected at least " + n + " bytes to read the string characters.");
                    }

                    return Encoding.UTF8.GetString(buffer, 0, len - 1);
                }
                finally
                {
                    if (len - 1 <= MAX_POOLED_STRING_BYTES)
                    {
                        s_stringPool.Release(buffer);
                    }
                }
            }

            return null;
        }

19 Source : StreamHelpers.cs
with MIT License
from reaqtive

public static string ReadString(this Stream stream)
        {
            var len = stream.ReadUInt32Compact();

            if (len > 0U)
            {
                var buffer = new byte[len - 1];
                var n = stream.Read(buffer, 0, buffer.Length);
                if (n < buffer.Length)
                {
                    throw new EndOfStreamException("Expected at least " + n + " bytes to read the string characters.");
                }

                return Encoding.UTF8.GetString(buffer);
            }

            return null;
        }