use AppSerializerContext singleton
This commit is contained in:
		
							parent
							
								
									189b6b5f62
								
							
						
					
					
						commit
						9bb4d11f3e
					
				
					 2 changed files with 3 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,4 @@
 | 
			
		|||
using System.Text.Json;
 | 
			
		||||
using System.Text.Json.Serialization;
 | 
			
		||||
 | 
			
		||||
namespace TanksServer.Interactivity;
 | 
			
		||||
| 
						 | 
				
			
			@ -6,4 +7,5 @@ namespace TanksServer.Interactivity;
 | 
			
		|||
[JsonSerializable(typeof(IEnumerable<Player>))]
 | 
			
		||||
[JsonSerializable(typeof(IEnumerable<string>))]
 | 
			
		||||
[JsonSerializable(typeof(PlayerInfo))]
 | 
			
		||||
[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
 | 
			
		||||
internal sealed partial class AppSerializerContext : JsonSerializerContext;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,6 @@ internal sealed class PlayerInfoConnection(
 | 
			
		|||
    MapEntityManager entityManager
 | 
			
		||||
) : WebsocketServerConnection(logger, new ByteChannelWebSocket(rawSocket, logger, 0))
 | 
			
		||||
{
 | 
			
		||||
    private readonly AppSerializerContext _context = new(new JsonSerializerOptions(JsonSerializerDefaults.Web));
 | 
			
		||||
    private bool _wantsInfoOnTick = true;
 | 
			
		||||
    private byte[] _lastMessage = [];
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -54,7 +53,7 @@ internal sealed class PlayerInfoConnection(
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        var info = new PlayerInfo(player.Name, player.Scores, player.Controls.ToDisplayString(), tankInfo);
 | 
			
		||||
        var response = JsonSerializer.SerializeToUtf8Bytes(info, _context.PlayerInfo);
 | 
			
		||||
        var response = JsonSerializer.SerializeToUtf8Bytes(info, AppSerializerContext.Default.PlayerInfo);
 | 
			
		||||
 | 
			
		||||
        if (response.SequenceEqual(_lastMessage))
 | 
			
		||||
            return null;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue