IExtension.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 
  2. using System.IO;
  3. namespace ProtoBuf
  4. {
  5. /// <summary>
  6. /// Provides addition capability for supporting unexpected fields during
  7. /// protocol-buffer serialization/deserialization. This allows for loss-less
  8. /// round-trip/merge, even when the data is not fully understood.
  9. /// </summary>
  10. public interface IExtension
  11. {
  12. /// <summary>
  13. /// Requests a stream into which any unexpected fields can be persisted.
  14. /// </summary>
  15. /// <returns>A new stream suitable for storing data.</returns>
  16. Stream BeginAppend();
  17. /// <summary>
  18. /// Indicates that all unexpected fields have now been stored. The
  19. /// implementing class is responsible for closing the stream. If
  20. /// "commit" is not true the data may be discarded.
  21. /// </summary>
  22. /// <param name="stream">The stream originally obtained by BeginAppend.</param>
  23. /// <param name="commit">True if the append operation completed successfully.</param>
  24. void EndAppend(Stream stream, bool commit);
  25. /// <summary>
  26. /// Requests a stream of the unexpected fields previously stored.
  27. /// </summary>
  28. /// <returns>A prepared stream of the unexpected fields.</returns>
  29. Stream BeginQuery();
  30. /// <summary>
  31. /// Indicates that all unexpected fields have now been read. The
  32. /// implementing class is responsible for closing the stream.
  33. /// </summary>
  34. /// <param name="stream">The stream originally obtained by BeginQuery.</param>
  35. void EndQuery(Stream stream);
  36. /// <summary>
  37. /// Requests the length of the raw binary stream; this is used
  38. /// when serializing sub-entities to indicate the expected size.
  39. /// </summary>
  40. /// <returns>The length of the binary stream representing unexpected data.</returns>
  41. int GetLength();
  42. }
  43. /// <summary>
  44. /// Provides the ability to remove all existing extension data
  45. /// </summary>
  46. public interface IExtensionResettable : IExtension
  47. {
  48. /// <summary>
  49. /// Remove all existing extension data
  50. /// </summary>
  51. void Reset();
  52. }
  53. }