37 lines
996 B
Java
37 lines
996 B
Java
package eu.mikroskeem.utils.simplerpc;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonSyntaxException;
|
|
import lombok.Data;
|
|
import lombok.ToString;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.io.*;
|
|
import java.util.List;
|
|
|
|
@Data @ToString
|
|
public class RPCRequest implements Serializable {
|
|
private String id;
|
|
private String method;
|
|
private List<Object> arguments;
|
|
|
|
@Nullable public byte[] toByteArray() {
|
|
try {
|
|
return new Gson().toJson(this, RPCRequest.class).getBytes("UTF-8");
|
|
} catch (JsonSyntaxException|UnsupportedEncodingException e){
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Nullable public static RPCRequest fromByteArray(byte[] serialized){
|
|
try {
|
|
return new Gson().fromJson(new String(serialized, "UTF-8"), RPCRequest.class);
|
|
} catch (JsonSyntaxException|UnsupportedEncodingException e){
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
}
|