Skip to content

Instantly share code, notes, and snippets.

@eutkin
Created August 13, 2021 16:13
Show Gist options
  • Save eutkin/34bfe9398d0288542f6a6ed69d5621a5 to your computer and use it in GitHub Desktop.
Save eutkin/34bfe9398d0288542f6a6ed69d5621a5 to your computer and use it in GitHub Desktop.
package zone.bi.biplan.card
import io.netty.buffer.ByteBufAllocator
import java.net.InetSocketAddress
import java.net.Socket
import java.nio.ByteBuffer
object Application
fun main(args: Array<String>) {
val byteArray = Application.javaClass.classLoader.getResourceAsStream("in_16222_20210726_162925_465_b74597d8.bin")
?.use { it.readAllBytes() }!!
val buffer = ByteBufAllocator.DEFAULT.buffer(byteArray.size)
buffer.writeBytes(byteArray)
val messages = mutableListOf<ByteArray>()
while (buffer.isReadable) {
val sizeInBytes = ByteArray(2).apply {
buffer.readBytes(this)
}
val size = ByteBuffer.wrap(sizeInBytes).short.toInt()
val isoMsgInBytes = ByteArray(size).apply {
buffer.readBytes(this)
}
messages += (sizeInBytes + isoMsgInBytes)
}
val start = System.currentTimeMillis()
var counter = 0
Socket().use { socket ->
socket.connect(InetSocketAddress(8888))
socket.getInputStream().use { inputStream ->
socket.getOutputStream().use { outputStream ->
messages
.filter { message -> ByteBuffer.wrap(ByteArray(2) { message[it] }).short.toInt() == 30 }
.forEach { (size, message) ->
outputStream.write(size + message)
counter++
var c = 0
while (inputStream.available() == 0) {
if (c++ > 50) {
break
}
Thread.sleep(1)
}
}
}
}
}
println("${(System.currentTimeMillis() - start) / counter}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment