Beispiel #1
0
        public static void WriteTo(this IMessage message, Span <byte> output)
        {
            ProtoPreconditions.CheckNotNull(message, nameof(message));

            WriteContext.Initialize(ref output, out WriteContext ctx);
            WritingPrimitivesMessages.WriteRawMessage(ref ctx, message);
            ctx.CheckNoSpaceLeft();
        }
Beispiel #2
0
        public static void WriteTo(this IMessage message, IBufferWriter <byte> output)
        {
            ProtoPreconditions.CheckNotNull(message, nameof(message));
            ProtoPreconditions.CheckNotNull(output, nameof(output));

            WriteContext.Initialize(output, out WriteContext ctx);
            WritingPrimitivesMessages.WriteRawMessage(ref ctx, message);
            ctx.Flush();
        }
Beispiel #3
0
        /// <summary>
        /// Writes a group, without a tag, to the stream.
        /// </summary>
        /// <param name="value">The value to write</param>
        public void WriteGroup(IMessage value)
        {
            var span = new Span <byte>(buffer);

            WriteContext.Initialize(ref span, ref state, out WriteContext ctx);
            try
            {
                WritingPrimitivesMessages.WriteGroup(ref ctx, value);
            }
            finally
            {
                ctx.CopyStateTo(this);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Writes a message, without a tag, to the stream.
        /// Only the message data is written, without a length-delimiter.
        /// </summary>
        /// <param name="value">The value to write</param>
        public void WriteRawMessage(IMessage value)
        {
            // TODO(jtattermusch): if the message doesn't implement IBufferMessage (and thus does not provide the InternalWriteTo method),
            // what we're doing here works fine, but could be more efficient.
            // For now, this inefficiency is fine, considering this is only a backward-compatibility scenario (and regenerating the code fixes it).
            var span = new Span <byte>(buffer);

            WriteContext.Initialize(ref span, ref state, out WriteContext ctx);
            try
            {
                WritingPrimitivesMessages.WriteRawMessage(ref ctx, value);
            }
            finally
            {
                ctx.CopyStateTo(this);
            }
        }
 /// <summary>
 /// Writes a group, without a tag, to the stream.
 /// </summary>
 /// <param name="value">The value to write</param>
 public void WriteGroup(IMessage value)
 {
     WritingPrimitivesMessages.WriteGroup(ref this, value);
 }
Beispiel #6
0
 /// <summary>
 /// Writes a message, without a tag.
 /// The data is length-prefixed.
 /// </summary>
 /// <param name="value">The value to write</param>
 public void WriteMessage(IMessage value) => WritingPrimitivesMessages.WriteMessage(ref this, value);