Beispiel #1
0
        static public byte[] JsonSerialize <T>(T messageBody)
        {
            var message = new JsonNetMessage <T>();

            message.tbsGameMessage = messageBody;

            return(Encoding.ASCII.GetBytes(JsonSerializer.Serialize(message)));
        }
Beispiel #2
0
        static public T JsonDeserialize <T>(byte[] buffer)
        {
            var jsonMessage = new JsonNetMessage <T>();

            jsonMessage.tbsGameMessage = Activator.CreateInstance <T>();

            try
            {
                string jsonDoc = Encoding.UTF8.GetString(buffer, 0, buffer.Length).TrimEnd('\0');
                Console.WriteLine($"Deserialize -> {jsonDoc}");
                jsonMessage = JsonSerializer.Deserialize <JsonNetMessage <T> >(Encoding.UTF8.GetString(buffer, 0, buffer.Length).TrimEnd('\0'));
            }
            catch (JsonException)
            {
                Console.WriteLine($"{typeof(T)} -> Deserialize -> invalid doc");
            }

            return(jsonMessage.tbsGameMessage);
        }