< Summary

Information
Class: Ice.Internal.OpaqueEndpointI
Assembly: Ice
File(s): /home/runner/work/ice/ice/csharp/src/Ice/Internal/OpaqueEndpointI.cs
Tag: 71_18251537082
Line coverage
44%
Covered lines: 49
Uncovered lines: 61
Coverable lines: 110
Total lines: 326
Line coverage: 44.5%
Branch coverage
37%
Covered branches: 21
Total branches: 56
Branch coverage: 37.5%
Method coverage
29%
Covered methods: 8
Total methods: 27
Method coverage: 29.6%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%44100%
.ctor(...)100%210%
streamWrite(...)100%11100%
ToString()100%11100%
getInfo()100%11100%
type()100%11100%
protocol()100%11100%
timeout()100%210%
timeout(...)100%210%
connectionId()100%210%
connectionId(...)100%210%
compress()100%210%
compress(...)100%210%
datagram()100%210%
secure()100%210%
rawBytes()100%210%
transceiver()100%210%
connectors_async(...)100%210%
acceptor(...)100%210%
expandHost()100%210%
isLoopbackOrMulticast()100%210%
toPublishedEndpoint(...)100%210%
equivalent(...)100%210%
GetHashCode()100%11100%
options()0%2040%
CompareTo(...)0%812280%
checkOption(...)85%20.952086.67%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Diagnostics;
 4using System.Globalization;
 5using System.Net.Security;
 6
 7namespace Ice.Internal;
 8
 9internal sealed class OpaqueEndpointI : EndpointI
 10{
 111    public OpaqueEndpointI(List<string> args)
 12    {
 113        _type = -1;
 114        _rawEncoding = Ice.Util.Encoding_1_0;
 115        _rawBytes = [];
 16
 117        initWithOptions(args);
 18
 119        if (_type < 0)
 20        {
 121            throw new ParseException($"no -t option in endpoint '{this}'");
 22        }
 123        if (_rawBytes.Length == 0)
 24        {
 125            throw new ParseException($"no -v option in endpoint '{this}'");
 26        }
 127    }
 28
 029    public OpaqueEndpointI(short type, Ice.InputStream s)
 30    {
 031        _type = type;
 032        _rawEncoding = s.getEncoding();
 033        int sz = s.getEncapsulationSize();
 034        _rawBytes = new byte[sz];
 035        s.readBlob(_rawBytes);
 036    }
 37
 38    //
 39    // Marshal the endpoint
 40    //
 41    public override void streamWrite(Ice.OutputStream s)
 42    {
 143        s.startEncapsulation(_rawEncoding);
 144        s.writeBlob(_rawBytes);
 145        s.endEncapsulation();
 146    }
 47
 48    public override void streamWriteImpl(Ice.OutputStream s) => Debug.Assert(false);
 49
 50    //
 51    // Convert the endpoint to its string form
 52    //
 53    public override string ToString()
 54    {
 155        string val = System.Convert.ToBase64String(_rawBytes);
 156        return "opaque -t " + _type + " -e " + Ice.Util.encodingVersionToString(_rawEncoding) + " -v " + val;
 57    }
 58
 59    //
 60    // Return the endpoint information.
 61    //
 162    public override EndpointInfo getInfo() => new OpaqueEndpointInfo(_type, _rawEncoding, _rawBytes);
 63
 64    //
 65    // Return the endpoint type
 66    //
 167    public override short type() => _type;
 68
 69    //
 70    // Return the protocol name;
 71    //
 172    public override string protocol() => "opaque";
 73
 74    //
 75    // Return the timeout for the endpoint in milliseconds. 0 means
 76    // non-blocking, -1 means no timeout.
 77    //
 078    public override int timeout() => -1;
 79
 80    //
 81    // Return a new endpoint with a different timeout value, provided
 82    // that timeouts are supported by the endpoint. Otherwise the same
 83    // endpoint is returned.
 84    //
 085    public override EndpointI timeout(int t) => this;
 86
 087    public override string connectionId() => "";
 88
 89    //
 90    // Return a new endpoint with a different connection id.
 91    //
 092    public override EndpointI connectionId(string id) => this;
 93
 94    //
 95    // Return true if the endpoints support bzip2 compress, or false
 96    // otherwise.
 97    //
 098    public override bool compress() => false;
 99
 100    //
 101    // Return a new endpoint with a different compression value,
 102    // provided that compression is supported by the
 103    // endpoint. Otherwise the same endpoint is returned.
 104    //
 0105    public override EndpointI compress(bool compress) => this;
 106
 107    //
 108    // Return true if the endpoint is datagram-based.
 109    //
 0110    public override bool datagram() => false;
 111
 112    //
 113    // Return true if the endpoint is secure.
 114    //
 0115    public override bool secure() => false;
 116
 117    //
 118    // Get the encoded endpoint.
 119    //
 0120    public byte[] rawBytes() => _rawBytes;
 121
 122    //
 123    // Return a server side transceiver for this endpoint, or null if a
 124    // transceiver can only be created by an acceptor.
 125    //
 0126    public override Transceiver transceiver() => null;
 127
 128    //
 129    // Return connectors for this endpoint, or empty list if no connector
 130    // is available.
 131    //
 0132    public override void connectors_async(EndpointI_connectors callback) => callback.connectors(new List<Connector>());
 133
 134    //
 135    // Return an acceptor for this endpoint, or null if no acceptors
 136    // is available.
 137    //
 138    public override Acceptor acceptor(string adapterName, SslServerAuthenticationOptions serverAuthenticationOptions) =>
 0139        null;
 140
 0141    public override List<EndpointI> expandHost() => [this];
 142
 0143    public override bool isLoopbackOrMulticast() => false;
 144
 0145    public override EndpointI toPublishedEndpoint(string host) => this;
 146
 147    //
 148    // Check whether the endpoint is equivalent to another one.
 149    //
 0150    public override bool equivalent(EndpointI endpoint) => false;
 151
 152    public override int GetHashCode()
 153    {
 1154        var hash = new HashCode();
 1155        hash.Add(_type);
 1156        hash.AddBytes(_rawBytes);
 1157        return hash.ToHashCode();
 158    }
 159
 160    public override string options()
 161    {
 0162        string s = "";
 0163        if (_type > -1)
 164        {
 0165            s += " -t " + _type;
 166        }
 0167        s += " -e " + Ice.Util.encodingVersionToString(_rawEncoding);
 0168        if (_rawBytes.Length > 0)
 169        {
 0170            s += " -v " + System.Convert.ToBase64String(_rawBytes);
 171        }
 0172        return s;
 173    }
 174
 175    //
 176    // Compare endpoints for sorting purposes
 177    //
 178    public override int CompareTo(EndpointI obj)
 179    {
 0180        if (!(obj is OpaqueEndpointI))
 181        {
 0182            return type() < obj.type() ? -1 : 1;
 183        }
 184
 0185        var p = (OpaqueEndpointI)obj;
 0186        if (this == p)
 187        {
 0188            return 0;
 189        }
 190
 0191        if (_type < p._type)
 192        {
 0193            return -1;
 194        }
 0195        else if (p._type < _type)
 196        {
 0197            return 1;
 198        }
 199
 0200        if (_rawEncoding.major < p._rawEncoding.major)
 201        {
 0202            return -1;
 203        }
 0204        else if (p._rawEncoding.major < _rawEncoding.major)
 205        {
 0206            return 1;
 207        }
 208
 0209        if (_rawEncoding.minor < p._rawEncoding.minor)
 210        {
 0211            return -1;
 212        }
 0213        else if (p._rawEncoding.minor < _rawEncoding.minor)
 214        {
 0215            return 1;
 216        }
 217
 0218        if (_rawBytes.Length < p._rawBytes.Length)
 219        {
 0220            return -1;
 221        }
 0222        else if (p._rawBytes.Length < _rawBytes.Length)
 223        {
 0224            return 1;
 225        }
 0226        for (int i = 0; i < _rawBytes.Length; i++)
 227        {
 0228            if (_rawBytes[i] < p._rawBytes[i])
 229            {
 0230                return -1;
 231            }
 0232            else if (p._rawBytes[i] < _rawBytes[i])
 233            {
 0234                return 1;
 235            }
 236        }
 237
 0238        return 0;
 239    }
 240
 241    protected override bool checkOption(string option, string argument, string endpoint)
 242    {
 1243        switch (option[1])
 244        {
 245            case 't':
 246            {
 1247                if (_type > -1)
 248                {
 1249                    throw new ParseException($"multiple -t options in endpoint '{endpoint}'");
 250                }
 1251                if (argument == null)
 252                {
 1253                    throw new ParseException($"no argument provided for -t option in endpoint '{endpoint}'");
 254                }
 255
 256                int t;
 257                try
 258                {
 1259                    t = int.Parse(argument, CultureInfo.InvariantCulture);
 1260                }
 1261                catch (FormatException ex)
 262                {
 1263                    throw new ParseException($"invalid type value '{argument}' in endpoint '{endpoint}'", ex);
 264                }
 265
 1266                if (t < 0 || t > 65535)
 267                {
 0268                    throw new ParseException($"type value '{argument}' out of range in endpoint '{endpoint}'");
 269                }
 270
 1271                _type = (short)t;
 1272                return true;
 273            }
 274
 275            case 'v':
 276            {
 1277                if (_rawBytes.Length > 0)
 278                {
 1279                    throw new ParseException($"multiple -v options in endpoint '{endpoint}'");
 280                }
 1281                if (argument == null)
 282                {
 1283                    throw new ParseException($"no argument provided for -v option in endpoint '{endpoint}'");
 284                }
 285
 286                try
 287                {
 1288                    _rawBytes = System.Convert.FromBase64String(argument);
 1289                }
 1290                catch (System.FormatException ex)
 291                {
 1292                    throw new ParseException($"invalid Base64 input in endpoint '{endpoint}'", ex);
 293                }
 294
 1295                return true;
 296            }
 297
 298            case 'e':
 299            {
 1300                if (argument == null)
 301                {
 0302                    throw new ParseException($"no argument provided for -e option in endpoint '{endpoint}'");
 303                }
 304
 305                try
 306                {
 1307                    _rawEncoding = Ice.Util.stringToEncodingVersion(argument);
 1308                }
 0309                catch (ParseException e)
 310                {
 0311                    throw new ParseException($"invalid encoding version '{argument}' in endpoint '{endpoint}'", e);
 312                }
 1313                return true;
 314            }
 315
 316            default:
 317            {
 1318                return false;
 319            }
 320        }
 321    }
 322
 323    private short _type;
 324    private Ice.EncodingVersion _rawEncoding;
 325    private byte[] _rawBytes;
 326}