comparison src/goodjava/rpc/RpcClient.java @ 1402:27efb1fcbcb5

move luan.lib to goodjava
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 17 Sep 2019 01:35:01 -0400
parents src/luan/lib/rpc/RpcClient.java@87c674f3f6b7
children
comparison
equal deleted inserted replaced
1401:ef1620aa99cb 1402:27efb1fcbcb5
1 package goodjava.rpc;
2
3 import java.net.Socket;
4 import java.util.List;
5 import java.util.ArrayList;
6
7
8 public class RpcClient extends RpcCon {
9
10 public RpcClient(Socket socket)
11 throws RpcError
12 {
13 super(socket);
14 }
15
16 public void write(RpcCall call)
17 throws RpcError
18 {
19 List list = new ArrayList();
20 list.add(call.cmd);
21 for( Object arg : call.args ) {
22 list.add(arg);
23 }
24 write(call.in,call.lenIn,list);
25 }
26
27 public RpcResult read()
28 throws RpcError, RpcException
29 {
30 List list = readJson();
31 boolean ok = (Boolean)list.remove(0);
32 if( !ok ) {
33 String errorId = (String)list.remove(0);
34 Object[] args = list.toArray();
35 throw new RpcException(inBinary,lenBinary,errorId,args);
36 }
37 Object[] args = list.toArray();
38 return new RpcResult(inBinary,lenBinary,args);
39 }
40
41 }