UNPKG

2.1 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2021 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.stringToSubchannelAddress = exports.subchannelAddressToString = exports.subchannelAddressEqual = exports.isTcpSubchannelAddress = void 0;
20const net_1 = require("net");
21function isTcpSubchannelAddress(address) {
22 return 'port' in address;
23}
24exports.isTcpSubchannelAddress = isTcpSubchannelAddress;
25function subchannelAddressEqual(address1, address2) {
26 if (isTcpSubchannelAddress(address1)) {
27 return (isTcpSubchannelAddress(address2) &&
28 address1.host === address2.host &&
29 address1.port === address2.port);
30 }
31 else {
32 return !isTcpSubchannelAddress(address2) && address1.path === address2.path;
33 }
34}
35exports.subchannelAddressEqual = subchannelAddressEqual;
36function subchannelAddressToString(address) {
37 if (isTcpSubchannelAddress(address)) {
38 return address.host + ':' + address.port;
39 }
40 else {
41 return address.path;
42 }
43}
44exports.subchannelAddressToString = subchannelAddressToString;
45const DEFAULT_PORT = 443;
46function stringToSubchannelAddress(addressString, port) {
47 if (net_1.isIP(addressString)) {
48 return {
49 host: addressString,
50 port: port !== null && port !== void 0 ? port : DEFAULT_PORT
51 };
52 }
53 else {
54 return {
55 path: addressString
56 };
57 }
58}
59exports.stringToSubchannelAddress = stringToSubchannelAddress;
60//# sourceMappingURL=subchannel-address.js.map
\No newline at end of file