< Summary

Information
Class: IceRpc.Internal.IceDefinitions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/IceDefinitions.cs
Tag: 275_13775359185
Line coverage
88%
Covered lines: 44
Uncovered lines: 6
Coverable lines: 50
Total lines: 82
Line coverage: 88%
Branch coverage
75%
Covered branches: 12
Total branches: 16
Branch coverage: 75%
Method coverage
100%
Covered methods: 3
Total methods: 3
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
CheckPrologue(...)75%25.491666.66%
BytesToString(...)100%11100%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace IceRpc.Internal;
 4
 5// Definitions for the ice protocol.
 6internal static class IceDefinitions
 7{
 8    // Size of an ice frame prologue:
 9    // Magic number (4 bytes)
 10    // Protocol bytes (4 bytes)
 11    // Frame type (Byte)
 12    // Compression status (Byte)
 13    // Frame size (Int - 4 bytes)
 14    internal const int PrologueSize = 14;
 15
 16    // The magic number at the front of each frame.
 317    internal static readonly byte[] Magic = "IceP"u8.ToArray(); // 'I', 'c', 'e', 'P'
 18
 19    // 4-bytes after magic that provide the protocol version (always 1.0 for an ice frame) and the encoding of the
 20    // frame header (always set to 1.0 with an ice frame, even though we use Slice1).
 321    internal static readonly byte[] ProtocolBytes = new byte[] { 1, 0, 1, 0 };
 22
 323    internal static readonly IcePrologue CloseConnectionFrame = new(
 324        Magic[0],
 325        Magic[1],
 326        Magic[2],
 327        Magic[3],
 328        ProtocolBytes[0],
 329        ProtocolBytes[1],
 330        ProtocolBytes[2],
 331        ProtocolBytes[3],
 332        IceFrameType.CloseConnection,
 333        compressionStatus: 0,
 334        PrologueSize);
 35
 336    internal static readonly byte[] FramePrologue = new byte[]
 337    {
 338        Magic[0], Magic[1], Magic[2], Magic[3],
 339        ProtocolBytes[0], ProtocolBytes[1], ProtocolBytes[2], ProtocolBytes[3],
 340    };
 41
 342    internal static readonly IcePrologue ValidateConnectionFrame = new(
 343        Magic[0],
 344        Magic[1],
 345        Magic[2],
 346        Magic[3],
 347        ProtocolBytes[0],
 348        ProtocolBytes[1],
 349        ProtocolBytes[2],
 350        ProtocolBytes[3],
 351        IceFrameType.ValidateConnection,
 352        compressionStatus: 0,
 353        PrologueSize);
 54
 55    // Verify that the first 8 bytes correspond to Magic + ProtocolBytes
 56    internal static void CheckPrologue(IcePrologue prologue)
 561657    {
 561658        if (prologue.Magic1 != Magic[0] ||
 561659            prologue.Magic2 != Magic[1] ||
 561660            prologue.Magic3 != Magic[2] ||
 561661            prologue.Magic4 != Magic[3])
 462        {
 463            byte[] magic = new byte[] { prologue.Magic1, prologue.Magic2, prologue.Magic3, prologue.Magic4 };
 464            throw new InvalidDataException(
 465                $"Received incorrect magic bytes in the prologue of an ice frame: '{BytesToString(magic)}'.");
 66        }
 67
 561268        if (prologue.ProtocolMajor != ProtocolBytes[0] || prologue.ProtocolMinor != ProtocolBytes[1])
 069        {
 070            throw new InvalidDataException(
 071                $"Received unexpected protocol in the prologue of an ice frame: '{prologue.ProtocolMajor}.{prologue.Prot
 72        }
 73
 561274        if (prologue.EncodingMajor != ProtocolBytes[2] || prologue.EncodingMinor != ProtocolBytes[3])
 075        {
 076            throw new InvalidDataException(
 077                $"Received unexpected protocol encoding in the prologue of an ice frame: '{prologue.EncodingMajor}.{prol
 78        }
 561279    }
 80
 481    private static string BytesToString(ReadOnlySpan<byte> bytes) => BitConverter.ToString(bytes.ToArray());
 82}