UNPKG

2.23 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 (!address1 && !address2) {
27 return true;
28 }
29 if (!address1 || !address2) {
30 return false;
31 }
32 if (isTcpSubchannelAddress(address1)) {
33 return (isTcpSubchannelAddress(address2) &&
34 address1.host === address2.host &&
35 address1.port === address2.port);
36 }
37 else {
38 return !isTcpSubchannelAddress(address2) && address1.path === address2.path;
39 }
40}
41exports.subchannelAddressEqual = subchannelAddressEqual;
42function subchannelAddressToString(address) {
43 if (isTcpSubchannelAddress(address)) {
44 return address.host + ':' + address.port;
45 }
46 else {
47 return address.path;
48 }
49}
50exports.subchannelAddressToString = subchannelAddressToString;
51const DEFAULT_PORT = 443;
52function stringToSubchannelAddress(addressString, port) {
53 if ((0, net_1.isIP)(addressString)) {
54 return {
55 host: addressString,
56 port: port !== null && port !== void 0 ? port : DEFAULT_PORT,
57 };
58 }
59 else {
60 return {
61 path: addressString,
62 };
63 }
64}
65exports.stringToSubchannelAddress = stringToSubchannelAddress;
66//# sourceMappingURL=subchannel-address.js.map
\No newline at end of file