< Summary

Information
Class: Ice.Internal.Protocol
Assembly: Ice
File(s): /home/runner/work/ice/ice/csharp/src/Ice/Internal/Protocol.cs
Tag: 71_18251537082
Line coverage
95%
Covered lines: 40
Uncovered lines: 2
Coverable lines: 42
Total lines: 129
Line coverage: 95.2%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage
80%
Covered methods: 4
Total methods: 5
Method coverage: 80%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
checkSupportedEncoding(...)100%44100%
getCompatibleEncoding(...)100%44100%
isSupported(...)50%22100%
.ctor()100%210%

File(s)

/home/runner/work/ice/ice/csharp/src/Ice/Internal/Protocol.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace Ice.Internal;
 4
 5public sealed class Protocol
 6{
 7    //
 8    // Size of the Ice protocol header
 9    //
 10    // Magic number (4 bytes)
 11    // Protocol version major (Byte)
 12    // Protocol version minor (Byte)
 13    // Encoding version major (Byte)
 14    // Encoding version minor (Byte)
 15    // Message type (Byte)
 16    // Compression status (Byte)
 17    // Message size (Int)
 18    //
 19    internal const int headerSize = 14;
 20
 21    //
 22    // The magic number at the front of each message
 23    //
 124    internal static readonly byte[] magic = new byte[] { 0x49, 0x63, 0x65, 0x50 }; // 'I', 'c', 'e', 'P'
 25
 26    //
 27    // The current Ice protocol and Slice encoding version
 28    //
 29    internal const byte protocolMajor = 1;
 30    internal const byte protocolMinor = 0;
 31    internal const byte protocolEncodingMajor = 1;
 32    internal const byte protocolEncodingMinor = 0;
 33
 34    internal const byte encodingMajor = 1;
 35    internal const byte encodingMinor = 1;
 36
 37    public const byte OPTIONAL_END_MARKER = 0xFF;
 38
 39    public const byte FLAG_HAS_TYPE_ID_STRING = 1 << 0;
 40    public const byte FLAG_HAS_TYPE_ID_INDEX = 1 << 1;
 41    public const byte FLAG_HAS_TYPE_ID_COMPACT = (1 << 1) | (1 << 0);
 42    public const byte FLAG_HAS_OPTIONAL_MEMBERS = 1 << 2;
 43    public const byte FLAG_HAS_INDIRECTION_TABLE = 1 << 3;
 44    public const byte FLAG_HAS_SLICE_SIZE = 1 << 4;
 45    public const byte FLAG_IS_LAST_SLICE = 1 << 5;
 46
 47    //
 48    // The Ice protocol message types
 49    //
 50    internal const byte requestMsg = 0;
 51    internal const byte requestBatchMsg = 1;
 52    internal const byte replyMsg = 2;
 53    internal const byte validateConnectionMsg = 3;
 54    internal const byte closeConnectionMsg = 4;
 55
 156    internal static readonly byte[] requestHdr = new byte[]
 157    {
 158        magic[0], magic[1], magic[2], magic[3],
 159        protocolMajor, protocolMinor,
 160        protocolEncodingMajor, protocolEncodingMinor,
 161        requestMsg,
 162        0, // Compression status.
 163        0, 0, 0, 0, // Message size (placeholder).
 164        0, 0, 0, 0  // Request ID (placeholder).
 165    };
 66
 167    internal static readonly byte[] requestBatchHdr = new byte[]
 168    {
 169        magic[0], magic[1], magic[2], magic[3],
 170        protocolMajor, protocolMinor,
 171        protocolEncodingMajor, protocolEncodingMinor,
 172        requestBatchMsg,
 173        0, // Compression status.
 174        0, 0, 0, 0, // Message size (placeholder).
 175        0, 0, 0, 0  // Number of requests in batch (placeholder).
 176    };
 77
 178    internal static readonly byte[] replyHdr = new byte[]
 179    {
 180        magic[0], magic[1], magic[2], magic[3],
 181        protocolMajor, protocolMinor,
 182        protocolEncodingMajor, protocolEncodingMinor,
 183        replyMsg,
 184        0, // Compression status.
 185        0, 0, 0, 0 // Message size (placeholder).
 186    };
 87
 88    internal static void checkSupportedEncoding(Ice.EncodingVersion v)
 89    {
 190        if (v.major != encodingMajor || v.minor > encodingMinor)
 91        {
 192            throw new MarshalException(
 193                $"This Ice runtime does not support encoding version {v.major}.{v.minor}");
 94        }
 195    }
 96
 97    //
 98    // Either return the given encoding if not compatible, or the greatest
 99    // supported encoding otherwise.
 100    //
 101    internal static Ice.EncodingVersion
 102    getCompatibleEncoding(Ice.EncodingVersion v)
 103    {
 1104        if (v.major != Ice.Util.currentEncoding.major)
 105        {
 1106            return v; // Unsupported encoding, return as is.
 107        }
 1108        else if (v.minor < Ice.Util.currentEncoding.minor)
 109        {
 1110            return v; // Supported encoding.
 111        }
 112        else
 113        {
 114            //
 115            // Unsupported but compatible, use the currently supported
 116            // encoding, that's the best we can do.
 117            //
 1118            return Ice.Util.currentEncoding;
 119        }
 120    }
 121
 122    internal static bool
 123    isSupported(Ice.EncodingVersion version, Ice.EncodingVersion supported) =>
 1124        version.major == supported.major && version.minor <= supported.minor;
 125
 0126    private Protocol()
 127    {
 0128    }
 129}