немного изменена логика работы TransmittedSharedObject, получается теперь, работает даже быстрее
This commit is contained in:
@@ -41,9 +41,7 @@ public class JsonSerialisationModule : ISerialisationModule
|
|||||||
|
|
||||||
public void PostResponse(NetworkMessage message, int clientId)
|
public void PostResponse(NetworkMessage message, int clientId)
|
||||||
{
|
{
|
||||||
var texted = JsonSerializer.Serialize(message);
|
_dataSource!.SendTo(clientId, JsonSerializer.SerializeToUtf8Bytes(message));
|
||||||
var binary = Encoding.UTF8.GetBytes(texted);
|
|
||||||
_dataSource!.SendTo(clientId, binary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Inject<T>(T dependency)
|
public void Inject<T>(T dependency)
|
||||||
|
|||||||
@@ -14,21 +14,33 @@ public class TransmittedSharedObject<T> where T : notnull
|
|||||||
throw new NullReferenceException(
|
throw new NullReferenceException(
|
||||||
"DefaultContextRepository was not defined");
|
"DefaultContextRepository was not defined");
|
||||||
|
|
||||||
|
private int _contextId = -1;
|
||||||
|
|
||||||
// ReSharper disable once MemberCanBePrivate.Global
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public int ContextId { get; init; } = -1;
|
public int ContextId
|
||||||
|
{
|
||||||
|
get => _contextId;
|
||||||
|
init
|
||||||
|
{
|
||||||
|
_contextId = value;
|
||||||
|
Value = GetDefaultContextRepository().GetObject<T>(_contextId)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public T? Value => GetDefaultContextRepository().GetObject<T>(ContextId);
|
public T Value { get; private set; }
|
||||||
|
|
||||||
public TransmittedSharedObject()
|
public TransmittedSharedObject()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
// ReSharper disable once UnusedMember.Global
|
||||||
public TransmittedSharedObject(T value)
|
public TransmittedSharedObject(T value)
|
||||||
{
|
{
|
||||||
ContextId = GetDefaultContextRepository().GetObjectIndex(value);
|
Value = value;
|
||||||
|
_contextId = GetDefaultContextRepository().GetObjectIndex(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator T(TransmittedSharedObject<T> value) => value.Value!;
|
public static implicit operator T(TransmittedSharedObject<T> value) => value.Value;
|
||||||
|
|
||||||
public static implicit operator TransmittedSharedObject<T>(T value) =>
|
public static implicit operator TransmittedSharedObject<T>(T value) =>
|
||||||
new() { ContextId = GetDefaultContextRepository().GetObjectIndex(value) };
|
new() { ContextId = GetDefaultContextRepository().GetObjectIndex(value) };
|
||||||
|
|||||||
Reference in New Issue
Block a user