-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
634 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace KissRpc.IDL.flatbuffer; | ||
namespace kissrpc.IDL.flatbuffer; | ||
|
||
table UserInfoFB{ | ||
name:string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module KissRpc.IDL.kissidlMessage; | ||
module kissrpc.IDL.kissidlMessage; | ||
import std.typetuple; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace KissRpc.IDL.flatbuffer; | ||
namespace kissrpc.IDL.flatbuffer; | ||
|
||
table UserInfoFB{ | ||
name:string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module KissRpc.IDL.kissidlMessage; | ||
module kissrpc.IDL.kissidlMessage; | ||
import std.typetuple; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
//kiss rpc idl demo | ||
|
||
@message:UserInfo | ||
{ | ||
int i:1; | ||
string name:2; | ||
} | ||
|
||
@service:Test | ||
{ | ||
UserInfo getName(UserInfo userInfo); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
//kiss rpc idl demo | ||
|
||
|
||
|
||
@message:UserInfo | ||
{ | ||
string name:1; | ||
int age:2; | ||
double widget:3; | ||
} | ||
|
||
@message:Contacts | ||
{ | ||
int number:1; | ||
UserInfo[] userInfoList:2; | ||
} | ||
|
||
|
||
@message:AccountName | ||
{ | ||
string name:1; | ||
int count:2; | ||
} | ||
|
||
@service:AddressBook //接口类 | ||
{ | ||
Contacts getContactList(AccountName accountName); | ||
} | ||
|
111 changes: 111 additions & 0 deletions
111
kiss-rpc-idl/kissrpc/generated/client/TestRpcInterface.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
module kissrpc.generated.TestRpcInterface; | ||
|
||
import kissrpc.generated.TestRpcMessage; | ||
import kissrpc.generated.TestRpcService; | ||
|
||
import kissrpc.RpcRequest; | ||
import kissrpc.RpcClientImpl; | ||
import kissrpc.RpcClient; | ||
import kissrpc.RpcResponse; | ||
import kissrpc.Unit; | ||
import flatbuffers; | ||
import kissrpc.generated.message.TestRpc; | ||
|
||
abstract class RpcTestInterface{ | ||
|
||
this(RpcClient rpClient){ | ||
rpImpl = new RpcClientImpl!(RpcTestService)(rpClient); | ||
} | ||
|
||
UserInfo getNameInterface(const UserInfo userInfo, const RPC_PACKAGE_COMPRESS_TYPE compressType, const int secondsTimeOut, const size_t funcId = 2791659981){ | ||
|
||
auto builder = new FlatBufferBuilder(512); | ||
|
||
//input flatbuffer code for UserInfoFB class | ||
|
||
|
||
|
||
|
||
auto userInfoPos = UserInfoFB.createUserInfoFB(builder, userInfo.i, builder.createString(userInfo.name), ); | ||
|
||
|
||
builder.finish(userInfoPos); | ||
|
||
auto req = new RpcRequest(compressType, secondsTimeOut); | ||
|
||
req.push(builder.sizedByteArray); | ||
|
||
RpcResponse resp = rpImpl.syncCall(req, RPC_PACKAGE_PROTOCOL.TPP_FLAT_BUF, funcId); | ||
|
||
if(resp.getStatus == RESPONSE_STATUS.RS_OK){ | ||
|
||
ubyte[] flatBufBytes; | ||
resp.pop(flatBufBytes); | ||
|
||
auto ret_UserInfoFB = UserInfoFB.getRootAsUserInfoFB(new ByteBuffer(flatBufBytes)); | ||
UserInfo ret_UserInfo; | ||
|
||
//input flatbuffer code for UserInfoFB class | ||
|
||
|
||
|
||
|
||
ret_UserInfo.i = ret_UserInfoFB.i; | ||
ret_UserInfo.name = ret_UserInfoFB.name; | ||
|
||
|
||
return ret_UserInfo; | ||
}else{ | ||
throw new Exception("rpc sync call error, function:" ~ RpcBindFunctionMap[funcId]); | ||
} | ||
} | ||
|
||
|
||
alias RpcgetNameCallback = void delegate(UserInfo); | ||
|
||
void getNameInterface(const UserInfo userInfo, RpcgetNameCallback rpcCallback, const RPC_PACKAGE_COMPRESS_TYPE compressType, const int secondsTimeOut, const size_t funcId = 2791659981){ | ||
|
||
auto builder = new FlatBufferBuilder(512); | ||
//input flatbuffer code for UserInfoFB class | ||
|
||
|
||
|
||
|
||
auto userInfoPos = UserInfoFB.createUserInfoFB(builder, userInfo.i, builder.createString(userInfo.name), ); | ||
|
||
|
||
builder.finish(userInfoPos); | ||
auto req = new RpcRequest(compressType, secondsTimeOut); | ||
|
||
req.push(builder.sizedByteArray); | ||
|
||
rpImpl.asyncCall(req, delegate(RpcResponse resp){ | ||
|
||
if(resp.getStatus == RESPONSE_STATUS.RS_OK){ | ||
|
||
ubyte[] flatBufBytes; | ||
UserInfo ret_UserInfo; | ||
|
||
resp.pop(flatBufBytes); | ||
|
||
auto ret_UserInfoFB = UserInfoFB.getRootAsUserInfoFB(new ByteBuffer(flatBufBytes)); | ||
//input flatbuffer code for UserInfoFB class | ||
|
||
|
||
|
||
|
||
ret_UserInfo.i = ret_UserInfoFB.i; | ||
ret_UserInfo.name = ret_UserInfoFB.name; | ||
|
||
|
||
rpcCallback(ret_UserInfo); | ||
}else{ | ||
throw new Exception("rpc sync call error, function:" ~ RpcBindFunctionMap[funcId]); | ||
}}, RPC_PACKAGE_PROTOCOL.TPP_FLAT_BUF, funcId); | ||
} | ||
|
||
|
||
RpcClientImpl!(RpcTestService) rpImpl; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module kissrpc.generated.TestRpcService; | ||
|
||
|
||
import kissrpc.generated.TestRpcInterface; | ||
import kissrpc.generated.TestRpcMessage; | ||
|
||
import kissrpc.RpcClient; | ||
import kissrpc.Unit; | ||
|
||
|
||
class RpcTestService: RpcTestInterface{ | ||
|
||
this(RpcClient rpClient){ | ||
RpcBindFunctionMap[2791659981] = typeid(&RpcTestService.getName).toString(); | ||
super(rpClient); | ||
} | ||
|
||
UserInfo getName(UserInfo userInfo, const RPC_PACKAGE_COMPRESS_TYPE compressType = RPC_PACKAGE_COMPRESS_TYPE.RPCT_NO, const int secondsTimeOut = RPC_REQUEST_TIMEOUT_SECONDS){ | ||
|
||
UserInfo ret = super.getNameInterface(userInfo, compressType, secondsTimeOut); | ||
return ret; | ||
} | ||
|
||
|
||
void getName(UserInfo userInfo, RpcgetNameCallback rpcCallback, const RPC_PACKAGE_COMPRESS_TYPE compressType = RPC_PACKAGE_COMPRESS_TYPE.RPCT_NO, const int secondsTimeOut = RPC_REQUEST_TIMEOUT_SECONDS){ | ||
|
||
super.getNameInterface(userInfo, rpcCallback, compressType, secondsTimeOut); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
Oops, something went wrong.