private static MqttBasePacket DecodeConnAckPacket(IMqttPacketBodyReader body) { ThrowIfBodyIsEmpty(body); var acknowledgeFlags = body.ReadByte(); var packet = new MqttConnAckPacket { IsSessionPresent = (acknowledgeFlags & 0x1) > 0, ReasonCode = (MqttConnectReasonCode)body.ReadByte() }; var propertiesReader = new MqttV500PropertiesReader(body); while (propertiesReader.MoveNext()) { if (packet.Properties == null) { packet.Properties = new MqttConnAckPacketProperties(); } if (propertiesReader.CurrentPropertyId == MqttPropertyId.SessionExpiryInterval) { packet.Properties.SessionExpiryInterval = propertiesReader.ReadSessionExpiryInterval(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.AuthenticationMethod) { packet.Properties.AuthenticationMethod = propertiesReader.ReadAuthenticationMethod(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.AuthenticationData) { packet.Properties.AuthenticationData = propertiesReader.ReadAuthenticationData(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.RetainAvailable) { packet.Properties.RetainAvailable = propertiesReader.ReadRetainAvailable(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ReceiveMaximum) { packet.Properties.ReceiveMaximum = propertiesReader.ReadReceiveMaximum(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.MaximumQoS) { packet.Properties.MaximumQoS = propertiesReader.ReadMaximumQoS(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.AssignedClientIdentifier) { packet.Properties.AssignedClientIdentifier = propertiesReader.ReadAssignedClientIdentifier(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.TopicAliasMaximum) { packet.Properties.TopicAliasMaximum = propertiesReader.ReadTopicAliasMaximum(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ReasonString) { packet.Properties.ReasonString = propertiesReader.ReadReasonString(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.MaximumPacketSize) { packet.Properties.MaximumPacketSize = propertiesReader.ReadMaximumPacketSize(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.WildcardSubscriptionAvailable) { packet.Properties.WildcardSubscriptionAvailable = propertiesReader.ReadWildcardSubscriptionAvailable(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.SubscriptionIdentifiersAvailable) { packet.Properties.SubscriptionIdentifiersAvailable = propertiesReader.ReadSubscriptionIdentifiersAvailable(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.SharedSubscriptionAvailable) { packet.Properties.SharedSubscriptionAvailable = propertiesReader.ReadSharedSubscriptionAvailable(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ServerKeepAlive) { packet.Properties.ServerKeepAlive = propertiesReader.ReadServerKeepAlive(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ResponseInformation) { packet.Properties.ResponseInformation = propertiesReader.ReadResponseInformation(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ServerReference) { packet.Properties.ServerReference = propertiesReader.ReadServerReference(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.UserProperty) { if (packet.Properties.UserProperties == null) { packet.Properties.UserProperties = new List <MqttUserProperty>(); } propertiesReader.AddUserPropertyTo(packet.Properties.UserProperties); } else { propertiesReader.ThrowInvalidPropertyIdException(typeof(MqttConnAckPacket)); } } return(packet); }