replace protoc with Wire

This commit is contained in:
Alexander Nozik 2021-01-28 12:31:17 +03:00
parent 387b6bbcb4
commit 62d33ddacd
4 changed files with 45 additions and 66 deletions

View File

@ -1,12 +1,7 @@
import com.google.protobuf.gradle.proto
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc
plugins {
java
kotlin("jvm")
id("ru.mipt.npm.kscience")
id("com.google.protobuf") version "0.8.14"
id("com.squareup.wire") version "3.5.0"
}
kscience{
@ -18,42 +13,9 @@ val dataforgeVersion: String by rootProject.extra
dependencies {
api(project(":numass-data-model"))
api("hep.dataforge:dataforge-workspace:$dataforgeVersion")
implementation("com.google.protobuf:protobuf-java:3.14.0")
implementation("javax.annotation:javax.annotation-api:1.3.1")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(":numass-data-proto:generateProto")
}
sourceSets {
create("proto") {
proto {
srcDir("src/main/proto")
}
}
create("gen"){
java{
srcDir("gen/main/java")
}
}
}
//kotlin{
// sourceSets{
// main{
// de
// }
// }
//}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = "com.google.protobuf:protoc:3.14.0"
}
generatedFilesBaseDir = "$projectDir/gen"
wire{
kotlin{}
}

View File

@ -37,22 +37,21 @@ import java.util.zip.Inflater
*/
public class ProtoNumassPoint(
override val meta: Meta,
private val protoBuilder: () -> NumassProto.Point,
private val protoBuilder: () -> Point,
) : NumassPoint {
private val proto: NumassProto.Point get() = protoBuilder()
private val proto: Point get() = protoBuilder()
override val blocks: List<NumassBlock>
get() = proto.channelsList
.flatMap { channel ->
channel.blocksList
get() = proto.channels.flatMap { channel ->
channel.blocks
.map { block -> ProtoBlock(channel.id.toInt(), block, this) }
.sortedBy { it.startTime }
}
override val channels: Map<Int, NumassBlock>
get() = proto.channelsList.groupBy { it.id.toInt() }.mapValues { entry ->
MetaBlock(entry.value.flatMap { it.blocksList }.map { ProtoBlock(entry.key, it, this) })
get() = proto.channels.groupBy { it.id.toInt() }.mapValues { entry ->
MetaBlock(entry.value.flatMap { it.blocks }.map { ProtoBlock(entry.key, it, this) })
}
override val voltage: Double get() = meta["external_meta.HV1_value"].double ?: super.voltage
@ -105,7 +104,7 @@ public class ProtoNumassPoint(
public fun fromEnvelope(envelope: Envelope): ProtoNumassPoint? {
val proto = envelope.useData {
NumassProto.Point.parseFrom(it)
Point.ADAPTER.decode(it)
}
return proto?.let { ProtoNumassPoint(envelope.meta) { it } }
}
@ -115,7 +114,7 @@ public class ProtoNumassPoint(
public class ProtoBlock(
override val channel: Int,
private val block: NumassProto.Point.Channel.Block,
private val block: Point.Channel.Block,
public val parent: NumassPoint? = null,
) : NumassBlock {
@ -136,14 +135,20 @@ public class ProtoBlock(
}
override val events: Flow<NumassEvent>
get() = if (block.hasEvents()) {
get() = if (block.events != null) {
val events = block.events
if (events.timesCount != events.amplitudesCount) {
val amplitudes = events.amplitudes
val times = events.times
if (times.size != amplitudes.size) {
LoggerFactory.getLogger(javaClass)
.error("The block is broken. Number of times is ${events.timesCount} and number of amplitudes is ${events.amplitudesCount}")
.error("The block is broken. Number of times is ${times.size} and number of amplitudes is ${amplitudes.size}")
}
(0..events.timesCount).asFlow()
.map { i -> NumassEvent(events.getAmplitudes(i).toShort(), events.getTimes(i), this) }
amplitudes.zip(times) { amp, time ->
NumassEvent(amp.toShort(), time, this)
}.asFlow()
} else {
emptyFlow<NumassEvent>()
}
@ -151,10 +156,10 @@ public class ProtoBlock(
override val frames: Flow<NumassFrame>
get() {
val tickSize = Duration.ofNanos(block.binSize)
return block.framesList.asFlow().map { frame ->
val tickSize = Duration.ofNanos(block.bin_size)
return block.frames.asFlow().map { frame ->
val time = startTime.plusNanos(frame.time)
val frameData = frame.data.asReadOnlyByteBuffer()
val frameData = frame.data_.asByteBuffer()
NumassFrame(time, tickSize, frameData.asShortBuffer())
}
}

View File

@ -21,6 +21,8 @@ class TestNumassDirectory {
assertEquals("2018-04-13T22:01:46", testSet.meta["end_time"].string)
assertEquals(ListValue.EMPTY, testSet.meta["comments"].value)
assertEquals(31, testSet.points.size)
assertEquals("2018-04-13T21:56:09", testSet.points.find { it.index == 22 }?.meta["end_time"].string)
val point22 = testSet.points.find { it.index == 22 }!!
point22.blocks
assertEquals("2018-04-13T21:56:09", point22.meta["end_time"].string)
}
}

View File

@ -1,8 +1,8 @@
pluginManagement {
repositories {
mavenLocal()
jcenter()
gradlePluginPortal()
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://dl.bintray.com/kotlin/kotlin-dev")
maven("https://dl.bintray.com/mipt-npm/dataforge")
@ -10,8 +10,8 @@ pluginManagement {
maven("https://dl.bintray.com/mipt-npm/dev")
}
val toolsVersion = "0.7.1"
val kotlinVersion = "1.4.21"
val toolsVersion = "0.7.3-1.4.30-RC"
val kotlinVersion = "1.4.30-RC"
plugins {
id("ru.mipt.npm.project") version toolsVersion
@ -22,6 +22,16 @@ pluginManagement {
kotlin("jvm") version kotlinVersion
kotlin("js") version kotlinVersion
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.squareup.wire") {
// For some reason, Gradle does a lookup on the wrong coordinates:
// 'com.squareup.wire:com.squareup.wire.gradle.plugin' instead of the one below.
useModule("com.squareup.wire:wire-gradle-plugin:${requested.version}")
}
}
}
}
include("numass-data-model")