Allocate buffer exactly in NameSuggestionsCodec

Signed-off-by: Graham <gpe@openrs2.org>
Graham 2 years ago
parent fa41b48f1a
commit 76e7e93f3c
  1. 14
      protocol/src/main/kotlin/org/openrs2/protocol/create/downstream/NameSuggestionsCodec.kt

@ -1,6 +1,7 @@
package org.openrs2.protocol.create.downstream package org.openrs2.protocol.create.downstream
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufAllocator
import org.openrs2.crypto.StreamCipher import org.openrs2.crypto.StreamCipher
import org.openrs2.protocol.PacketCodec import org.openrs2.protocol.PacketCodec
import org.openrs2.util.Base37 import org.openrs2.util.Base37
@ -42,4 +43,17 @@ public class NameSuggestionsCodec : PacketCodec<CreateResponse.NameSuggestions>(
output.setByte(index, written / 8) output.setByte(index, written / 8)
} }
override fun allocateBuffer(
alloc: ByteBufAllocator,
input: CreateResponse.NameSuggestions,
preferDirect: Boolean
): ByteBuf {
val len = 2 + input.names.size * 8
return if (preferDirect) {
alloc.ioBuffer(len, len)
} else {
alloc.heapBuffer(len, len)
}
}
} }

Loading…
Cancel
Save