ms-lima / photonserializer Goto Github PK
View Code? Open in Web Editor NEWCustom Type Serializer For Photon(PUN2), Unity.
License: MIT License
Custom Type Serializer For Photon(PUN2), Unity.
License: MIT License
Hello, thanks for creating this serializer. It's very helpful, could you please help me with extending your serializer. I want to add serializing for byte[], but it gives me error about lenght of byte array, but I done this same as int[].
public static void Serialize(byte value, ref byte[] bytes)
{
byte[] _bytes = BitConverter.GetBytes(value);
if (BitConverter.IsLittleEndian)
Array.Reverse(_bytes);
JoinBytes(ref bytes, _bytes);
}
public static void Serialize(byte[] values, ref byte[] bytes)
{
int length = values == null ? 0 : values.Length;
if (length > 0)
{
Serialize(length, ref bytes);
for (int i = 0; i < values.Length; i++)
{
Serialize(values[i], ref bytes);
}
}
else
{
Serialize(0, ref bytes);
}
}
public static byte DeserializeByte(byte[] bytes, ref int offset)
{
byte[] _bytes = new byte[4];
Array.Copy(bytes, offset, _bytes, 0, 4);
if (BitConverter.IsLittleEndian)
Array.Reverse(_bytes);
offset += 4;
return (byte)BitConverter.ToInt16(_bytes, 0);
// int, float, bool vecot3, ve2 ,qua, string
}
public static byte[] DeserializeByteArray(byte[] bytes, ref int offset)
{
int length = DeserializeInt(bytes, ref offset);
if (length > 0)
{
byte[] array = new byte[length];
for (int i = 0; i < array.Length; i++)
{
array[i] = DeserializeByte(bytes, ref offset);
}
return array;
}
return new byte[0];
}
Good day, do you mind if I'll prepare your asset for package released on https://openupm.com? I wanna create Photon RaiseEvent Bus system, and I wanna add dependency onto your package to keep you as creator of this serializer.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.