/// <summary>
        /// The file descriptor proto.
        /// </summary>
        /// <param name="totalLength">
        /// The total length.
        /// </param>
        /// <param name="fd">
        /// The file descriptor.
        /// </param>
        // ReSharper disable once FunctionComplexityOverflow
        private void FileDescriptorProto(uint totalLength, FileDescriptor fd)
        {
            intend++;

            while (totalLength != 0)
            {
                int type, no;
                var l = GetTypeAndFieldNo(out type, out no);
                ix += l;
                totalLength -= (uint)l;

                switch (no)
                {
                    case 1: // string name
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            fd.Name = GetString(length);
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2}, Name = {3}", type, no, length, fd.Name));
                            ix += (int)length;
                            totalLength -= length;
                            break;
                        }

                    case 2: // string package
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            fd.Package = GetString(length);
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2}, Package = {3}", type, no, length, fd.Package));
                            ix += (int)length;
                            totalLength -= length;
                            break;
                        }

                    case 3: // string[] dependecy
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            var value = GetString(length);
                            fd.Dependencies.Add(value);
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2}, Dependency = {3}", type, no, length, value));
                            ix += (int)length;
                            totalLength -= length;
                            break;
                        }

                    case 4: // DescriptorProto[] message type
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2} - DescriptorProto", type, no, length));
                            var md = new MessageDescriptor();
                            fd.MessageTypes.Add(md);
                            DescriptorProto(length, md);
                            totalLength -= length;
                            break;
                        }

                    case 5: // EnumDescriptorProto[] enum type
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2} - EnumDescriptorProto", type, no, length));
                            var ed = new EnumDescriptor();
                            fd.EnumTypes.Add(ed);
                            EnumDescriptorProto(length, ed);
                            totalLength -= length;
                            break;
                        }

                    case 6: // ServiceDescriptorProto[] service
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2} - ServiceDescriptorProto", type, no, length));
                            var sd = new ServiceDescriptor();
                            fd.Services.Add(sd);
                            ServiceDescriptorProto(length, sd);
                            totalLength -= length;
                            break;
                        }

                    case 7: // FieldDescriptorProto[] extension
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2} - FieldDescriptorProto", type, no, length));
                            var fd2 = new FieldDescriptor();
                            fd.Extensions.Add(fd2);
                            FieldDescriptorProto(length, fd2);
                            totalLength -= length;
                            break;
                        }

                    case 8: // FileOptions options
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2} - FileOptions", type, no, length));
                            if (fd.Options == null)
                            {
                                fd.Options = new FileOptions();
                            }

                            FileOptions(length, fd.Options);
                            totalLength -= length;
                            break;
                        }

                    case 9: // SourceCodeInfo source_code_info
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2} - SourceCodeInfo", type, no, length));
                            fd.SourceCodeInfo = new SourceCodeInfo();
                            ////SourceCodeInfo(length, fd.SourceCodeInfo);
                            ix += (int)length;
                            totalLength -= length;
                            break;
                        }

                    case 10: // int32[] public_dependency
                        {
                            uint value;
                            var ixl = GetVarint(out value);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            fd.PublicDependencies.Add((int)value);
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2}, public_dependency = {3}", type, no, ixl, value));
                            break;
                        }

                    case 11: // int32[] weak_dependency
                        {
                            uint value;
                            var ixl = GetVarint(out value);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            fd.WeakDependencies.Add((int)value);
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2}, weak_dependency = {3}", type, no, ixl, value));
                            break;
                        }
                }
            }

            intend--;
        }
        /// <summary>
        /// The file descriptor set.
        /// </summary>
        /// <param name="fd">
        /// The file descriptor.
        /// </param>
        private void FileDescriptorSet(FileDescriptor fd)
        {
            if (array[ix] == 0x0a)
            {
                ix++;
                uint length;
                var ixl = GetVarint(out length);
                Write("FileDescriptorProto Length = " + length);
                ix += ixl;

                FileDescriptorProto(length, fd);
            }
        }
        /// <summary>
        /// The run.
        /// </summary>
        /// <param name="filename">
        /// The filename.
        /// </param>
        private void Run(string filename)
        {
            array = File.ReadAllBytes(filename);

            Write("Message langth = " + array.Length);

            var def = new FileDescriptorSet();

            var fd = new FileDescriptor();
            def.File.Add(fd);

            FileDescriptorSet(fd);

            Console.ReadKey();
        }