Example #1
0
        private Host ParseHost()
        {
            string host;

            if (parser.buffer[parser.offset] == '[')
            {
                // IPV6 addresses can start with bracket.
                parser.offset++;
                host = parser.ParseString(']');
                parser.offset++;
            }
            else
            {
                host = parser.ParseString(':', ',', ']');
            }

            if (cluster.ipMap != null)
            {
                string alternativeHost;

                if (cluster.ipMap.TryGetValue(host, out alternativeHost))
                {
                    host = alternativeHost;
                }
            }

            if (parser.offset < parser.length)
            {
                byte b = parser.buffer[parser.offset];

                if (b == ':')
                {
                    parser.offset++;
                    int port = parser.ParseInt();
                    return(new Host(host, tlsName, port));
                }

                if (b == ',' || b == ']')
                {
                    return(new Host(host, tlsName, portDefault));
                }
            }

            string response = parser.GetTruncatedResponse();

            throw new AerospikeException.Parse("Unterminated host in response: " + response);
        }