-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new generic Read and Write methods for all types (#2301)
Currently in mirror, there is no way for Mirror itself to invoke readers and writers for types it does not know about. This causes us to have to generate code for lists, dictionaries and messages. This PR makes it so that if there is a reader and writer anywhere in the code for type X, then the writer can be invoked like this: ```cs X x = ...; writer.Write<X>(x); ``` and the reader can be invoked like this: ```cs X x = reader.Read<X>(); ```
- Loading branch information
Showing
9 changed files
with
234 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using NUnit.Framework; | ||
|
||
namespace Mirror.Tests | ||
{ | ||
[TestFixture] | ||
public class NetworkReaderWriterTest | ||
{ | ||
[Test] | ||
public void TestIntWriterNotNull() | ||
{ | ||
Assert.That(Writer<int>.write, Is.Not.Null); | ||
} | ||
|
||
[Test] | ||
public void TestIntReaderNotNull() | ||
{ | ||
Assert.That(Reader<int>.read, Is.Not.Null); | ||
} | ||
|
||
[Test] | ||
public void TestAccessingCustomWriterAndReader() | ||
{ | ||
NetworkWriter writer = new NetworkWriter(); | ||
writer.Write<int>(3); | ||
NetworkReader reader = new NetworkReader(writer.ToArray()); | ||
int copy = reader.Read<int>(); | ||
|
||
Assert.That(copy, Is.EqualTo(3)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Mirror/Tests/Editor/NetworkReaderWriterTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.