Created
May 1, 2022 05:56
-
-
Save Tunied/018a39708615441819200e4b3bf569db to your computer and use it in GitHub Desktop.
在 Mirror 中 Sync Protobuf
This file contains hidden or 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
private static void Write_Common(NetworkWriter writer, IMessage _target) | |
{ | |
byte[] bytes = null; | |
if (_target != null) | |
{ | |
bytes = _target.ToByteArray(); | |
} | |
if (bytes is {Length: > 0}) | |
{ | |
var l = bytes.Length; | |
writer.Write(l); | |
writer.WriteBytes(bytes, 0, l); | |
} | |
else | |
{ | |
writer.Write(0); | |
} | |
} | |
private static T Read_Common<T>(NetworkReader reader) where T : class, IMessage<T>, new() | |
{ | |
var l = reader.ReadInt(); | |
var parser = new MessageParser<T>(() => new T()); | |
return parser.ParseFrom(reader.ReadBytes(l)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment