public void SerializeInteger() { byte[] resultBuffer = new byte[] { 0, 0, 4, 210 }; byte[] buffer = new byte[4]; int offset = 0; NumberSerializer.Serialize(1234, buffer, ref offset); Assert.AreEqual(resultBuffer, buffer); Assert.AreEqual(4, offset); }
public void ProcessPhotonData(byte[] payload) { if (payload.Length < PhotonHeaderLength) { return; } TickCount = Environment.TickCount; //TickCount = 146722234; int offset = 0; NumberDeserializer.Deserialize(out short peerId, payload, ref offset); ReadByte(out byte flags, payload, ref offset); ReadByte(out byte commandCount, payload, ref offset); NumberDeserializer.Deserialize(out int timestamp, payload, ref offset); NumberDeserializer.Deserialize(out int challenge, payload, ref offset); bool isEncrypted = flags == 1; bool isCrcEnabled = flags == 0xCC; if (isEncrypted) { // Encrypted packages are not supported return; } if (isCrcEnabled) { int ignoredOffset = 0; NumberDeserializer.Deserialize(out int crc, payload, ref ignoredOffset); NumberSerializer.Serialize(0, payload, ref offset); if (crc != CrcCalculator.Calculate(payload, payload.Length)) { // Invalid crc return; } } for (int commandIdx = 0; commandIdx < commandCount; commandIdx++) { HandleCommand(payload, ref offset); } }