< Summary

Information
Class: Ice.Internal.OpaqueEndpointI
Assembly: Ice
File(s): /_/csharp/src/Ice/Internal/OpaqueEndpointI.cs
Tag: 125_37167941578
Line coverage
44%
Covered lines: 49
Uncovered lines: 60
Coverable lines: 109
Total lines: 321
Line coverage: 44.9%
Branch coverage
37%
Covered branches: 21
Total branches: 56
Branch coverage: 37.5%
Method coverage
30%
Covered methods: 8
Fully covered methods: 7
Total methods: 26
Method coverage: 30.7%
Full method coverage: 26.9%

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%
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%212086.67%

File(s)

/_/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 " + Protocol.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    // Return a server side transceiver for this endpoint, or null if a
 119    // transceiver can only be created by an acceptor.
 120    //
 0121    public override Transceiver transceiver() => null;
 122
 123    //
 124    // Return connectors for this endpoint, or empty list if no connector
 125    // is available.
 126    //
 0127    public override void connectors_async(EndpointI_connectors callback) => callback.connectors(new List<Connector>());
 128
 129    //
 130    // Return an acceptor for this endpoint, or null if no acceptors
 131    // is available.
 132    //
 133    public override Acceptor acceptor(string adapterName, SslServerAuthenticationOptions serverAuthenticationOptions) =>
 0134        null;
 135
 0136    public override List<EndpointI> expandHost() => [this];
 137
 0138    public override bool isLoopbackOrMulticast() => false;
 139
 0140    public override EndpointI toPublishedEndpoint(string host) => this;
 141
 142    //
 143    // Check whether the endpoint is equivalent to another one.
 144    //
 0145    public override bool equivalent(EndpointI endpoint) => false;
 146
 147    public override int GetHashCode()
 148    {
 1149        var hash = new HashCode();
 1150        hash.Add(_type);
 1151        hash.AddBytes(_rawBytes);
 1152        return hash.ToHashCode();
 153    }
 154
 155    public override string options()
 156    {
 0157        string s = "";
 0158        if (_type > -1)
 159        {
 0160            s += " -t " + _type;
 161        }
 0162        s += " -e " + Protocol.encodingVersionToString(_rawEncoding);
 0163        if (_rawBytes.Length > 0)
 164        {
 0165            s += " -v " + System.Convert.ToBase64String(_rawBytes);
 166        }
 0167        return s;
 168    }
 169
 170    //
 171    // Compare endpoints for sorting purposes
 172    //
 173    public override int CompareTo(EndpointI obj)
 174    {
 0175        if (!(obj is OpaqueEndpointI))
 176        {
 0177            return type() < obj.type() ? -1 : 1;
 178        }
 179
 0180        var p = (OpaqueEndpointI)obj;
 0181        if (this == p)
 182        {
 0183            return 0;
 184        }
 185
 0186        if (_type < p._type)
 187        {
 0188            return -1;
 189        }
 0190        else if (p._type < _type)
 191        {
 0192            return 1;
 193        }
 194
 0195        if (_rawEncoding.major < p._rawEncoding.major)
 196        {
 0197            return -1;
 198        }
 0199        else if (p._rawEncoding.major < _rawEncoding.major)
 200        {
 0201            return 1;
 202        }
 203
 0204        if (_rawEncoding.minor < p._rawEncoding.minor)
 205        {
 0206            return -1;
 207        }
 0208        else if (p._rawEncoding.minor < _rawEncoding.minor)
 209        {
 0210            return 1;
 211        }
 212
 0213        if (_rawBytes.Length < p._rawBytes.Length)
 214        {
 0215            return -1;
 216        }
 0217        else if (p._rawBytes.Length < _rawBytes.Length)
 218        {
 0219            return 1;
 220        }
 0221        for (int i = 0; i < _rawBytes.Length; i++)
 222        {
 0223            if (_rawBytes[i] < p._rawBytes[i])
 224            {
 0225                return -1;
 226            }
 0227            else if (p._rawBytes[i] < _rawBytes[i])
 228            {
 0229                return 1;
 230            }
 231        }
 232
 0233        return 0;
 234    }
 235
 236    protected override bool checkOption(string option, string argument, string endpoint)
 237    {
 1238        switch (option[1])
 239        {
 240            case 't':
 241            {
 1242                if (_type > -1)
 243                {
 1244                    throw new ParseException($"multiple -t options in endpoint '{endpoint}'");
 245                }
 1246                if (argument == null)
 247                {
 1248                    throw new ParseException($"no argument provided for -t option in endpoint '{endpoint}'");
 249                }
 250
 251                int t;
 252                try
 253                {
 1254                    t = int.Parse(argument, CultureInfo.InvariantCulture);
 1255                }
 1256                catch (System.Exception ex) when (ex is FormatException or OverflowException)
 257                {
 1258                    throw new ParseException($"invalid type value '{argument}' in endpoint '{endpoint}'", ex);
 259                }
 260
 1261                if (t < 0 || t > 32767)
 262                {
 0263                    throw new ParseException($"type value '{argument}' out of range in endpoint '{endpoint}'");
 264                }
 265
 1266                _type = (short)t;
 1267                return true;
 268            }
 269
 270            case 'v':
 271            {
 1272                if (_rawBytes.Length > 0)
 273                {
 1274                    throw new ParseException($"multiple -v options in endpoint '{endpoint}'");
 275                }
 1276                if (argument == null)
 277                {
 1278                    throw new ParseException($"no argument provided for -v option in endpoint '{endpoint}'");
 279                }
 280
 281                try
 282                {
 1283                    _rawBytes = System.Convert.FromBase64String(argument);
 1284                }
 1285                catch (System.FormatException ex)
 286                {
 1287                    throw new ParseException($"invalid base64 value '{argument}' in endpoint '{endpoint}'", ex);
 288                }
 289
 1290                return true;
 291            }
 292
 293            case 'e':
 294            {
 1295                if (argument == null)
 296                {
 0297                    throw new ParseException($"no argument provided for -e option in endpoint '{endpoint}'");
 298                }
 299
 300                try
 301                {
 1302                    _rawEncoding = Protocol.stringToEncodingVersion(argument);
 1303                }
 0304                catch (ParseException e)
 305                {
 0306                    throw new ParseException($"invalid encoding version '{argument}' in endpoint '{endpoint}'", e);
 307                }
 1308                return true;
 309            }
 310
 311            default:
 312            {
 1313                return false;
 314            }
 315        }
 316    }
 317
 318    private short _type;
 319    private Ice.EncodingVersion _rawEncoding;
 320    private byte[] _rawBytes;
 321}