internal static async Task <IPacket> CreatePacketAsync(Message message, IFormatter formatter, string packetType) { Logger.Debug("Serializing message:"); Logger.Debug(message.ToString()); IPacket packet = new BackendPacketFactory().Create(packetType); using (MemoryStream stream = new MemoryStream()) { formatter.Attach(stream); await Message.SerializeAsync(message, formatter).ConfigureAwait(false); packet.ContentType = message.ContentType; packet.Encoding = formatter.Type; packet.Content = stream.ToArray(); return(packet); } }