Skip to content

Commit 405757d

Browse files
committed
feat: move hasMulticastAddress extension to core package
1 parent 669333a commit 405757d

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

lib/core.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
/// runtime used for consuming, exposing, and discovering Things.
1010
library core;
1111

12+
// TODO(JKRhb): Reorganize top-level core package into smaller packages.
1213
export "src/core/definitions.dart";
1314
export "src/core/exceptions.dart";
15+
export "src/core/extensions.dart";
1416
export "src/core/implementation.dart";
1517
export "src/core/protocol_interfaces.dart";
1618
export "src/core/scripting_api.dart";

lib/src/binding_coap/coap_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ final class CoapClient extends ProtocolClient {
506506
final streamController = StreamController<DiscoveryContent>();
507507

508508
// TODO: Replace once https://github.com/shamblett/coap/pull/129 is merged
509-
if (uri.isMulticastAddress) {
509+
if (uri.hasMulticastAddress) {
510510
multicastResponseHandler = coap.CoapMulticastResponseHandler(
511511
(data) {
512512
streamController.add(data.determineDiscoveryContent(uri.scheme));
@@ -526,7 +526,7 @@ final class CoapClient extends ProtocolClient {
526526
multicastResponseHandler: multicastResponseHandler,
527527
);
528528

529-
if (uri.isMulticastAddress) {
529+
if (uri.hasMulticastAddress) {
530530
yield* streamController.stream;
531531
} else {
532532
yield content;

lib/src/binding_coap/coap_extensions.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//
55
// SPDX-License-Identifier: BSD-3-Clause
66

7-
import "dart:io";
87
import "dart:typed_data";
98

109
import "package:cbor/cbor.dart";
@@ -16,15 +15,6 @@ import "../../core.dart" hide PskCredentials;
1615
import "coap_binding_exception.dart";
1716
import "coap_definitions.dart";
1817

19-
/// Extension which makes it easier to handle [Uri]s containing
20-
/// [InternetAddress]es.
21-
extension InternetAddressMethods on Uri {
22-
/// Checks whether the host of this [Uri] is a multicast [InternetAddress].
23-
bool get isMulticastAddress {
24-
return InternetAddress.tryParse(host)?.isMulticast ?? false;
25-
}
26-
}
27-
2818
/// CoAP-specific extensions for the [AugmentedForm] class.
2919
extension CoapFormExtension on AugmentedForm {
3020
T? _obtainVocabularyTerm<T>(String vocabularyTerm) {

lib/src/core/extensions.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
/// Sub-library for extensions used by `dart_wot`.
8+
library extensions;
9+
10+
export "extensions/uri_extensions.dart";
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
import "dart:io";
8+
9+
/// Extension that makes it easier to handle [Uri]s which potentially contain
10+
/// [InternetAddress]es.
11+
extension InternetAddressMethodExtension on Uri {
12+
/// Checks whether the host of this [Uri] is a multicast [InternetAddress].
13+
bool get hasMulticastAddress {
14+
return InternetAddress.tryParse(host)?.isMulticast ?? false;
15+
}
16+
}

0 commit comments

Comments
 (0)