MqttPacket DecodeConnAckPacket(ArraySegment <byte> body) { ThrowIfBodyIsEmpty(body); _bufferReader.SetBuffer(body.Array, body.Offset, body.Count); var acknowledgeFlags = _bufferReader.ReadByte(); var packet = new MqttConnAckPacket { IsSessionPresent = (acknowledgeFlags & 0x1) > 0, ReasonCode = (MqttConnectReasonCode)_bufferReader.ReadByte(), // indicate that a feature is available. // Set all default values according to specification. When they are missing the often RetainAvailable = true, SharedSubscriptionAvailable = true, SubscriptionIdentifiersAvailable = true, WildcardSubscriptionAvailable = true, // Absence indicates max QoS level. MaximumQoS = MqttQualityOfServiceLevel.ExactlyOnce }; var propertiesReader = new MqttV5PropertiesReader(_bufferReader); while (propertiesReader.MoveNext()) { if (propertiesReader.CurrentPropertyId == MqttPropertyId.SessionExpiryInterval) { packet.SessionExpiryInterval = propertiesReader.ReadSessionExpiryInterval(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.AuthenticationMethod) { packet.AuthenticationMethod = propertiesReader.ReadAuthenticationMethod(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.AuthenticationData) { packet.AuthenticationData = propertiesReader.ReadAuthenticationData(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.RetainAvailable) { packet.RetainAvailable = propertiesReader.ReadRetainAvailable(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ReceiveMaximum) { packet.ReceiveMaximum = propertiesReader.ReadReceiveMaximum(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.MaximumQoS) { packet.MaximumQoS = propertiesReader.ReadMaximumQoS(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.AssignedClientIdentifier) { packet.AssignedClientIdentifier = propertiesReader.ReadAssignedClientIdentifier(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.TopicAliasMaximum) { packet.TopicAliasMaximum = propertiesReader.ReadTopicAliasMaximum(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ReasonString) { packet.ReasonString = propertiesReader.ReadReasonString(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.MaximumPacketSize) { packet.MaximumPacketSize = propertiesReader.ReadMaximumPacketSize(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.WildcardSubscriptionAvailable) { packet.WildcardSubscriptionAvailable = propertiesReader.ReadWildcardSubscriptionAvailable(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.SubscriptionIdentifiersAvailable) { packet.SubscriptionIdentifiersAvailable = propertiesReader.ReadSubscriptionIdentifiersAvailable(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.SharedSubscriptionAvailable) { packet.SharedSubscriptionAvailable = propertiesReader.ReadSharedSubscriptionAvailable(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ServerKeepAlive) { packet.ServerKeepAlive = propertiesReader.ReadServerKeepAlive(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ResponseInformation) { packet.ResponseInformation = propertiesReader.ReadResponseInformation(); } else if (propertiesReader.CurrentPropertyId == MqttPropertyId.ServerReference) { packet.ServerReference = propertiesReader.ReadServerReference(); } else { propertiesReader.ThrowInvalidPropertyIdException(typeof(MqttConnAckPacket)); } } packet.UserProperties = propertiesReader.CollectedUserProperties; return(packet); }