diff src/luan/lib/rpc/RpcServer.java @ 1118:e4710ddfd287

start luan/lib/rpc
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 06 Aug 2017 20:11:11 -0600
parents
children 87c674f3f6b7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/lib/rpc/RpcServer.java	Sun Aug 06 20:11:11 2017 -0600
@@ -0,0 +1,46 @@
+package luan.lib.rpc;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.util.List;
+import java.util.ArrayList;
+
+
+public class RpcServer extends RpcCon {
+
+	public RpcServer(Socket socket) throws IOException {
+		super(socket);
+	}
+
+	public RpcCall read()
+		throws IOException
+	{
+		List list = readJson();
+		String cmd = (String)list.remove(0);
+		Object[] args = list.toArray();
+		return new RpcCall(inBinary,lenBinary,cmd,args);
+	}
+
+	public void write(RpcResult result)
+		throws IOException
+	{
+		List list = new ArrayList();
+		list.add(true);
+		for( Object val : result.returnValues ) {
+			list.add(val);
+		}
+		write(result.in,result.lenIn,list);
+	}
+
+	public void write(RpcException ex)
+		throws IOException
+	{
+		List list = new ArrayList();
+		list.add(false);
+		for( Object val : ex.values ) {
+			list.add(val);
+		}
+		write(ex.in,ex.lenIn,list);
+	}
+
+}