implement typescript server, bug fix
[PxpRpc.git] / csharp / dotnet / pxprpc / AbstractCallable.cs
blob540f026ce8bfd32e715005489724a520e0f59a8f
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
5 namespace pxprpc
7 public abstract class AbstractCallable : PxpCallable
9 public void writeResult(PxpRequest req)
11 ServerContext ctx = req.context;
12 if (req.result is Exception)
14 ctx.writeInt32(1);
16 else
18 ctx.writeInt32(0);
22 public int csTypeToSwitchId(Type cstype)
24 if (cstype == typeof(bool))
26 return 1;
28 else if (cstype == typeof(byte))
30 return 2;
32 else if (cstype == typeof(short))
34 return 3;
36 else if (cstype == typeof(int))
38 return 4;
40 else if (cstype == typeof(long))
42 return 5;
44 else if (cstype == typeof(float))
46 return 6;
48 else if (cstype == typeof(double))
50 return 7;
52 else if (cstype == typeof(string))
54 return 9;
56 else
58 return 8;
63 public Object readNext(ServerContext ctx, int switchId)
65 switch (switchId)
67 //primitive type
68 //boolean
69 case 1:
70 return ctx.readInt32() != 0;
71 //byte
72 case 2:
73 return (byte)ctx.readInt32();
74 //short
75 case 3:
76 return (short)ctx.readInt32();
77 //int
78 case 4:
79 return ctx.readInt32();
80 //long
81 case 5:
82 return ctx.readInt64();
83 //float
84 case 6:
85 return ctx.readFloat32();
86 //double
87 case 7:
88 return ctx.readFloat64();
89 //reference type
90 case 8:
91 int addr = ctx.readInt32();
92 return ctx.refSlots[addr].get();
93 case 9:
94 //string type
95 return ctx.readNextString();
96 default:
97 throw new NotImplementedException();
101 public void writeNext(ServerContext ctx, int switchId, Object obj, int addrIfRefType)
103 switch (switchId)
105 //primitive type
106 //boolean
107 case 1:
108 ctx.writeInt32((Boolean)obj ? 1 : 0);
109 break;
110 //byte
111 case 2:
112 ctx.writeInt32((Byte)obj);
113 break;
114 //short
115 case 3:
116 ctx.writeInt32((Int16)obj);
117 break;
118 //int
119 case 4:
120 ctx.writeInt32((Int32)obj);
121 break;
122 //long
123 case 5:
124 ctx.writeInt64((Int64)obj);
125 break;
126 //float
127 case 6:
128 ctx.writeFloat32((Single)obj);
129 break;
130 //double
131 case 7:
132 ctx.writeFloat64((Double)obj);
133 break;
134 //reference type
135 case 8:
136 case 9:
137 //processed by callable
138 default:
139 throw new NotImplementedException();
143 public abstract void readParameter(PxpRequest req);
144 public abstract void call(PxpRequest req, Action<object> asyncRet);