File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -55,4 +55,15 @@ enum CoapRequestMethod {
5555enum CoapSubprotocol {
5656 /// Subprotocol for observing CoAP resources.
5757 observe,
58+ ;
59+
60+ /// Tries to match the given [subprotocol] string to one of the known
61+ /// [CoapSubprotocol.values] .
62+ static CoapSubprotocol ? tryParse (String subprotocol) {
63+ if (subprotocol == "cov:observe" ) {
64+ return CoapSubprotocol .observe;
65+ }
66+
67+ return null ;
68+ }
5869}
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ import "package:dart_wot/src/binding_coap/coap_extensions.dart";
1111import "package:test/test.dart" ;
1212
1313void main () {
14- group ("CoAP definitions" , () {
15- test ("should deserialize CoAP Forms" , () async {
14+ group ("CoAP definitions should " , () {
15+ test ("deserialize CoAP Forms" , () async {
1616 const thingDescriptionJson = {
1717 "@context" : [
1818 "https://www.w3.org/2022/wot/td/v1.1" ,
@@ -88,4 +88,12 @@ void main() {
8888 );
8989 });
9090 });
91+
92+ test ("parse CoAP subprotocols" , () async {
93+ final observeSubprotocol = CoapSubprotocol .tryParse ("cov:observe" );
94+ expect (observeSubprotocol == CoapSubprotocol .observe, isTrue);
95+
96+ final unknownSubprotocol = CoapSubprotocol .tryParse ("foobar" );
97+ expect (unknownSubprotocol, isNull);
98+ });
9199}
You can’t perform that action at this time.
0 commit comments