/// <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 service descriptor proto.
        /// </summary>
        /// <param name="totalLength">
        /// The total length.
        /// </param>
        /// <param name="sd">
        /// The sd.
        /// </param>
        private void ServiceDescriptorProto(uint totalLength, ServiceDescriptor sd)
        {
            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;
                            sd.Name = GetString(length);
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2}, name = {3}", type, no, length, sd.Name));
                            ix += (int)length;
                            totalLength -= length;
                            break;
                        }

                    case 2: // MethodDescriptorProto options
                        {
                            uint length;
                            var ixl = GetVarint(out length);
                            ix += ixl;
                            totalLength -= (uint)ixl;
                            Write(string.Format("Type = {0}, F#= {1}, Length = {2} - MethodDescriptorProto", type, no, length));
                            var md = new MethodDescriptor();
                            sd.Methods.Add(md);
                            MethodDescriptorProto(length, md);
                            totalLength -= length;
                            break;
                        }

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

                            ServiceOptions(length, sd.Options);
                            totalLength -= length;
                            break;
                        }
                }
            }

            intend--;
        }