mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
feat: support sending and receiving ArraySegment<byte> (#898)
Add ArraySegment<byte> support to the weaver
This commit is contained in:
parent
954a3d594d
commit
e5eecbff72
@ -48,6 +48,7 @@ public static void Init(AssemblyDefinition CurrentAssembly)
|
|||||||
{ Weaver.NetworkIdentityType.FullName, Resolvers.ResolveMethod(networkReaderType, CurrentAssembly, "ReadNetworkIdentity") },
|
{ Weaver.NetworkIdentityType.FullName, Resolvers.ResolveMethod(networkReaderType, CurrentAssembly, "ReadNetworkIdentity") },
|
||||||
{ Weaver.transformType.FullName, Resolvers.ResolveMethod(networkReaderType, CurrentAssembly, "ReadTransform") },
|
{ Weaver.transformType.FullName, Resolvers.ResolveMethod(networkReaderType, CurrentAssembly, "ReadTransform") },
|
||||||
{ "System.Byte[]", Resolvers.ResolveMethod(networkReaderType, CurrentAssembly, "ReadBytesAndSize") },
|
{ "System.Byte[]", Resolvers.ResolveMethod(networkReaderType, CurrentAssembly, "ReadBytesAndSize") },
|
||||||
|
{ "System.ArraySegment`1<System.Byte>", Resolvers.ResolveMethod(networkReaderType, CurrentAssembly, "ReadBytesSegment") }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,8 @@ public static void Init(AssemblyDefinition CurrentAssembly)
|
|||||||
{ Weaver.gameObjectType.FullName, Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "Write", Weaver.gameObjectType) },
|
{ Weaver.gameObjectType.FullName, Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "Write", Weaver.gameObjectType) },
|
||||||
{ Weaver.NetworkIdentityType.FullName, Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "Write", Weaver.NetworkIdentityType) },
|
{ Weaver.NetworkIdentityType.FullName, Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "Write", Weaver.NetworkIdentityType) },
|
||||||
{ Weaver.transformType.FullName, Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "Write", Weaver.transformType) },
|
{ Weaver.transformType.FullName, Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "Write", Weaver.transformType) },
|
||||||
{ "System.Byte[]", Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "WriteBytesAndSize", "System.Byte[]") }
|
{ "System.Byte[]", Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "WriteBytesAndSize", "System.Byte[]") },
|
||||||
|
{ "System.ArraySegment`1<System.Byte>", Resolvers.ResolveMethodWithArg(networkWriterType, CurrentAssembly, "WriteBytesSegment", "System.ArraySegment`1<System.Byte>") }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ public byte[] ReadBytes(int count)
|
|||||||
// Use checked() to force it to throw OverflowException if data is invalid
|
// Use checked() to force it to throw OverflowException if data is invalid
|
||||||
// null support, see NetworkWriter
|
// null support, see NetworkWriter
|
||||||
public byte[] ReadBytesAndSize() => ReadBoolean() ? ReadBytes(checked((int)ReadPackedUInt32())) : null;
|
public byte[] ReadBytesAndSize() => ReadBoolean() ? ReadBytes(checked((int)ReadPackedUInt32())) : null;
|
||||||
|
public ArraySegment<byte> ReadBytesSegment() => new ArraySegment<byte>(ReadBytesAndSize());
|
||||||
|
|
||||||
// zigzag decoding https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba
|
// zigzag decoding https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba
|
||||||
public int ReadPackedInt32()
|
public int ReadPackedInt32()
|
||||||
|
@ -94,6 +94,11 @@ public void WriteBytesAndSize(byte[] buffer)
|
|||||||
WriteBytesAndSize(buffer, 0, buffer != null ? buffer.Length : 0);
|
WriteBytesAndSize(buffer, 0, buffer != null ? buffer.Length : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void WriteBytesSegment(ArraySegment<byte> buffer)
|
||||||
|
{
|
||||||
|
WriteBytesAndSize(buffer.Array, buffer.Offset, buffer.Count);
|
||||||
|
}
|
||||||
|
|
||||||
// zigzag encoding https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba
|
// zigzag encoding https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba
|
||||||
public void WritePackedInt32(int i)
|
public void WritePackedInt32(int i)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user