This commit is contained in:
Coloryr committed 2024-05-08 16:25:33 +08:00
1 parent d276319c7a
commit dc86980a04
103 files changed
+2226 -1560

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
package com.coloryr.allmusic.server.codec;
import com.coloryr.allmusic.server.core.objs.enums.ComType;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
public class PacketCodec {
public static ByteBuf pack(ComType type, String data, int data1) {
ByteBuf buf = Unpooled.buffer(0);
buf.writeByte(type.ordinal());
switch (type) {
case HUD:
case LYRIC:
case LIST:
case INFO:
case IMG:
case PLAY:
writeString(buf, data);
break;
case POS:
buf.writeInt(data1);
break;
}
return buf;
}
public static void pack(ByteBuf buf, ComType type, String data, int data1) {
buf.writeByte(type.ordinal());
switch (type) {
case HUD:
case LYRIC:
case LIST:
case INFO:
case IMG:
case PLAY:
writeString(buf, data);
break;
case POS:
buf.writeInt(data1);
break;
}
}
private static void writeString(ByteBuf buf, String text) {
byte[] temp = text.getBytes(StandardCharsets.UTF_8);
buf.writeInt(temp.length);
buf.writeBytes(temp);
}
}