Skip to content

Instantly share code, notes, and snippets.

@alexson
Last active January 13, 2022 09:34
Show Gist options
  • Save alexson/547cda13f4726f443570a17a8c304291 to your computer and use it in GitHub Desktop.
Save alexson/547cda13f4726f443570a17a8c304291 to your computer and use it in GitHub Desktop.
// Helper to serialize a String into a byte[] to be passed over the network
private byte[] SerializeString(string s)
{
_builderMemoryStream.Position = 0;
_builderMemoryStream.SetLength(0);
using (var binarySerializer = new BinarySerializer(_builderMemoryStream))
StringSerializer.Instance.Serialize(binarySerializer, s);
return _builderMemoryStream.ToArray();
}
// Helper to serialize a Vector3 into a byte[] to be passed over the network
private byte[] SerializeVector3(Vector3 vector)
{
_builderMemoryStream.Position = 0;
_builderMemoryStream.SetLength(0);
using (var binarySerializer = new BinarySerializer(_builderMemoryStream))
Vector3Serializer.Instance.Serialize(binarySerializer, vector);
return _builderMemoryStream.ToArray();
}
private byte[] SerializeQuaternionSerializer(Quaternion quaternion)
{
_builderMemoryStream.Position = 0;
_builderMemoryStream.SetLength(0);
using (var binarySerializer = new BinarySerializer(_builderMemoryStream))
QuaternionSerializer.Instance.Serialize(binarySerializer, quaternion);
return _builderMemoryStream.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment