Skip to content

Commit

Permalink
Change name to Endec as the possible final name
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Seeker committed Oct 24, 2023
1 parent 7336ee7 commit 08cde20
Show file tree
Hide file tree
Showing 28 changed files with 764 additions and 775 deletions.
9 changes: 4 additions & 5 deletions src/main/java/io/wispforest/owo/network/OwoHandshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import io.wispforest.owo.mixin.ServerCommonNetworkHandlerAccessor;
import io.wispforest.owo.ops.TextOps;
import io.wispforest.owo.particles.systems.ParticleSystemController;
import io.wispforest.owo.serialization.Codeck;
import io.wispforest.owo.serialization.impl.ReflectionCodeckBuilder;
import io.wispforest.owo.serialization.Endec;
import io.wispforest.owo.serialization.impl.ReflectionEndecBuilder;
import io.wispforest.owo.serialization.impl.bytebuf.ByteBufDeserializer;
import io.wispforest.owo.serialization.impl.bytebuf.ByteBufSerializer;
import io.wispforest.owo.util.OwoFreezer;
Expand All @@ -31,16 +31,15 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.ToIntFunction;

@SuppressWarnings("UnstableApiUsage")
@ApiStatus.Internal
public final class OwoHandshake {

@SuppressWarnings("unchecked")
private static final Codeck<Map<Identifier, Integer>> RESPONSE_SERIALIZER =
(Codeck<Map<Identifier, Integer>>) (Object) ReflectionCodeckBuilder.createMapSerializer(Map.class, Identifier.class, Integer.class);
private static final Endec<Map<Identifier, Integer>> RESPONSE_SERIALIZER =
(Endec<Map<Identifier, Integer>>) (Object) ReflectionEndecBuilder.createMapSerializer(Map.class, Identifier.class, Integer.class);

private static final MutableText PREFIX = TextOps.concat(Owo.PREFIX, Text.of("§chandshake failure\n"));
public static final Identifier CHANNEL_ID = new Identifier("owo", "handshake");
Expand Down
48 changes: 24 additions & 24 deletions src/main/java/io/wispforest/owo/network/OwoNetChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.wispforest.owo.mixin.ServerCommonNetworkHandlerAccessor;
import io.wispforest.owo.network.serialization.PacketBufSerializer;
import io.wispforest.owo.serialization.impl.RecordCodeck;
import io.wispforest.owo.serialization.impl.StructCodeck;
import io.wispforest.owo.serialization.impl.RecordEndec;
import io.wispforest.owo.serialization.impl.StructEndec;
import io.wispforest.owo.serialization.impl.bytebuf.ByteBufDeserializer;
import io.wispforest.owo.serialization.impl.bytebuf.ByteBufSerializer;
import io.wispforest.owo.util.OwoFreezer;
Expand Down Expand Up @@ -167,7 +167,7 @@ private OwoNetChannel(Identifier id, String ownerClassName, boolean required) {
*/
@SuppressWarnings("unchecked")
public <R extends Record> void registerClientbound(Class<R> messageClass, ChannelHandler<R, ClientAccess> handler) {
registerClientbound(messageClass, handler, () -> RecordCodeck.create(messageClass));
registerClientbound(messageClass, handler, () -> RecordEndec.create(messageClass));
}

/**
Expand All @@ -182,7 +182,7 @@ public <R extends Record> void registerClientbound(Class<R> messageClass, Channe
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
public <R extends Record> void registerClientboundDeferred(Class<R> messageClass) {
registerClientboundDeferred(messageClass, () -> RecordCodeck.create(messageClass));
registerClientboundDeferred(messageClass, () -> RecordEndec.create(messageClass));
}

/**
Expand All @@ -197,7 +197,7 @@ public <R extends Record> void registerClientboundDeferred(Class<R> messageClass
*/
@SuppressWarnings("unchecked")
public <R extends Record> void registerServerbound(Class<R> messageClass, ChannelHandler<R, ServerAccess> handler) {
registerServerbound(messageClass, handler, () -> RecordCodeck.create(messageClass));
registerServerbound(messageClass, handler, () -> RecordEndec.create(messageClass));
}

//--
Expand All @@ -208,16 +208,16 @@ public <R extends Record> void registerServerbound(Class<R> messageClass, Channe
* about a missing type adapter is thrown, register one
*
* @param messageClass The type of packet data to send and serialize
* @param codeck The alternative Codeck to Serialize the given Record
* @param endec The alternative Endec to Serialize the given Record
* @param handler The handler that will receive the deserialized
* @see #serverHandle(PlayerEntity)
* @see #serverHandle(MinecraftServer)
* @see #serverHandle(ServerWorld, BlockPos)
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
@SuppressWarnings("unchecked")
public <R extends Record> void registerClientbound(Class<R> messageClass, StructCodeck<R> codeck, ChannelHandler<R, ClientAccess> handler) {
registerClientbound(messageClass, handler, () -> codeck);
public <R extends Record> void registerClientbound(Class<R> messageClass, StructEndec<R> endec, ChannelHandler<R, ClientAccess> handler) {
registerClientbound(messageClass, handler, () -> endec);
}

/**
Expand All @@ -226,14 +226,14 @@ public <R extends Record> void registerClientbound(Class<R> messageClass, Struct
* about a missing type adapter is thrown, register one
*
* @param messageClass The type of packet data to send and serialize
* @param codeck The alternative Codeck to Serialize the given Record
* @param endec The alternative Endec to Serialize the given Record
* @see #serverHandle(PlayerEntity)
* @see #serverHandle(MinecraftServer)
* @see #serverHandle(ServerWorld, BlockPos)
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
public <R extends Record> void registerClientboundDeferred(Class<R> messageClass, StructCodeck<R> codeck) {
registerClientboundDeferred(messageClass, () -> codeck);
public <R extends Record> void registerClientboundDeferred(Class<R> messageClass, StructEndec<R> endec) {
registerClientboundDeferred(messageClass, () -> endec);
}

/**
Expand All @@ -242,20 +242,20 @@ public <R extends Record> void registerClientboundDeferred(Class<R> messageClass
* about a missing type adapter is thrown, register one
*
* @param messageClass The type of packet data to send and serialize
* @param codeck The alternative Codeck to Serialize the given Record
* @param endec The alternative Endec to Serialize the given Record
* @param handler The handler that will receive the deserialized
* @see #clientHandle()
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
@SuppressWarnings("unchecked")
public <R extends Record> void registerServerbound(Class<R> messageClass, StructCodeck<R> codeck, ChannelHandler<R, ServerAccess> handler) {
registerServerbound(messageClass, handler, () -> codeck);
public <R extends Record> void registerServerbound(Class<R> messageClass, StructEndec<R> endec, ChannelHandler<R, ServerAccess> handler) {
registerServerbound(messageClass, handler, () -> endec);
}

//--

@SuppressWarnings("unchecked")
private <R extends Record> void registerClientbound(Class<R> messageClass, ChannelHandler<R, ClientAccess> handler, Supplier<StructCodeck<R>> codeck) {
private <R extends Record> void registerClientbound(Class<R> messageClass, ChannelHandler<R, ClientAccess> handler, Supplier<StructEndec<R>> endec) {
int deferredIndex = deferredClientSerializers.removeInt(messageClass);
if (deferredIndex != -1) {
OwoFreezer.checkRegister("Network handlers");
Expand All @@ -265,22 +265,22 @@ private <R extends Record> void registerClientbound(Class<R> messageClass, Chan
}

int index = this.clientHandlers.size();
this.createSerializer(messageClass, index, EnvType.CLIENT, codeck);
this.createSerializer(messageClass, index, EnvType.CLIENT, endec);
this.clientHandlers.add((ChannelHandler<Record, ClientAccess>) handler);
}

private <R extends Record> void registerClientboundDeferred(Class<R> messageClass, Supplier<StructCodeck<R>> codeck) {
private <R extends Record> void registerClientboundDeferred(Class<R> messageClass, Supplier<StructEndec<R>> endec) {
int index = this.clientHandlers.size();
this.createSerializer(messageClass, index, EnvType.CLIENT, codeck);
this.createSerializer(messageClass, index, EnvType.CLIENT, endec);
this.clientHandlers.add(null);

this.deferredClientSerializers.put(messageClass, index);
}

@SuppressWarnings("unchecked")
private <R extends Record> void registerServerbound(Class<R> messageClass, ChannelHandler<R, ServerAccess> handler, Supplier<StructCodeck<R>> codeck) {
private <R extends Record> void registerServerbound(Class<R> messageClass, ChannelHandler<R, ServerAccess> handler, Supplier<StructEndec<R>> endec) {
int index = this.serverHandlers.size();
this.createSerializer(messageClass, index, EnvType.SERVER, codeck);
this.createSerializer(messageClass, index, EnvType.SERVER, endec);
this.serverHandlers.add((ChannelHandler<Record, ServerAccess>) handler);
}

Expand Down Expand Up @@ -412,7 +412,7 @@ private ServerHandle getServerHandle() {
return serverHandle;
}

private <R extends Record> void createSerializer(Class<R> messageClass, int handlerIndex, EnvType target, Supplier<StructCodeck<R>> supplier) {
private <R extends Record> void createSerializer(Class<R> messageClass, int handlerIndex, EnvType target, Supplier<StructEndec<R>> supplier) {
OwoFreezer.checkRegister("Network handlers");

var serializer = serializersByClass.get(messageClass);
Expand Down Expand Up @@ -568,14 +568,14 @@ static final class IndexedSerializer<R extends Record> {
private int serverHandlerIndex = -1;

final Class<R> rClass;
final StructCodeck<R> serializer;
final StructEndec<R> serializer;

private IndexedSerializer(Class<R> rClass, StructCodeck<R> serializer) {
private IndexedSerializer(Class<R> rClass, StructEndec<R> serializer) {
this.serializer = serializer;
this.rClass = rClass;
}

public static <R extends Record> IndexedSerializer<R> create(Class<R> rClass, StructCodeck<R> serializer, int index, EnvType target) {
public static <R extends Record> IndexedSerializer<R> create(Class<R> rClass, StructEndec<R> serializer, int index, EnvType target) {
return new IndexedSerializer<>(rClass, serializer).setHandlerIndex(index, target);
}

Expand Down
Loading

0 comments on commit 08cde20

Please sign in to comment.