-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
kotlin.code.style=official | ||
|
||
group=io.rebble.libpebblecommon | ||
version=0.0.16 | ||
version=0.0.17 | ||
org.gradle.jvmargs=-Xms1G |
44 changes: 44 additions & 0 deletions
44
src/commonMain/kotlin/io/rebble/libpebblecommon/packets/Emulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.rebble.libpebblecommon.packets | ||
|
||
import io.rebble.libpebblecommon.exceptions.PacketDecodeException | ||
import io.rebble.libpebblecommon.protocolhelpers.PebblePacket | ||
import io.rebble.libpebblecommon.structmapper.SBytes | ||
import io.rebble.libpebblecommon.structmapper.SUShort | ||
import io.rebble.libpebblecommon.structmapper.StructMapper | ||
import io.rebble.libpebblecommon.util.DataBuffer | ||
|
||
const val HEADER_SIGNATURE = 0xFEEDU | ||
const val FOOTER_SIGNATURE = 0xBEEFU | ||
|
||
open class QemuInboundPacket { | ||
val m = StructMapper() | ||
val signature = SUShort(m, HEADER_SIGNATURE.toUShort()) | ||
val protocol = SUShort(m) | ||
val length = SUShort(m) | ||
|
||
class QemuSPP: QemuInboundPacket() { | ||
val payload = SBytes(m) | ||
val footer = SUShort(m, FOOTER_SIGNATURE.toUShort()) | ||
|
||
init { | ||
payload.linkWithSize(length) | ||
} | ||
} | ||
|
||
companion object { | ||
fun deserialize(packet: UByteArray): QemuInboundPacket { | ||
val buf = DataBuffer(packet) | ||
val meta = StructMapper() | ||
val header = SUShort(meta) | ||
val protocol = SUShort(meta) | ||
meta.fromBytes(buf) | ||
return when (protocol.get()) { | ||
1u.toUShort() -> QemuSPP().also { it.m.fromBytes(buf) } | ||
else -> { | ||
println("Warning: QEMU packet left generic") | ||
QemuInboundPacket().also { it.m.fromBytes(buf) } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters