bbaldino
03/12/2019, 11:02 PMbbaldino
03/12/2019, 11:05 PMfun ByteArray.getLong(byteIndex: Int): Long {
val b1 = get(byteIndex + 0)
val b2 = get(byteIndex + 1)
val b3 = get(byteIndex + 2)
val b4 = get(byteIndex + 3)
val b5 = get(byteIndex + 4)
val b6 = get(byteIndex + 5)
val b7 = get(byteIndex + 6)
val b8 = get(byteIndex + 7)
return ((b1.toLong() and 0xFF) shl 56) or
((b2.toLong() and 0xFF) shl 48) or
((b3.toLong() and 0xFF) shl 40) or
((b4.toLong() and 0xFF) shl 32) or
((b5.toLong() and 0xFF) shl 24) or
((b6.toLong() and 0xFF) shl 16) or
((b7.toLong() and 0xFF) shl 8) or
((b8.toLong() and 0xFF))
}
the test is class ByteArrayExtensionsKtTest : ShouldSpec() {
init {
"ByteArray.getLong/putLong" {
should("parse the Long correctly") {
// forall(
// row(byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 0.toLong()),
// row(byteArrayOf(0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), 9223372036854775807L)
// ) { buf, expectedLong ->
// buf.getLong(0) shouldBe expectedLong
//
// val array = ByteArray(4)
// array.putLong(0, expectedLong)
// array should haveSameContentAs(buf)
// }
byteArrayOf(0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF).getLong(0) shouldBe 9223372036854775807L
}
}
}
bbaldino
03/12/2019, 11:05 PMbyteArrayOf
is defined as fun byteArrayOf(vararg elements: Number): ByteArray {
return elements.map { it.toByte() }.toByteArray()
}
bbaldino
03/12/2019, 11:05 PMbbaldino
03/12/2019, 11:05 PMbbaldino
03/12/2019, 11:07 PMcurrent:95, SignatureParser (sun.reflect.generics.parser)
parseSuperInterfaces:559, SignatureParser (sun.reflect.generics.parser)
parseClassSignature:214, SignatureParser (sun.reflect.generics.parser)
parseClassSig:156, SignatureParser (sun.reflect.generics.parser)
parse:57, ClassRepository (sun.reflect.generics.repository)
parse:41, ClassRepository (sun.reflect.generics.repository)
<init>:74, AbstractRepository (sun.reflect.generics.repository)
<init>:49, GenericDeclRepository (sun.reflect.generics.repository)
<init>:53, ClassRepository (sun.reflect.generics.repository)
make:70, ClassRepository (sun.reflect.generics.repository)
<clinit>:43, ClassRepository (sun.reflect.generics.repository)
getGenericInfo:2548, Class (java.lang)
getGenericInterfaces:912, Class (java.lang)
renderLambdaToString:41, ReflectionFactory (kotlin.jvm.internal)
renderLambdaToString:74, Reflection (kotlin.jvm.internal)
toString:163, SuspendLambda (kotlin.coroutines.jvm.internal)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
toString:-1, TestCase (io.kotlintest)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
toString:-1, TopLevelTest (io.kotlintest.extensions)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
toString:462, AbstractCollection (java.util)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
toString:-1, TopLevelTests (io.kotlintest.extensions)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
invoke:43, SpecExecutor$execute$$inlined$invoke$lambda$1 (io.kotlintest.runner.jvm.spec)
invoke:17, SpecExecutor$execute$$inlined$invoke$lambda$1 (io.kotlintest.runner.jvm.spec)
withExecutor:28, SpecExecutor (io.kotlintest.runner.jvm.spec)
execute:34, SpecExecutor (io.kotlintest.runner.jvm.spec)
run:102, TestEngine$submitSpec$1 (io.kotlintest.runner.jvm)
call:511, Executors$RunnableAdapter (java.util.concurrent)
run$$$capture:266, FutureTask (java.util.concurrent)
run:-1, FutureTask (java.util.concurrent)
- Async stack trace
<init>:151, FutureTask (java.util.concurrent)
newTaskFor:87, AbstractExecutorService (java.util.concurrent)
submit:111, AbstractExecutorService (java.util.concurrent)
submitSpec:90, TestEngine (io.kotlintest.runner.jvm)
submitAll:48, TestEngine (io.kotlintest.runner.jvm)
execute:75, TestEngine (io.kotlintest.runner.jvm)
execute:44, KotlinTestEngine (io.kotlintest.runner.junit5)
execute:229, DefaultLauncher (org.junit.platform.launcher.core)
lambda$execute$6:197, DefaultLauncher (org.junit.platform.launcher.core)
withInterceptedStreams:211, DefaultLauncher (org.junit.platform.launcher.core)
execute:191, DefaultLauncher (org.junit.platform.launcher.core)
execute:128, DefaultLauncher (org.junit.platform.launcher.core)
startRunnerWithArgs:74, JUnit5IdeaTestRunner (com.intellij.junit5)
startRunnerWithArgs:47, IdeaTestRunner$Repeater (com.intellij.rt.execution.junit)
prepareStreamsAndStart:242, JUnitStarter (com.intellij.rt.execution.junit)
main:70, JUnitStarter (com.intellij.rt.execution.junit)
sam
03/12/2019, 11:07 PMbbaldino
03/12/2019, 11:07 PMbbaldino
03/12/2019, 11:07 PMrow
?sam
03/12/2019, 11:07 PMbbaldino
03/12/2019, 11:08 PMbbaldino
03/12/2019, 11:08 PMbbaldino
03/12/2019, 11:08 PMbbaldino
03/12/2019, 11:08 PMval array = ByteArray(4)
sam
03/12/2019, 11:09 PMbbaldino
03/12/2019, 11:09 PMbbaldino
03/12/2019, 11:09 PMsam
03/12/2019, 11:09 PMsam
03/12/2019, 11:09 PMsam
03/12/2019, 11:09 PMsam
03/12/2019, 11:09 PM