RpcSaveResult.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using InABox.Core;
  4. namespace InABox.Rpc
  5. {
  6. public class RpcSaveResult : ISerializeBinary
  7. {
  8. public Type Type { get; set; }
  9. public Dictionary<string, object?>[] Deltas { get; set; }
  10. public RpcSaveResult()
  11. {
  12. Deltas = new Dictionary<string, object?>[] { };
  13. }
  14. public void SerializeBinary(CoreBinaryWriter writer)
  15. {
  16. writer.Write(Type.EntityName());
  17. writer.Write(Deltas.Length);
  18. foreach (var delta in Deltas)
  19. {
  20. writer.Write(delta.Count);
  21. foreach (var key in delta.Keys)
  22. {
  23. writer.Write(key);
  24. writer.WriteBinaryValue(delta[key]);
  25. }
  26. }
  27. }
  28. public void DeserializeBinary(CoreBinaryReader reader)
  29. {
  30. List<Dictionary<String, object?>> deltas = new List<Dictionary<string, object?>>();
  31. String typename = reader.ReadString();
  32. var type = CoreUtils.GetEntityOrNull(typename);
  33. int deltacount = reader.ReadInt32();
  34. for (int iDelta = 0; iDelta < deltacount; iDelta++)
  35. {
  36. Dictionary<String, object?> delta = new Dictionary<string, object?>();
  37. int keycount = reader.ReadInt32();
  38. for (int iKey = 0; iKey < keycount; iKey++)
  39. {
  40. var key = reader.ReadString();
  41. var prop = CoreUtils.GetProperty(type, key);
  42. var value = reader.ReadBinaryValue(prop.PropertyType);
  43. delta[key] = value;
  44. }
  45. deltas.Add(delta);
  46. }
  47. Deltas = deltas.ToArray();
  48. }
  49. }
  50. }