Skip to content

Instantly share code, notes, and snippets.

@eutkin
Created September 8, 2022 11:45
Show Gist options
  • Save eutkin/96c88d7849a65bb088cf03755e77a9d8 to your computer and use it in GitHub Desktop.
Save eutkin/96c88d7849a65bb088cf03755e77a9d8 to your computer and use it in GitHub Desktop.
package com
import org.apache.ignite.Ignition
import org.apache.ignite.internal.IgniteEx
import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl
import org.msgpack.core.MessagePack
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.ZoneOffset
import java.util.*
import java.util.stream.Collectors
import java.util.stream.Stream
object App {
@JvmStatic
fun main(args: Array<String>) {
val events = (0..2000).map { getEvent() }
val msgPack = MessagePack.newDefaultBufferPacker().use { packer ->
packer.packArrayHeader(events.size)
events.forEach { event ->
packer.packMapHeader(event.size)
event.forEach { (key, value) ->
packer.packString(key);
when (value) {
null -> packer.packNil()
is Boolean -> packer.packBoolean(value)
is Int -> packer.packInt(value)
is Long -> packer.packLong(value)
is Double -> packer.packDouble(value)
is UUID -> {
packer.packLong(value.mostSignificantBits); packer.packLong(value.leastSignificantBits)
}
is String -> packer.packString(value)
}
}
}
packer.toByteArray()
}
val igniteEx = Ignition.start() as IgniteEx
val binProc = igniteEx.context().cacheObjects() as CacheObjectBinaryProcessorImpl
val ignite = binProc.marshal(events)
println("Size msgPack: ${msgPack.size}, Size ignite: ${ignite.size}")
}
fun getEvent(): Map<String, Any?> {
return mapOf(
"string" to "test",
"bool" to true,
"int" to 10,
"double" to 1412.4124,
"localDate" to LocalDate.now().toEpochSecond(LocalTime.MIN, ZoneOffset.UTC),
"localDateTime" to LocalDateTime.now().toEpochSecond(ZoneOffset.UTC),
"uuid" to UUID.randomUUID(),
"null" to null
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment