-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MachineMC/1.1
1.1
- Loading branch information
Showing
107 changed files
with
3,545 additions
and
1,571 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 |
---|---|---|
|
@@ -12,4 +12,4 @@ tasks { | |
jvmTarget = "21" | ||
} | ||
} | ||
} | ||
} |
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
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,11 +1,15 @@ | ||
# Group and version | ||
group = org.machinemc.paklet | ||
version = 1.0.1 | ||
version = 1.1 | ||
|
||
# Dependency versions | ||
jetbrainsAnnotations = 24.1.0 | ||
junit = 5.10.1 | ||
asm = 9.6 | ||
netty = 4.1.80.Final | ||
googleAutoservice = 1.1.1 | ||
googleGson = 2.10.1 | ||
googleGson = 2.10.1 | ||
jmh = 1.37 | ||
|
||
# Plugins | ||
champeauJmh = 0.7.2 |
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,14 @@ | ||
plugins { | ||
id("java-library-convention") | ||
id("org.machinemc.paklet-plugin") | ||
alias(libs.plugins.champeau.jmh) | ||
} | ||
|
||
dependencies { | ||
implementation(libs.netty) | ||
|
||
jmhAnnotationProcessor(project(":paklet-processor")) | ||
|
||
implementation(project(":paklet-api")) | ||
implementation(project(":paklet-core")) | ||
} |
41 changes: 41 additions & 0 deletions
41
jmh-benchmarks/src/jmh/java/org/machinemc/paklet/BenchmarkPackets.java
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,41 @@ | ||
package org.machinemc.paklet; | ||
|
||
import org.machinemc.paklet.packets.ArrayPacket; | ||
import org.machinemc.paklet.packets.CollectionPacket; | ||
import org.machinemc.paklet.packets.SimplePacket; | ||
|
||
import java.util.List; | ||
|
||
public final class BenchmarkPackets { | ||
|
||
private BenchmarkPackets() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public static SimplePacket simplePacket() { | ||
var packet = new SimplePacket(); | ||
packet.f1 = 20; | ||
packet.f2 = true; | ||
packet.f3 = 10; | ||
packet.f4 = "Hello World!"; | ||
packet.f5 = 1.5f; | ||
return packet; | ||
} | ||
|
||
public static ArrayPacket arrayPacket() { | ||
var packet = new ArrayPacket(); | ||
packet.intArray = new int[] { 1, 2, 3, 4, 5, 6 }; | ||
packet.nestedStringArray = new String[][] { new String[] { "Hello World" }, new String[0] }; | ||
packet.doubleArray = new double[] { 1, 2, 3, 4, 5, 6, 7, 8 }; | ||
return packet; | ||
} | ||
|
||
public static CollectionPacket collectionPacket() { | ||
var packet = new CollectionPacket(); | ||
packet.stringList = List.of("Hello", "World", "!", "Foo", "Bar"); | ||
packet.integerCollection = List.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||
packet.nestedStringList = List.of(packet.stringList, packet.stringList); | ||
return packet; | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
jmh-benchmarks/src/jmh/java/org/machinemc/paklet/PacketReadBenchmark.java
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,67 @@ | ||
package org.machinemc.paklet; | ||
|
||
import io.netty.buffer.Unpooled; | ||
import org.machinemc.paklet.netty.NettyDataVisitor; | ||
import org.machinemc.paklet.packets.ArrayPacket; | ||
import org.machinemc.paklet.packets.CollectionPacket; | ||
import org.machinemc.paklet.packets.SimplePacket; | ||
import org.machinemc.paklet.serialization.SerializerProvider; | ||
import org.machinemc.paklet.serialization.catalogue.DefaultSerializationRules; | ||
import org.machinemc.paklet.serialization.catalogue.DefaultSerializers; | ||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Measurement(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
public class PacketReadBenchmark { | ||
|
||
PacketFactory factory; | ||
|
||
@Setup | ||
public void setup() { | ||
SerializerProvider serializerProvider = new SerializerProviderImpl(); | ||
serializerProvider.addSerializers(DefaultSerializers.class); | ||
serializerProvider.addSerializationRules(DefaultSerializationRules.class); | ||
|
||
factory = new PacketFactoryImpl(PacketEncoder.varInt(), serializerProvider); | ||
factory.addPackets(BenchmarkPackets.class); | ||
} | ||
|
||
@Benchmark | ||
public void simplePacketRead100() { | ||
SimplePacket packet = BenchmarkPackets.simplePacket(); | ||
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer()); | ||
factory.write(packet, visitor); | ||
for (int i = 0; i < 100; i++) { | ||
factory.create(Packet.DEFAULT, visitor); | ||
visitor.readerIndex(0); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void arrayPacketRead100() { | ||
ArrayPacket packet = BenchmarkPackets.arrayPacket(); | ||
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer()); | ||
factory.write(packet, visitor); | ||
for (int i = 0; i < 100; i++) { | ||
factory.create(Packet.DEFAULT, visitor); | ||
visitor.readerIndex(0); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void collectionPacketRead100() { | ||
CollectionPacket packet = BenchmarkPackets.collectionPacket(); | ||
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer()); | ||
factory.write(packet, visitor); | ||
for (int i = 0; i < 100; i++) { | ||
factory.create(Packet.DEFAULT, visitor); | ||
visitor.readerIndex(0); | ||
} | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
jmh-benchmarks/src/jmh/java/org/machinemc/paklet/PacketWriteBenchmark.java
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,64 @@ | ||
package org.machinemc.paklet; | ||
|
||
import io.netty.buffer.Unpooled; | ||
import org.machinemc.paklet.netty.NettyDataVisitor; | ||
import org.machinemc.paklet.packets.ArrayPacket; | ||
import org.machinemc.paklet.packets.CollectionPacket; | ||
import org.machinemc.paklet.packets.SimplePacket; | ||
import org.machinemc.paklet.serialization.SerializerProvider; | ||
import org.machinemc.paklet.serialization.catalogue.DefaultSerializationRules; | ||
import org.machinemc.paklet.serialization.catalogue.DefaultSerializers; | ||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@Measurement(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
public class PacketWriteBenchmark { | ||
|
||
PacketFactory factory; | ||
|
||
@Setup | ||
public void setup() { | ||
SerializerProvider serializerProvider = new SerializerProviderImpl(); | ||
serializerProvider.addSerializers(DefaultSerializers.class); | ||
serializerProvider.addSerializationRules(DefaultSerializationRules.class); | ||
|
||
factory = new PacketFactoryImpl(PacketEncoder.varInt(), serializerProvider); | ||
factory.addPackets(BenchmarkPackets.class); | ||
} | ||
|
||
@Benchmark | ||
public void simplePacketWrite100() { | ||
SimplePacket packet = BenchmarkPackets.simplePacket(); | ||
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer()); | ||
for (int i = 0; i < 100; i++) { | ||
factory.write(packet, visitor); | ||
visitor.writerIndex(0); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void arrayPacketWrite100() { | ||
ArrayPacket packet = BenchmarkPackets.arrayPacket(); | ||
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer()); | ||
for (int i = 0; i < 100; i++) { | ||
factory.write(packet, visitor); | ||
visitor.writerIndex(0); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void collectionPacketWrite100() { | ||
CollectionPacket packet = BenchmarkPackets.collectionPacket(); | ||
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer()); | ||
for (int i = 0; i < 100; i++) { | ||
factory.write(packet, visitor); | ||
visitor.writerIndex(0); | ||
} | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
jmh-benchmarks/src/jmh/java/org/machinemc/paklet/packets/ArrayPacket.java
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,13 @@ | ||
package org.machinemc.paklet.packets; | ||
|
||
import org.machinemc.paklet.BenchmarkPackets; | ||
import org.machinemc.paklet.Packet; | ||
|
||
@Packet(id = 1, catalogue = BenchmarkPackets.class) | ||
public class ArrayPacket { | ||
|
||
public int[] intArray; | ||
public String[][] nestedStringArray; | ||
public double[] doubleArray; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
jmh-benchmarks/src/jmh/java/org/machinemc/paklet/packets/CollectionPacket.java
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,16 @@ | ||
package org.machinemc.paklet.packets; | ||
|
||
import org.machinemc.paklet.BenchmarkPackets; | ||
import org.machinemc.paklet.Packet; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
@Packet(id = 3, catalogue = BenchmarkPackets.class) | ||
public class CollectionPacket { | ||
|
||
public List<String> stringList; | ||
public Collection<Integer> integerCollection; | ||
public List<List<String>> nestedStringList; | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
jmh-benchmarks/src/jmh/java/org/machinemc/paklet/packets/SimplePacket.java
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,15 @@ | ||
package org.machinemc.paklet.packets; | ||
|
||
import org.machinemc.paklet.BenchmarkPackets; | ||
import org.machinemc.paklet.Packet; | ||
|
||
@Packet(id = 0, catalogue = BenchmarkPackets.class) | ||
public class SimplePacket { | ||
|
||
public double f1; | ||
public boolean f2; | ||
public int f3; | ||
public String f4; | ||
public float f5; | ||
|
||
} |
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 |
---|---|---|
|
@@ -22,4 +22,4 @@ publishing { | |
from(components["java"]) | ||
} | ||
} | ||
} | ||
} |
16 changes: 9 additions & 7 deletions
16
...ava/org/machinemc/paklet/PacketLogic.java → ...va/org/machinemc/paklet/CustomPacket.java
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,29 +1,31 @@ | ||
package org.machinemc.paklet; | ||
|
||
import org.machinemc.paklet.serialization.SerializerContext; | ||
|
||
/** | ||
* Used for packets that are serialized manually (not automatically using registered serializers). | ||
* <p> | ||
* This can be used for packets that require very specific serialization to be done to optimize | ||
* the process and keeping the code clean. | ||
* <p> | ||
* This also allows the packet class to extend another class. | ||
*/ | ||
public interface PacketLogic { | ||
public interface CustomPacket { | ||
|
||
/** | ||
* Used during deserialization of the packet to read the packet data. | ||
* <p> | ||
* Is called only within serializer context; {@link Serializer#context()} can be used. | ||
* | ||
* @param context serialization context | ||
* @param visitor visitor | ||
*/ | ||
void construct(DataVisitor visitor); | ||
void construct(SerializerContext context, DataVisitor visitor); | ||
|
||
/** | ||
* Used during serialization of the packet to write the packet data. | ||
* <p> | ||
* Is called only within serializer context; {@link Serializer#context()} can be used. | ||
* | ||
* @param context serialization context | ||
* @param visitor visitor | ||
*/ | ||
void deconstruct(DataVisitor visitor); | ||
void deconstruct(SerializerContext context, DataVisitor visitor); | ||
|
||
} |
Oops, something went wrong.