2023-09-04 11:30:57 +00:00
|
|
|
package me.topchetoeu.jscript.engine.debug;
|
|
|
|
|
|
|
|
public class WebSocketMessage {
|
|
|
|
public static enum Type {
|
|
|
|
Text,
|
|
|
|
Binary,
|
|
|
|
}
|
|
|
|
|
|
|
|
public final Type type;
|
|
|
|
private final Object data;
|
|
|
|
|
|
|
|
public final String textData() {
|
|
|
|
if (type != Type.Text) throw new IllegalStateException("Message is not text.");
|
|
|
|
return (String)data;
|
|
|
|
}
|
|
|
|
public final byte[] binaryData() {
|
|
|
|
if (type != Type.Binary) throw new IllegalStateException("Message is not binary.");
|
|
|
|
return (byte[])data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public WebSocketMessage(String data) {
|
|
|
|
this.type = Type.Text;
|
|
|
|
this.data = data;
|
|
|
|
}
|
|
|
|
public WebSocketMessage(byte[] data) {
|
|
|
|
this.type = Type.Binary;
|
|
|
|
this.data = data;
|
|
|
|
}
|
|
|
|
}
|