< Summary

Information
Class: IceRpc.Protobuf.Internal.MessageExtensions
Assembly: IceRpc.Protobuf
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Protobuf/Internal/MessageExtensions.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 29
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 1
Total methods: 1
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
EncodeAsLengthPrefixedMessage(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Protobuf/Internal/MessageExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using Google.Protobuf;
 4using System.Buffers;
 5using System.Buffers.Binary;
 6using System.IO.Pipelines;
 7
 8namespace IceRpc.Protobuf.Internal;
 9
 10/// <summary>Provides an extension method for <see cref="IMessage" />.</summary>
 11internal static class MessageExtensions
 12{
 13    /// <summary>Encodes an <see cref="IMessage"/> as a length-prefixed message, using the Protobuf encoding.</summary>
 14    /// <param name="message">The <see cref="IMessage" /> to encode.</param>
 15    /// <param name="pipeOptions">The options used to create the pipe.</param>
 16    /// <returns>A <see cref="PipeReader" /> containing the length-prefixed message.</returns>
 17    internal static PipeReader EncodeAsLengthPrefixedMessage(this IMessage message, PipeOptions pipeOptions)
 5418    {
 5419        var pipe = new Pipe(pipeOptions);
 5420        pipe.Writer.Write(new Span<byte>([0])); // Not compressed
 5421        Span<byte> lengthPlaceholder = pipe.Writer.GetSpan(4);
 5422        pipe.Writer.Advance(4);
 5423        message.WriteTo(pipe.Writer);
 5424        int length = checked((int)pipe.Writer.UnflushedBytes);
 5425        BinaryPrimitives.WriteInt32BigEndian(lengthPlaceholder, length - 5);
 5426        pipe.Writer.Complete();
 5427        return pipe.Reader;
 5428    }
 29}