SerializationContext.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #region Copyright notice and license
  2. // Copyright 2018 The gRPC Authors
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. using System.Buffers;
  18. namespace Grpc.Core
  19. {
  20. /// <summary>
  21. /// Provides storage for payload when serializing a message.
  22. /// </summary>
  23. public abstract class SerializationContext
  24. {
  25. /// <summary>
  26. /// Use the byte array as serialized form of current message and mark serialization process as complete.
  27. /// <c>Complete(byte[])</c> can only be called once. By calling this method the caller gives up the ownership of the
  28. /// payload which must not be accessed afterwards.
  29. /// </summary>
  30. /// <param name="payload">the serialized form of current message</param>
  31. public virtual void Complete(byte[] payload)
  32. {
  33. throw new NotImplementedException();
  34. }
  35. /// <summary>
  36. /// Gets buffer writer that can be used to write the serialized data. Once serialization is finished,
  37. /// <c>Complete()</c> needs to be called.
  38. /// </summary>
  39. public virtual IBufferWriter<byte> GetBufferWriter()
  40. {
  41. throw new NotImplementedException();
  42. }
  43. /// <summary>
  44. /// Complete the payload written to the buffer writer. <c>Complete()</c> can only be called once.
  45. /// </summary>
  46. public virtual void Complete()
  47. {
  48. throw new NotImplementedException();
  49. }
  50. }
  51. }