diff src/luan/lib/rpc/RpcClient.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/RpcClient.java	Sun Aug 06 20:11:11 2017 -0600
@@ -0,0 +1,40 @@
+package luan.lib.rpc;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.util.List;
+import java.util.ArrayList;
+
+
+public class RpcClient extends RpcCon {
+
+	public RpcClient(Socket socket) throws IOException {
+		super(socket);
+	}
+
+	public void write(RpcCall call)
+		throws IOException
+	{
+		List list = new ArrayList();
+		list.add(call.cmd);
+		for( Object arg : call.args ) {
+			list.add(arg);
+		}
+		write(call.in,call.lenIn,list);
+	}
+
+	public RpcResult read()
+		throws IOException, RpcException
+	{
+		List list = readJson();
+		boolean ok = (Boolean)list.remove(0);
+		if( !ok ) {
+			String errorId = (String)list.remove(0);
+			Object[] args = list.toArray();
+			throw new RpcException(inBinary,lenBinary,errorId,args);
+		}
+		Object[] args = list.toArray();
+		return new RpcResult(inBinary,lenBinary,args);
+	}
+
+}