Google.Protobuf.ServiceDescriptorProto.DeserializeLength C# (CSharp) Method

DeserializeLength() public static method

Read the given number of bytes from the stream and deserialze it into the instance.
public static DeserializeLength ( Stream stream, int length, Google instance ) : Google.Protobuf.ServiceDescriptorProto
stream Stream
length int
instance Google
return Google.Protobuf.ServiceDescriptorProto
        public static Google.Protobuf.ServiceDescriptorProto DeserializeLength(Stream stream, int length, Google.Protobuf.ServiceDescriptorProto instance)
        {
            if (instance.Method == null)
                instance.Method = new List<Google.Protobuf.MethodDescriptorProto>();
            long limit = stream.Position + length;
            while (true)
            {
                if (stream.Position >= limit)
                {
                    if (stream.Position == limit)
                        break;
                    else
                        throw new global::SilentOrbit.ProtocolBuffers.ProtocolBufferException("Read past max limit");
                }
                int keyByte = stream.ReadByte();
                if (keyByte == -1)
                    throw new System.IO.EndOfStreamException();
                // Optimized reading of known fields with field ID < 16
                switch (keyByte)
                {
                    // Field 1 LengthDelimited
                    case 10:
                        instance.Name = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 2 LengthDelimited
                    case 18:
                        // repeated
                        instance.Method.Add(Google.Protobuf.MethodDescriptorProto.DeserializeLengthDelimited(stream));
                        continue;
                    // Field 3 LengthDelimited
                    case 26:
                        if (instance.Options == null)
                            instance.Options = Google.Protobuf.ServiceOptions.DeserializeLengthDelimited(stream);
                        else
                            Google.Protobuf.ServiceOptions.DeserializeLengthDelimited(stream, instance.Options);
                        continue;
                }

                var key = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadKey((byte)keyByte, stream);

                // Reading field ID > 16 and unknown field ID/wire type combinations
                switch (key.Field)
                {
                    case 0:
                        throw new global::SilentOrbit.ProtocolBuffers.ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    default:
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.SkipKey(stream, key);
                        break;
                }
            }

            return instance;
        }

Same methods

ServiceDescriptorProto::DeserializeLength ( Stream stream, int length ) : ServiceDescriptorProto