Personal.Person.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 ( System.Stream stream, int length, Personal instance ) : Personal.Person
stream System.Stream
length int
instance Personal
return Personal.Person
        public static Personal.Person DeserializeLength(Stream stream, int length, Personal.Person instance)
        {
            if (instance.Phone == null)
                instance.Phone = new List<Personal.Person.PhoneNumber>();
            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 Varint
                    case 16:
                        instance.Id = (int)global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadUInt64(stream);
                        continue;
                    // Field 3 LengthDelimited
                    case 26:
                        instance.Email = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadString(stream);
                        continue;
                    // Field 4 LengthDelimited
                    case 34:
                        // repeated
                        instance.Phone.Add(Personal.Person.PhoneNumber.DeserializeLengthDelimited(stream));
                        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

Person::DeserializeLength ( System.Stream stream, int length ) : Person