IProtoSerializer.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #if !NO_RUNTIME
  2. using System;
  3. namespace ProtoBuf.Serializers
  4. {
  5. interface IProtoSerializer
  6. {
  7. /// <summary>
  8. /// The type that this serializer is intended to work for.
  9. /// </summary>
  10. Type ExpectedType { get; }
  11. /// <summary>
  12. /// Perform the steps necessary to serialize this data.
  13. /// </summary>
  14. /// <param name="value">The value to be serialized.</param>
  15. /// <param name="dest">The writer entity that is accumulating the output data.</param>
  16. void Write(object value, ProtoWriter dest);
  17. /// <summary>
  18. /// Perform the steps necessary to deserialize this data.
  19. /// </summary>
  20. /// <param name="value">The current value, if appropriate.</param>
  21. /// <param name="source">The reader providing the input data.</param>
  22. /// <returns>The updated / replacement value.</returns>
  23. object Read(object value, ProtoReader source);
  24. /// <summary>
  25. /// Indicates whether a Read operation <em>replaces</em> the existing value, or
  26. /// <em>extends</em> the value. If false, the "value" parameter to Read is
  27. /// discarded, and should be passed in as null.
  28. /// </summary>
  29. bool RequiresOldValue { get; }
  30. /// <summary>
  31. /// Now all Read operations return a value (although most do); if false no
  32. /// value should be expected.
  33. /// </summary>
  34. bool ReturnsValue { get; }
  35. #if FEAT_COMPILER
  36. /// <summary>Emit the IL necessary to perform the given actions
  37. /// to serialize this data.
  38. /// </summary>
  39. /// <param name="ctx">Details and utilities for the method being generated.</param>
  40. /// <param name="valueFrom">The source of the data to work against;
  41. /// If the value is only needed once, then LoadValue is sufficient. If
  42. /// the value is needed multiple times, then note that a "null"
  43. /// means "the top of the stack", in which case you should create your
  44. /// own copy - GetLocalWithValue.</param>
  45. void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom);
  46. /// <summary>
  47. /// Emit the IL necessary to perform the given actions to deserialize this data.
  48. /// </summary>
  49. /// <param name="ctx">Details and utilities for the method being generated.</param>
  50. /// <param name="entity">For nested values, the instance holding the values; note
  51. /// that this is not always provided - a null means not supplied. Since this is always
  52. /// a variable or argument, it is not necessary to consume this value.</param>
  53. void EmitRead(Compiler.CompilerContext ctx, Compiler.Local entity);
  54. #endif
  55. }
  56. }
  57. #endif