IProtoSerializer.cs 2.8 KB

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