mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-11 21:57:31 +00:00
up
This commit is contained in:
1 parent
d276319c7a
commit
dc86980a04
103 files changed
+2226
-1560
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user