Skip to content

Commit

Permalink
replace Serializer.string with TypeIO
Browse files Browse the repository at this point in the history
  • Loading branch information
xzxADIxzx committed Mar 13, 2023
1 parent ce891e8 commit 820ec68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
2 changes: 1 addition & 1 deletion mod.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ A mod that increases the schematic size limit to 512 blocks! Adds admins, render
",
author: "[#0096FF]xzxADIxzx",
minGameVersion: 142,
version: 2.7.44,
version: 2.7.45,
hidden: true,
main: scheme.Main
23 changes: 4 additions & 19 deletions src/java/scheme/ClajIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import arc.util.Threads;
import mindustry.game.EventType.*;
import mindustry.gen.Call;
import mindustry.io.TypeIO;
import mindustry.net.ArcNetProvider.*;

import static mindustry.Vars.*;
Expand Down Expand Up @@ -82,7 +83,7 @@ public static void joinRoom(String ip, int port, String key, Runnable success) {

ByteBuffer buffer = ByteBuffer.allocate(8192);
buffer.put(Serializer.linkID);
Serializer.writeString(buffer, key);
TypeIO.writeString(buffer, key);

buffer.limit(buffer.position()).position(0);
net.send(buffer, true);
Expand Down Expand Up @@ -127,33 +128,17 @@ public static class Serializer extends PacketSerializer {
public void write(ByteBuffer buffer, Object object) {
if (object instanceof String link) {
buffer.put(linkID);
writeString(buffer, link);
TypeIO.writeString(buffer, link);
} else
super.write(buffer, object);
}

@Override
public Object read(ByteBuffer buffer) {
if (buffer.get() == linkID) return readString(buffer);
if (buffer.get() == linkID) return TypeIO.readString(buffer);

buffer.position(buffer.position() - 1);
return super.read(buffer);
}

public static void writeString(ByteBuffer buffer, String message) {
buffer.putInt(message.length());
for (char chara : message.toCharArray())
buffer.putChar(chara);
}

public static String readString(ByteBuffer buffer) {
int length = buffer.getInt();

StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++)
builder.append(buffer.getChar());

return builder.toString();
}
}
}

0 comments on commit 820ec68

Please sign in to comment.