Add Kotlin Eve media observation contract
This commit is contained in:
parent
78c073c3d5
commit
e7a570111d
3 changed files with 63 additions and 0 deletions
|
|
@ -10,6 +10,11 @@ an in-memory CultCache, and the first Eve dashboard/sensor document contracts.
|
|||
references, and the flat `nodes` projection remains a compatibility and binding
|
||||
surface for selection, commands, and fallback rendering.
|
||||
|
||||
`EveMediaObservationDocument` carries byte-backed device streams such as camera
|
||||
luma frames and microphone PCM blocks. The document is observation transport,
|
||||
not synchronization authority: the device owns capture and local timestamps,
|
||||
while Mimir or another consumer owns alignment and interpretation.
|
||||
|
||||
## Build
|
||||
|
||||
```powershell
|
||||
|
|
|
|||
|
|
@ -298,6 +298,15 @@ class MessagePackWriter {
|
|||
out.write(bytes)
|
||||
}
|
||||
|
||||
fun binary(value: ByteArray): MessagePackWriter = apply {
|
||||
when {
|
||||
value.size < 256 -> { out.write(0xc4); out.write(value.size) }
|
||||
value.size <= 65535 -> { out.write(0xc5); out.write((value.size shr 8) and 0xff); out.write(value.size and 0xff) }
|
||||
else -> { out.write(0xc6); out.write(ByteBuffer.allocate(4).putInt(value.size).array()) }
|
||||
}
|
||||
out.write(value)
|
||||
}
|
||||
|
||||
fun nullableString(value: String?): MessagePackWriter = apply { if (value == null) out.write(0xc0) else string(value) }
|
||||
fun nullableBoolean(value: Boolean?): MessagePackWriter = apply { if (value == null) out.write(0xc0) else out.write(if (value) 0xc3 else 0xc2) }
|
||||
fun nullableDouble(value: Double?): MessagePackWriter = apply { if (value == null) out.write(0xc0) else doubleValue(value) }
|
||||
|
|
|
|||
|
|
@ -308,3 +308,52 @@ data class EveSensorObservationDocument(
|
|||
throw UnsupportedOperationException("sensor decode is consumer-owned")
|
||||
}
|
||||
}
|
||||
|
||||
data class EveMediaObservationDocument(
|
||||
val observationId: String,
|
||||
val deviceId: String,
|
||||
val streamId: String,
|
||||
val kind: String,
|
||||
val sequence: Long,
|
||||
val sensorTimestampNs: Long,
|
||||
val elapsedRealtimeNs: Long,
|
||||
val wallClockUtc: String,
|
||||
val clockDomainId: String,
|
||||
val format: String,
|
||||
val width: Int? = null,
|
||||
val height: Int? = null,
|
||||
val sampleRate: Int? = null,
|
||||
val channels: Int? = null,
|
||||
val frameCount: Int? = null,
|
||||
val payloadEncoding: String,
|
||||
val payload: ByteArray,
|
||||
) {
|
||||
companion object Codec : CultDocumentCodec<EveMediaObservationDocument> {
|
||||
override val documentType = "mimir.eve_media_observation"
|
||||
override val schemaVersion = "mimir.eve_media_observation.v1"
|
||||
override fun encode(value: EveMediaObservationDocument): ByteArray =
|
||||
MessagePackWriter()
|
||||
.array(17)
|
||||
.string(value.observationId)
|
||||
.string(value.deviceId)
|
||||
.string(value.streamId)
|
||||
.string(value.kind)
|
||||
.longValue(value.sequence)
|
||||
.longValue(value.sensorTimestampNs)
|
||||
.longValue(value.elapsedRealtimeNs)
|
||||
.string(value.wallClockUtc)
|
||||
.string(value.clockDomainId)
|
||||
.string(value.format)
|
||||
.nullableLong(value.width?.toLong())
|
||||
.nullableLong(value.height?.toLong())
|
||||
.nullableLong(value.sampleRate?.toLong())
|
||||
.nullableLong(value.channels?.toLong())
|
||||
.nullableLong(value.frameCount?.toLong())
|
||||
.string(value.payloadEncoding)
|
||||
.binary(value.payload)
|
||||
.toByteArray()
|
||||
|
||||
override fun decode(payload: ByteArray): EveMediaObservationDocument =
|
||||
throw UnsupportedOperationException("media decode is consumer-owned")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue