Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SerializedCLreMessage.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.IO;
  2. using NetworkFramework.Shared;
  3. namespace CLre_server.API.Synergy
  4. {
  5. public struct SerializedCLreMessage: ISerializedNetData
  6. {
  7. public uint Id;
  8. public byte[] Data;
  9. public byte[] Serialize()
  10. {
  11. using (MemoryStream stream = new MemoryStream())
  12. {
  13. using (BinaryWriter writer = new BinaryWriter(stream))
  14. {
  15. writer.Write(Id);
  16. writer.Write(Data.Length);
  17. foreach (byte b in Data)
  18. {
  19. writer.Write(b);
  20. }
  21. return stream.ToArray();
  22. }
  23. }
  24. }
  25. public void Deserialize(byte[] data)
  26. {
  27. using (MemoryStream stream = new MemoryStream(data))
  28. {
  29. using (BinaryReader reader = new BinaryReader(stream))
  30. {
  31. Id = reader.ReadUInt32();
  32. Data = new byte[reader.ReadInt32()];
  33. for (int i = 0; i < Data.Length; i++)
  34. {
  35. Data[i] = reader.ReadByte();
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }