Add some basic structures to aid in serialize/deserializing

This commit is contained in:
Aria 2023-06-13 22:58:43 -07:00
parent 609ffd6a86
commit 7d862f046f
3 changed files with 52 additions and 1 deletions

View file

@ -0,0 +1,26 @@
package dev.zontreck.ariaslib.xmlrpc;
public class MethodCall {
private String methodName;
private Object[] params;
public MethodCall ( String methodName , Object[] params ) {
this.methodName = methodName;
this.params = params;
}
public String getMethodName ( ) {
return methodName;
}
public Object[] getParams ( ) {
return params;
}
public static MethodCall fromDeserializer ( XmlRpcDeserializer deserializer ) throws Exception {
String methodName = deserializer.readMethodName ( );
Object[] params = deserializer.readMethodParams ( );
return new MethodCall ( methodName , params );
}
}

View file

@ -0,0 +1,26 @@
package dev.zontreck.ariaslib.xmlrpc;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class MethodResponse {
public Map<String, Object> parameters = new HashMap<> ( );
public MethodResponse ( ) {
}
public String toXml ( ) {
ByteArrayOutputStream baos = new ByteArrayOutputStream ( );
XmlRpcStreamWriter streamWriter = new XmlRpcStreamWriter ( baos );
try {
streamWriter.writeMethodResponse ( parameters );
return new String ( baos.toByteArray ( ) );
} catch ( IOException e ) {
throw new RuntimeException ( e );
}
}
}

View file

@ -53,7 +53,6 @@ public class XmlRpcStreamWriter {
writer.write ( PARAM_END_TAG );
}
}
writer.write ( PARAMS_END_TAG );
writer.write ( METHOD_CALL_END_TAG );
writer.flush ( );