diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index ee5ead80b18b38..71c2a8b07bcbf5 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -328,9 +328,7 @@ kotlin_library("chipcluster") { deps = [ ":tlv" ] - sources = [ "src/chip/devicecontroller/cluster/TlvReaderExtension.kt" ] - - sources += structs_sources + sources = structs_sources sources += eventstructs_sources kotlinc_flags = [ "-Xlint:deprecation" ] diff --git a/src/controller/java/src/chip/devicecontroller/cluster/TlvReaderExtension.kt b/src/controller/java/src/chip/devicecontroller/cluster/TlvReaderExtension.kt deleted file mode 100644 index 136e64e4b555fd..00000000000000 --- a/src/controller/java/src/chip/devicecontroller/cluster/TlvReaderExtension.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package chip.devicecontroller.cluster - -import matter.tlv.NullValue -import matter.tlv.Tag -import matter.tlv.TlvReader - -fun TlvReader.getBoolean(tag: Tag): Boolean { - return getBool(tag) -} - -fun TlvReader.getString(tag: Tag): String { - return getUtf8String(tag) -} - -fun TlvReader.getByteArray(tag: Tag): ByteArray { - return getByteString(tag) -} - -fun TlvReader.isNull(): Boolean { - val value = peekElement().value - return (value is NullValue) -} - -fun TlvReader.isNextTag(tag: Tag): Boolean { - val nextTag = peekElement().tag - return (nextTag == tag) -} diff --git a/src/controller/java/src/matter/tlv/TlvReader.kt b/src/controller/java/src/matter/tlv/TlvReader.kt index 94fefe0b07f5cf..d8ce4d187a08f8 100644 --- a/src/controller/java/src/matter/tlv/TlvReader.kt +++ b/src/controller/java/src/matter/tlv/TlvReader.kt @@ -265,6 +265,57 @@ class TlvReader(bytes: ByteArray) : Iterable { require(value is NullValue) { "Unexpected value $value at index $index (expected NullValue)" } } + /** + * Retrieves a Boolean value associated with the given tag. + * + * @param tag The Tag to query for. + * @return The Boolean value associated with the tag. + */ + fun getBoolean(tag: Tag): Boolean { + return getBool(tag) + } + + /** + * Retrieves a String value associated with the given tag. The returned string is in UTF-8 format. + * + * @param tag The Tag to query for. + * @return The String value associated with the tag. + */ + fun getString(tag: Tag): String { + return getUtf8String(tag) + } + + /** + * Retrieves a ByteArray value associated with the given tag. + * + * @param tag The Tag to query for. + * @return The ByteArray value associated with the tag. + */ + fun getByteArray(tag: Tag): ByteArray { + return getByteString(tag) + } + + /** + * Checks if the current element's value is of type NullValue. + * + * @return True if the current element's value is NullValue, otherwise false. + */ + fun isNull(): Boolean { + val value = peekElement().value + return (value is NullValue) + } + + /** + * Checks if the next tag in sequence matches the provided tag. + * + * @param tag The Tag to compare against the next tag. + * @return True if the next tag matches the provided tag, otherwise false. + */ + fun isNextTag(tag: Tag): Boolean { + val nextTag = peekElement().tag + return (nextTag == tag) + } + /** * Verifies that the current element is a start of a Structure and advances to the next element. *