diff --git a/packages/cultmesh-kotlin/README.md b/packages/cultmesh-kotlin/README.md index f88cc4fe..e00c1ef9 100644 --- a/packages/cultmesh-kotlin/README.md +++ b/packages/cultmesh-kotlin/README.md @@ -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 diff --git a/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/CultMesh.kt b/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/CultMesh.kt index e63fb400..e8132601 100644 --- a/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/CultMesh.kt +++ b/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/CultMesh.kt @@ -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) } diff --git a/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/eve/EveDocuments.kt b/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/eve/EveDocuments.kt index 5b6e575e..b2e7dcd6 100644 --- a/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/eve/EveDocuments.kt +++ b/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/eve/EveDocuments.kt @@ -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 { + 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") + } +}