mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-01 02:05:46 +02:00
Prepare test parse_TLV
This commit is contained in:
@@ -78,7 +78,7 @@ fun toInt32(bytes: ByteArray): Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun parseTLV(data: ByteArray): Map<Byte, List<ByteArray>> {
|
fun parseTLV(data: ByteArray): Map<Byte, List<ByteArray>> {
|
||||||
var result = mutableMapOf<Byte, MutableList<ByteArray>>()
|
val result = mutableMapOf<Byte, MutableList<ByteArray>>()
|
||||||
var rest = data
|
var rest = data
|
||||||
while (rest.isNotEmpty()) {
|
while (rest.isNotEmpty()) {
|
||||||
val t = rest[0]
|
val t = rest[0]
|
||||||
@@ -88,9 +88,9 @@ fun parseTLV(data: ByteArray): Map<Byte, List<ByteArray>> {
|
|||||||
if (v.size < l) continue
|
if (v.size < l) continue
|
||||||
|
|
||||||
if (!result.containsKey(t)) {
|
if (!result.containsKey(t)) {
|
||||||
result.put(t, mutableListOf())
|
result[t] = mutableListOf()
|
||||||
}
|
}
|
||||||
result.get(t)?.add(v)
|
result[t]?.add(v)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.vitorpamplona.amethyst.service
|
package com.vitorpamplona.amethyst.service
|
||||||
|
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
import org.junit.Ignore
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class Nip19Test {
|
class Nip19Test {
|
||||||
@@ -18,8 +19,15 @@ class Nip19Test {
|
|||||||
@Test()
|
@Test()
|
||||||
fun to_int_32_length_4() {
|
fun to_int_32_length_4() {
|
||||||
val actual = toInt32(byteArrayOfInts(1, 2, 3, 4))
|
val actual = toInt32(byteArrayOfInts(1, 2, 3, 4))
|
||||||
|
|
||||||
Assert.assertEquals(16909060, actual)
|
Assert.assertEquals(16909060, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore("Not implemented yet")
|
||||||
|
@Test()
|
||||||
|
fun parse_TLV() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
private fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
|
private fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user