public Stream ReadLengthPrefixedStream(int bufferSize)
        {
            if (bufferSize < 1)
            {
                throw new ArgumentOutOfRangeException("bufferSize", string.Format("The provided value '{0}' is not a positive integer.", bufferSize));
            }

            var length = ProtocolBuffersEncoding.ReadUInt64(_stream);

            if (length > int.MaxValue)
            {
                throw new InvalidOperationException("Cannot read length prefixed stream with size more than int.MaxValue.");
            }
            //throw new ArgumentOutOfRangeException(string.Empty, "Cannot read length prefixed stream with size more than int.MaxValue.");

            // TODO implement using http://www.codeproject.com/Articles/13061/StreamMuxer
            var ms = new MemoryStream((int)length);

            _stream.CopyTo(ms, bufferSize);
            return(ms);
        }
 public ulong ReadUInt64()
 {
     return(ProtocolBuffersEncoding.ReadUInt64(_stream));
 }