Skip to content

Commit

Permalink
Move the TlvReaderExternsion to TlvReader (project-chip#30117)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored Oct 31, 2023
1 parent a9769a8 commit 1890490
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 47 deletions.
4 changes: 1 addition & 3 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down

This file was deleted.

51 changes: 51 additions & 0 deletions src/controller/java/src/matter/tlv/TlvReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,57 @@ class TlvReader(bytes: ByteArray) : Iterable<Element> {
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.
*
Expand Down

0 comments on commit 1890490

Please sign in to comment.