Skip to content

Commit

Permalink
fix: workaround Packet was larger than I expected error
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchen5209 committed Jul 15, 2024
1 parent 4a9dd75 commit 05f145a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/kotlin/one/oktw/galaxy/network/ProxyAPIPayload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ data class ProxyAPIPayload(val packet: Packet) : CustomPayload {
val ID = CustomPayload.Id<ProxyAPIPayload>(PROXY_IDENTIFIER)
val CODEC: PacketCodec<PacketByteBuf, ProxyAPIPayload> = PacketCodec.of(
{ value, buf -> buf.writeBytes(wrappedBuffer(encode(value.packet))) },
{ buf -> ProxyAPIPayload(ProxyAPI.decode(buf.nioBuffer())) })
{ buf ->
val packet = ProxyAPIPayload(ProxyAPI.decode(buf.nioBuffer()))
// FIXME: Workaround force clear buffer to suppress "Packet was larger than I expected" error
buf.clear()
return@of packet
})
}

override fun getId(): CustomPayload.Id<out CustomPayload> {
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/one/oktw/galaxy/network/ProxyChatPayload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ data class ProxyChatPayload(val packet: Packet) : CustomPayload {
val ID = CustomPayload.Id<ProxyChatPayload>(PROXY_CHAT_IDENTIFIER)
val CODEC: PacketCodec<PacketByteBuf, ProxyChatPayload> = PacketCodec.of(
{ value, buf -> buf.writeBytes(wrappedBuffer(encode(value.packet))) },
{ buf -> ProxyChatPayload(ProxyAPI.decode(buf.nioBuffer())) })
{ buf ->
val packet = ProxyChatPayload(ProxyAPI.decode(buf.nioBuffer()))
// FIXME: Workaround force clear buffer to suppress "Packet was larger than I expected" error
buf.clear()
return@of packet
})
}

override fun getId(): CustomPayload.Id<out CustomPayload> {
Expand Down

0 comments on commit 05f145a

Please sign in to comment.