Skip to content

Commit 48cb97c

Browse files
committed
Fixed generic write for signed values
1 parent c27e4c3 commit 48cb97c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitWriter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ private void Push<T>(T b)
102102
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("The type \"" + b.GetType() + "\" is not supported by the Binary Serializer. It will be ignored");
103103
}
104104

105-
public void WriteValueTypeOrString<T>(T t) => Push(t);
105+
private void PushPreZigZag<T>(T b)
106+
{
107+
if (b is sbyte || b is short || b is int || b is long) Push(ZigZagEncode((long)(object)b)); //BOX
108+
else Push(b);
109+
}
110+
111+
public void WriteValueTypeOrString<T>(T t) => PushPreZigZag(t);
106112
public void WriteValueType(ValueType v) => Push(v);
107113
public void WriteBool(bool b) => Push(b);
108114
public void WriteFloat(float f) => Push(f);

0 commit comments

Comments
 (0)