comparison 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
comparison
equal deleted inserted replaced
1117:9a1aa6fc0b4e 1118:e4710ddfd287
1 package luan.lib.rpc;
2
3 import java.io.IOException;
4 import java.net.Socket;
5 import java.util.List;
6 import java.util.ArrayList;
7
8
9 public class RpcClient extends RpcCon {
10
11 public RpcClient(Socket socket) throws IOException {
12 super(socket);
13 }
14
15 public void write(RpcCall call)
16 throws IOException
17 {
18 List list = new ArrayList();
19 list.add(call.cmd);
20 for( Object arg : call.args ) {
21 list.add(arg);
22 }
23 write(call.in,call.lenIn,list);
24 }
25
26 public RpcResult read()
27 throws IOException, RpcException
28 {
29 List list = readJson();
30 boolean ok = (Boolean)list.remove(0);
31 if( !ok ) {
32 String errorId = (String)list.remove(0);
33 Object[] args = list.toArray();
34 throw new RpcException(inBinary,lenBinary,errorId,args);
35 }
36 Object[] args = list.toArray();
37 return new RpcResult(inBinary,lenBinary,args);
38 }
39
40 }